Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I eliminate the"OK" prompt from a VB Script?

Status
Not open for further replies.

stevemarks59

Technical User
Apr 8, 2010
22
US
My OS is XP-Pro SP3

I use the VB Script shown below to quickly kill applications when I don't want them loading at startup. This VB Script seems to kill the applications much faster than running a batch file to start taskkill.exe. However I would rather not have to click the "OK" button prompted AFTER each application is terminated. Seems pointless anyway to be asked for an "OK" AFTER the application has been killed. Can this script be modified to eliminate the pointless prompts? I would not have ran the script in the first place if I did not want to kill the apps.

The popup window displays how many instances of the application it has killed and you have to click the "OK" button before the script will kill the next application or close.

This is the script:

strComputer = "."
strProcessToKill = "cmd.exe"

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & strProcessToKill & "'")

count = 0
For Each objProcess in colProcess
objProcess.Terminate()
count = count + 1
Next


wscript.echo "Killed " & count & " instances of " & _
strProcessToKill & "on " & strComputer


strComputer = "."
strProcessToKill = "firefox.exe"

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & strProcessToKill & "'")

count = 0
For Each objProcess in colProcess
objProcess.Terminate()
count = count + 1
Next


wscript.echo "Killed " & count & " instances of " & _
strProcessToKill & "on " & strComputer


strComputer = "."
strProcessToKill = "yahoomessenger.exe"

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & strProcessToKill & "'")

count = 0
For Each objProcess in colProcess
objProcess.Terminate()
count = count + 1
Next


wscript.echo "Killed " & count & " instances of " & _
strProcessToKill & "on " & strComputer




Thanks.
 
Comment out all the wscript.echo lines.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks that solved my problem! I feel like such an idiot! The first thing I attempted to modify this script was to comment out this line "wscript.echo "Killed " & count & " instances of " & _" but I thought the line beneath it "strProcessToKill & "on " & strComputer" was necessary for the operation. Needless to say I got an error and the script failed. Thanks again for your help I appreciate you taking the time to help me.
 
&_ just means "line continuation".

You might also want to consider consolidating the script (as it is quite repetative)

Code:
dim arrProcessToKill(2)

strComputer = "."
arrProcessToKill(0) = "cmd.exe"
arrProcessToKill(1) = "firefox.exe"
arrProcessToKill(2) = "yahoomessenger.exe"

set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 

for each strProcessToKill in arrProcessToKill
   set colProcess = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & strProcessToKill & "'")
   count = 0
   for each objProcess in colProcess
        objProcess.Terminate()
        count = count + 1
   next
   wscript.echo "Killed " & count & " instances of " & strProcessToKill & "on " & strComputer
next

or remove these startup processes from the Run key in the local machines hive of the registry.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

This is just a suggestion if you're confident with registry editing. It doesn't even really belong on this thread but thought I would offer an alternative as it looks as though your concern may be with startup performance.

-Geates

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
- Martin Golding
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top