RE: Send CTRL-C to program started with WshShell.Exec method
- From: "L-P Lavoie" <LPLavoie@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 4 May 2005 11:42:06 -0700
What I'm looking for is not a solution to stop the VB Script but a solution
to stop defrag.exe in clean manner.
Moreover, the script will be started by a scheduled task so nobody will be
at the console to interact.
Do you have somethig else to propose me?
Thanks a lot
"MEHRAN SEDAGHATPOUR" wrote:
> If all fails try to communicate throught the file system. Instead of sending
> control C try to create a file on the file system, and have the VB Script to
> look for the file. When file is created, it should take the same actions as
> if control C was received. It is a simple trick, but is guaranteed to work.
>
> "L-P Lavoie" wrote:
>
> > Hi,
> >
> > I'm writing a VBScript to automate the defragmentation of all local drives
> > on a Windows 2003 box with defrag.exe.
> >
> > I don't want that defrag.exe continues to run after a pre-defined time so I
> > must stop it at this time. When started from the command line, defrag.exe
> > can be stopped by pressing CTRL-C.
> >
> > This is what I try to do in VBScript.
> >
> > I don't want to kill or terminate the process to be sure to not corrupt the
> > volume and also because defrag.exe start an other process dfrgntfs.exe. I
> > don't want to kill this process for the same reasons. Also, when terminating
> > the defrag.exe process, dfrgntfs.exe doesn't stop and continue to defragment
> > the volume. It only stop when the defragmentation is finished or by pressing
> > CTRL-C at the command line.
> >
> > So I tried to send a CTRL-C to defrag.exe in two ways:
> >
> > 1----------
> > Set oExec = WshShell.Exec("C:\Windows\System32\Defrag.exe")
> > Do While oExec.Status = 0
> > WScript.Sleep 100
> > If Timer() => LimitTime Then 'If later than limit time,
> > default is 8:00 AM
> > WshShell.AppActivate(oExec.ProcessID)
> > WshShell.SendKeys("^C")
> > Wscript.Quit(999)
> > End If
> > Loop
> >
> > When this script is started with cscript.exe, the CTRL-C is send to
> > cscript.exe instead of defrag.exe. When started with wscript.exe, it just
> > doesn't work.
> >
> >
> > 2--------
> > Set oExec = WshShell.Exec(strExecCommand)
> > Do While oExec.Status = 0
> > WScript.Sleep 100
> > If Timer() => LimitTime Then 'If later than limit time,
> > default is 8:00 AM
> > oExec.StdIn.Write "^C"
> > Wscript.Quit(999)
> > End If
> > Loop
> >
> > -------------
> > In this manner, it doesn't work with cscript or wscript.
> >
> > Can you help me?
.
- References:
- Send CTRL-C to program started with WshShell.Exec method
- From: L-P Lavoie
- RE: Send CTRL-C to program started with WshShell.Exec method
- From: MEHRAN SEDAGHATPOUR
- Send CTRL-C to program started with WshShell.Exec method
- Prev by Date: Windows 2003 VB Script Follow-Up Question
- Next by Date: Re: Redimming Array problem - SUBSCRIPT OUT OF RANGE! :)
- Previous by thread: RE: Send CTRL-C to program started with WshShell.Exec method
- Next by thread: Re: WScript.Sleep for HTA?
- Index(es):
Relevant Pages
|