Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Help needed

Reply
 
Old 02-22-2009   #1 (permalink)
Bobby


 
 

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
Old 02-22-2009   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: How to detect & kill a task


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

> 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
Reply

Thread Tools


Similar Threads
Thread Forum
help needed General Discussion
Help needed!!! Drivers
Serious Help Needed plz! General Discussion
New OS needed? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46