Re: Terminating a process

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

From: Dennis Hancy (dennishancy_at_eaton.com)
Date: 07/06/04


Date: 6 Jul 2004 11:40:17 -0700

Tom,

I tried this code as is (except I changed RunThis.exe to my own exe
file). However, the exe file still shows up in the task manager.

I am not sure I know what WMI is. Do I need to do something special
to make it run? Or will it run as listed? I included some debug
msgbox statements in my code, so I know that it found my exe file.
Just not sure why it still shows up in the task manager.

Thanks.

Dennis

"Tom Lavedas" <tlavedas@hotmail.remove.com> wrote in message news:<C44AC7EA-2DBC-44D3-9716-29D4DAF2FB55@microsoft.com>...
> Setting that object to Nothing has no effect because the wshShell is no longer attached to the RunThis.exe thread. The third argument on the Run line made sure that this was the case.
>
> You need to use WMI to either create the thread in the first place or to search for the thread's PID to permit termination under your script's control.
>
> For example, from the Script Center's sample library ...
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set colProcessList = objWMIService.ExecQuery _
> ("Select * from Win32_Process Where Name = 'RunThis.exe'")
> For Each objProcess in colProcessList
> objProcess.Terminate()
> Next
>
> There is also a process creation class (Win32_ProcessStartup) that returns the PID directly at the time the thread is created, but it's way complicated to use (I think ;-)
>
> Tom Lavedas
> ===========
>
> Microsoft® Windows®2000 Scripting Guide (URL all one line)
> http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp
>
> TechNet Script Center Sample Scripts (URL all one line)
> http://www.microsoft.com/downloads/release.asp?ReleaseID=38942
>
> "Dennis Hancy" wrote:
>
> > I have code in a .wsf file:
> >
> > Set wshShell = WScript.CreateObject("WScript.Shell")
> > wshShell.Run RunThis.exe, 0, false
> >
> > It does some other processing, and before the program ends, it runs
> > this command:
> >
> > Set wshShell = nothing
> >
> >
> >
> > However, when the script ends, RunThis.exe still shows up as an active
> > process in my Task Manager.
> >
> > Any idea why this process isn't being killed as a result of the last
> > command?
> >
> >
> > Dennis Hancy
> > Eaton Corporation
> > Cleveland, OH



Relevant Pages

  • Re: control CPU usage
    ... My first question is whether the pyHook event is calling the SendKeys ... The task manager has far too simplistic ... I included my main script for your reference. ... paragraph = rc.ProcessEvent ...
    (comp.lang.python)
  • Re: control CPU usage
    ... The script monitors global input using PyHook, ... you're using SendKeys to generate a keystroke to the other process. ... My first question is whether the pyHook event is calling the SendKeys function directly (after your "lengthy" calculation) or whether there are other events firing off in between. ... The task manager has far too simplistic visibility to be useful for this purpose. ...
    (comp.lang.python)
  • Re: Process runs but browser doesnt open
    ... If the .exe file is running in the task manager but does not open ... "Uncle Gus" wrote: ... > I suspect this machine had a browser hijack so I ran SpyBot, ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: An executable file to run a VB script?
    ... macros in this script or would it circumvent this Excel dialogue box? ... VBA you shared, I think I'd do everything from a single vbs file and just ... workbook 'myBook.xls' containing the script) I included in my previous ... My intention is to create an .exe file that I can assign to to the ...
    (microsoft.public.excel.programming)
  • Re: Startup Script Issues (Running EXE file)
    ... If you are getting an error at startup the same thing will happen at start of day, so yes you will need to quell all popups. ... placing the script and the exe in the SysVol and also granting ... the machines rights on the share, ... > EXE file from the startup script. ...
    (microsoft.public.windows.server.active_directory)