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
Help needed
Suddenly my laptop stated there is a potential threat and needs to run chkdsk. After running chkdsk it displays message - " windows has finished...
General Discussion
Help needed!!!
I have on my computer vista x64. last day it crashed and said that some drivers are missing. I've tried to use the option of automatic repair and it...
Drivers
Serious Help Needed plz!
ok first of all sorry to use this topic but i saw way too many threads so I figured i might get help sooner from you guys here... I had been using...
General Discussion
Help Needed
I recently updated my drivers for my video card (an integrated Ati Radeon Hd3200)off of Ati/Amd's website. After instalation windows told me it did...
Drivers
Help Needed Plz
Hi i've just upgraded my desktop from vista home premium to vista ultimate but upon doing this i can't acces the internet through my usual adapter...
Drivers
Help needed
Hi I am new to this forum and have a question that has been bugging me for some time now. I have a problem that has been discussed sooo many times...
Software
help needed
Hi All, A few months ago a guy at work emigrated and sold me his WORD 2007,,he let me have it cheap and i waspleased with it,the trouble started...
Vista General