![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 - 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 Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| help needed | General Discussion | |||
| Help needed!!! | Drivers | |||
| Serious Help Needed plz! | General Discussion | |||
| New OS needed? | Vista General | |||