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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop processes array

Status
Not open for further replies.

stev379

Technical User
Jan 2, 2005
19
US
I need to stop a changing list of processes on local machines. I'd like to be able to just add to list within the script when I have a new process name. Currently, I just write the guts of the script over and over. I've gotten close with a sub routine that works for deleting files. I just edited to use PSKill and try to kill the processes with a variable but no luck with my example below:
Dim shell

Set shell = CreateObject("WScript.Shell")

call ProcName("Winword.exe")
call ProcName("notepad.exe")
wscript.quit

sub ProcName(ProcessName)

shell.Run (("pskill.exe /t (Processname)"))

end sub
'End Example
Any help with any manner of completing this task (with or without PSKill) with vbs is appreciated.
Thanks!
-Steve
 
I think you need
Code:
shell.Run (("pskill.exe /t (" & Processname & ")"))
As you have it coded you are trying to Kill a process named "Processname" and not the process contained on the variable of that name.
 
Golom,
Thanks! I tried your suggestion and a couple variations of it, but all that results is a quick flash of a command prompt window and the test processes (Word and notepad) continue to run. Task mgr doesn't show any script running.
Any further suggestions...?

Also, how do you post your code in the extra window in this forum?

Below works for files, but obviously won't work on the objects needed to stop a process.

'Begin script
Const ForAppending = 8
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")

LogFile = "C:\LOGTEST1.txt"
Set f = objFSO.OpenTextFile(LogFile, ForAppending, True)

WinDir = objFSO.GetSpecialFolder(0)

On Error Resume Next

call FILECHECK("C:\testfile1.txt")
call FILECHECK(Windir & "\testfile2.txt")

'''''''''''''''''''''''''''''''''''''''''''''''
' '
' ***sub routine to check if files exist*** '
' and delete them if they do '
'''''''''''''''''''''''''''''''''''''''''''''''
sub FILECHECK(filename)

If objFSO.FileExists(filename)=True Then
f.WriteLine Now & " ; " & WshNetwork.ComputerName _
& " ; FOUND ; FILE ;" & filename & " was FOUND!" _
& ";" & Err.Description
Else
f.WriteLine Now & " ; " & WshNetwork.ComputerName _
& " ; ; ;" & filename & " was not found." _
& ";" & Err.Description
Err.Clear
End If

If objFSO.FileExists(filename)=True then
objFSO.DeleteFile(filename)
End If


end sub
'End Script
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top