Home > Archive > Visual Basic > March 2006 > Weird cmd.exe problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Weird cmd.exe problem
|
|
|
| I'm trying to add code to my VB6 program that would automatically schedule a
task to run my program in the future, but I'm having problems.
Here's my code.
Private Sub Command1_Click()
x = Shell("C:\WINDOWS\System32\cmd.exe", vbNormalFocus)
SendKeys " schtasks ", True
SendKeys "/create ", True
SendKeys "/tn " & Chr(34) & "123456789" & Chr(34) & " ", True
SendKeys "/tr " & Chr(34) & "C:\Program Files\Lot
Finder\prjLotFinder.exe" & Chr(34) & " ", True
SendKeys "/sc once ", True
SendKeys "/st 01:00:00 ", True
SendKeys "/sd 04/17/2006 ", True
End Sub
When I run it, it will open multiple cmd.exe windows, usually 6. The first 5
windows will just have the command prompt. The last window will have
schtasks printed 6 times and the rest of the code printed 6 times.
It's as if there are invisible loops in my code. It behaves as if the code
was as follows.
Private Sub Command1_Click()
for i=1 to 6
x = Shell("C:\WINDOWS\System32\cmd.exe", vbNormalFocus)
next i
for i=1 to 6
SendKeys " schtasks ", True
next i
for i=1 to 6
SendKeys "/create ", True
SendKeys "/tn " & Chr(34) & "123456789" & Chr(34) & " ", True
SendKeys "/tr " & Chr(34) & "C:\Program Files\Lot
Finder\prjLotFinder.exe" & Chr(34) & " ", True
SendKeys "/sc once ", True
SendKeys "/st 01:00:00 ", True
SendKeys "/sd 04/17/2006 ", True
next i
End Sub
Another strange thing that I discovered is that if I put a breakpoint on the
first line 'Private Sub Command1_Click()', when I run it, it stops at the
breakpoint and when I restart it, it usually works the way it should.
So, what is the solution?
| |
| Karl E. Peterson 2006-03-30, 6:56 pm |
| http://www.google.com/search?q=edan...+task+scheduler
--
Working without a .NET?
http://classicvb.org/
BKM wrote:
> I'm trying to add code to my VB6 program that would automatically
> schedule a task to run my program in the future, but I'm having
> problems.
>
> Here's my code.
>
> Private Sub Command1_Click()
> x = Shell("C:\WINDOWS\System32\cmd.exe", vbNormalFocus)
> SendKeys " schtasks ", True
> SendKeys "/create ", True
> SendKeys "/tn " & Chr(34) & "123456789" & Chr(34) & " ", True
> SendKeys "/tr " & Chr(34) & "C:\Program Files\Lot
> Finder\prjLotFinder.exe" & Chr(34) & " ", True
> SendKeys "/sc once ", True
> SendKeys "/st 01:00:00 ", True
> SendKeys "/sd 04/17/2006 ", True
> End Sub
>
> When I run it, it will open multiple cmd.exe windows, usually 6. The
> first 5 windows will just have the command prompt. The last window
> will have schtasks printed 6 times and the rest of the code printed 6
> times.
>
> It's as if there are invisible loops in my code. It behaves as if the
> code was as follows.
> Private Sub Command1_Click()
> for i=1 to 6
> x = Shell("C:\WINDOWS\System32\cmd.exe", vbNormalFocus)
> next i
> for i=1 to 6
> SendKeys " schtasks ", True
> next i
> for i=1 to 6
> SendKeys "/create ", True
> SendKeys "/tn " & Chr(34) & "123456789" & Chr(34) & " ", True
> SendKeys "/tr " & Chr(34) & "C:\Program Files\Lot
> Finder\prjLotFinder.exe" & Chr(34) & " ", True
> SendKeys "/sc once ", True
> SendKeys "/st 01:00:00 ", True
> SendKeys "/sd 04/17/2006 ", True
> next i
> End Sub
>
> Another strange thing that I discovered is that if I put a breakpoint
> on the first line 'Private Sub Command1_Click()', when I run it, it
> stops at the breakpoint and when I restart it, it usually works the
> way it should.
>
> So, what is the solution?
|
|
|
|
|