RE: Send CTRL-C to program started with WshShell.Exec method

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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?
.



Relevant Pages

  • Re: Few questions about W2K management ( Defrag AD - Add, move partition)
    ... Gig of NTDS.dit is equivalent to about 250,000 users. ... The misnamed "offline defragmentation" procedure will shrink ... (I did not find any exemple on Microsoft Script Center ... Gig is quite large for a database in most companies. ...
    (microsoft.public.win2000.active_directory)
  • (reposted) Question about CTRL-C handling in scripts
    ... I have a 'wrapper' script that sets up some environment variables and ... then executes another script, which then eventually runs a Fortran ... Then it requires a second <Ctrl-C> to exit this looping and return to ...
    (comp.unix.shell)
  • Interrupt Handling
    ... script while executing the particular sub will ignore the ctrl-c. ... But when i give the ctrl-c the process seems to be hanging and I ...
    (perl.beginners)
  • Cant ctrl-c to exit with DBI, DBD::Oracle
    ... Once my script connects to my database, ... I just can't exit when I'm done. ... use DBI; ... I'm able to interrupt the script with ctrl-c as I'd expect. ...
    (perl.dbi.users)
  • trap does not
    ... I'm trying to abort the execution of a scipt, ... Ctrl-C. ... So I put the 'trap' command at the beginning of the script, ...
    (comp.os.linux.misc)