
It's getting kinda late so I'm going to bed but I don't see why this can't be made to work easily. Anyway, here's the code and links: http://www.teammacosx.com/forum/cgi-bin ... f=3;t=1893
filename (it references its self): GetProcess.vbs
Code: Select all
On Error Resume Next
Dim strServer, executable
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objFS = CreateObject("Scripting.FileSystemObject")
' Get Name of Input File and Check to see if its valid
strInputFile = "c:\GetProcess\list.txt"
Set processList = objFS.OpenTextFile (strInputFile)
If strInputFile = "" Then
MsgBox ("Operation Cancelled, no input file supplied")
Wscript.Quit(1)
ElseIf Err Then
ErrMsg = AdsiErr(strInputFile)
MsgBox ("Error: "& ErrMsg)
Wscript.Quit(1)
End if
do while processList.AtEndOfStream <> True
executable = ProcessList.ReadLine
Dim DoTheLoop
'strComputer = "."
' The service name is the last word after the / in this line.
Set FoldingServiceObj1 = GetObject("WinNT://./F@H1")
'Set FoldingServiceObj2 = GetObject("WinNT://./F@H2")
'Set FoldingServiceObj3 = GetObject("WinNT://./F@H3")
'Set FoldingServiceObj4 = GetObject("WinNT://./F@H4")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
' Looking for the Process to be running. This is Read from the list.txt file...
Do
'WScript.Echo "Beginning of Loop, DoTheLoop = " & DoTheLoop
DoTheLoop = 0
WScript.Echo executable
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & executable & "'")
' If the process is found the following happens and then the script loops until the process is done.
For Each objProcess In colProcessList
WScript.Echo "Process Found, Stopping Service"
FoldingServiceObj1.Stop
'FoldingServiceObj2.Stop
'FoldingServiceObj3.Stop
'FoldingServiceObj4.Stop
DoTheLoop = 1
'Sleep for Specified time in Milliseconds. 60000 = 60 seconds or 1 minute
Wscript.Sleep 10000
'WScript.Quit
Next
Loop While DoTheLoop = 1
Loop
' If the process is not found this happens and then the script quits
'WScript.Echo "Process Not Found, Exiting"
FoldingServiceObj1.Start
Set FoldingServiceObj1 = Nothing
'FoldingServiceObj2.Start
'Set FoldingServiceObj2 = Nothing
'FoldingServiceObj3.Start
'Set FoldingServiceObj3 = Nothing
'FoldingServiceObj4.Start
'Set FoldingServiceObj4 = Nothing
' Set a time to run the Script again. After Soon.exe the number is in seconds, 60 = 1 minute.
Set objApp = CreateObject("WScript.Shell")
objApp.Run "cmd /C C:\GetProcess\Soon.exe 180 C:\GetProcess\GetProcess.vbs"