Windows Vista Forums

Help needed

  1. #1


    Bobby Guest

    Help needed

    Hi,
    I am trying with a simple VBSCRIPT to locate en stop exel.exe from
    running! Could someone correct this simple program!
    Thanks ahead.


    Dim objShell, objExecObject, pid, app

    set objShell = CreateObject("wscript.shell")
    set objExecObject = objShell.Exec("c:\WINDOWS\system32\QPROCESS.EXE
    *")

    Do Until objExecObject.StdOut.AtEndOfStream


    app = Left(objExecObject.StdOut.ReadLine, 63)
    app = right(app,9)

    pid = Left(objExecObject.StdOut.ReadLine, 52)
    pid = Right(pid, 4)

    'WScript.Echo (objExecObject.StdOut.ReadLine)
    'WScript.Echo (pid & " " & app)

    If app = "EXCEL.EXE" Then
    objExecObject = objShell.Exec("c:\WINDOWS\system32\TSKILL.EXE " &
    pid)
    End If

    Loop


      My System SpecsSystem Spec

  2. #2


    Pegasus \(MVP\) Guest

    Re: How to detect & kill a task


    "Bobby" <rpqcca@xxxxxx> wrote in message
    news:acf98bc1-5658-48d0-980a-35a919f311de@xxxxxx

    > Hi,
    > I am trying with a simple VBSCRIPT to locate en stop exel.exe from
    > running! Could someone correct this simple program!
    > Thanks ahead.
    >
    >
    > Dim objShell, objExecObject, pid, app
    >
    > set objShell = CreateObject("wscript.shell")
    > set objExecObject = objShell.Exec("c:\WINDOWS\system32\QPROCESS.EXE
    > *")
    >
    > Do Until objExecObject.StdOut.AtEndOfStream
    >
    >
    > app = Left(objExecObject.StdOut.ReadLine, 63)
    > app = right(app,9)
    >
    > pid = Left(objExecObject.StdOut.ReadLine, 52)
    > pid = Right(pid, 4)
    >
    > 'WScript.Echo (objExecObject.StdOut.ReadLine)
    > 'WScript.Echo (pid & " " & app)
    >
    > If app = "EXCEL.EXE" Then
    > objExecObject = objShell.Exec("c:\WINDOWS\system32\TSKILL.EXE " &
    > pid)
    > End If
    >
    > Loop
    There are a couple of problems with your script:
    - Executing qprocess.exe requires quite a bit of CPU power.
    - The script will end after it has killed Excel.

    You might get better results if you rely on WMI. Here is a script based on
    an idea by the Scripting Guy:
    sProcess = "Excel.exe"
    Set oWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set cMonitoredProcesses = oWMIService.ExecNotificationQuery _
    ("Select * From __InstanceCreationEvent Within 5 " _
    & "Where TargetInstance ISA 'Win32_Process'")
    Do
    Set oLatestProcess = cMonitoredProcesses.NextEvent
    If InStr(1, oLatestProcess.TargetInstance.Name, sProcess, 1) > 0 _
    Then WScript.Echo sProcess & " has started."
    Loop

    You will need to replace [WScript.Echo sProcess & " has started."] with your
    own code to kill Excel. If you use taskkill.exe then you do not really need
    the PID - it is sufficient for you to use /im excel.exe. However, you should
    use the /f switch.



      My System SpecsSystem Spec


Help needed
Similar Threads
Thread Forum
not needed Vista General
SP1 help needed Vista General
Help needed... Sound & Audio
help needed Vista networking & sharing
RAM needed? Vista installation & setup