All Forums >> [Scripting] >> WSH & Client Side VBScript >> Using an Array to assign to a Variable Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
I am new today to VBScript!! I am trying to stop a number of Processes on the PC, then start up a couple of processes.
I have located code to stop a single process. So I though you could just create an array and use For Each to loop through the list of processes provided. But it just shuts down the 1st process and freezes.
Any Ideas??
dim KillList(2) killList(0)="Notepad.exe" KillList(1)="taskmgr.exe" KillList(2)="desktopmgr.exe"
For Each x in KillList On Error Resume Next ProNum = 0 InProcess = False
Do While InProcess = False pickle = x wbscript.echo "Killing Process " & pickle If pickle = "" Then WScript.Quit Forever = 1
Do Until Forever = 1000 Set colProcessList2 = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & pickle & "' OR Handle = '" & pickle & "'") For Each objProcess in colProcessList2 If obj.Process.Name = pickle OR obj.Process.Handle = pickle Then InProcess = True objProcess.Terminate() Next If KillForever = vbNo Then Forever = 1000 Loop Loop next For Each objProcess in colProcessList2 If objProcess.Name = pickle Then Success = False
If Success = False Then WScript.Echo "Successfully killed the " & pickle & " process" Else WScript.Echo "Unable to kill the " & pickle & " process" End If Next
Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
First, when troubleshooting a script, make sure you comment out any On error resume next's. Once you do that, you will see that you get an error on the line wbscript.echo "Killing Process " & pickle. Also, make sure that you are indenting correctly as it will help you verify that you are looping correctly. I also got an error on line 20 ( If obj.Process.Name = pickle OR obj.Process.Handle = pickle Then InProcess = True). Once I changed it to obkprocess.--- it worked. But only once. For some reason it was not checking for the next process. Try the code below.
Excellent...I found PSKILL & TaskKill this morning!
Now is the decider. I want to start up 2 programs after the kill process.
PSKILL seems to start up Excel & Notes easily, but I cannot get it to start another executable in the Program Files directory. Not sure why it can find 1 & not the other.
Locations are C:\lotus\notes\notes.exe C:\Program Files\Research in Motion\Blackberry\DesktopMgr.exe (over came errors by PROGRA~1\RESEAR~1\BLACKB~1\DesktoipMgr.exe but just opens a DOS box with this as the title)
VBScript probably has some options, I am currently scouring the internet for some code.
Taskkill probably does not have an option to Start programs. Shame as cannot believe you managed to nail it to 1 line of code.