I am starting a process on a remote win2000 server [bat file] that I need to
be able to monitor progress and report when complete as I need to start a
local job once done.
How can I wait until the first job finishes then start another local process
?
I'm using the following script to start the remote process:
strComputer = "SERVER01"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & _
"\root\cimv2:Win32_Process")
errReturn = objWMIService.Create("BATFILE.BAT", null, null, intProcessID)
If errReturn = 0 Then
Wscript.Echo "BATFILE.BAT was started with a process ID of " _
& intProcessID & "."
Else
Wscript.Echo "BATFILE.BAT could not be started due to error " & _
errReturn & "."
End If
Many thanks in anticipation.
TD
Another would be to use the SWbemRefresher interface and call Refresh.
Another would be to just re-get the object and throw it through a sleep
loop. All of these approaches basically do the same thing however.
on error resume next
bDone = false
do while bDone = false
set obj = svc.get("win32_process=" & intPID)
if err <> 0 then
bDone = true
else
wscript.sleep 1000
end if
loop
--
[MS] Scott McNairy
WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Tim Davidge" <tdavidge@no_spam.hotmail.com> wrote in message
news:LPjLBL3...@newsgroup.korea.com...
Thanks for that, unfortunately, the script runs fine but it is only starting
the BAT file and then simply ends and is not looping while waiting for the
remote process to finish. I tried changing the "intPID" to "intProcessID"
named earlier in the script and it ran fine but again is not checking
status.
Any ideas ?
"[MS] Scott McNairy" <sco...@online.microsoft.com> wrote in message
news:3e527fc5$1...@news.microsoft.com...
"Tim Davidge" <tdavidge@no_spam.hotmail.com> wrote in message
news:DabdLT4...@newsgroup.korea.com...
The script tries to get the running win32_process instance. If it is
successful, then it knows the process is still running and it sleeps for a
second ( i guess you could echo something like "Process is still running
..."). If it cannot find the process, it must have terminated so the loop
(and the script) exits. You could add an echo at this point as well to
indicate what has happened.
Let us know if/how this doesn't accomplish what you need.
--
-Philip
This posting is provided "As Is" with no warranties, and confers no rights.
"Tim Davidge" <tdavidge@no_spam.hotmail.com> wrote in message
news:xqXoctQ...@newsgroup.korea.com...
We've got it working now. Scot was kind enough to provide me with the
answer. We had a few problems in the earlier version of the script. Here's
what we are running now and it works just fine ofr anyone that is
interested. I can now add to the bottom of this script and continue
processing once this remote job is complete. Usually takes about 20 mins to
complete which is why I needed to monitor it's progress.
i'm gong to have to add to it to check the completion status I guess to make
sure it completed successfully rather than just terminated unexpectedly. If
I can get the BATFILE to write to a log file of sorts, or out to the
eventlog, then I could check the status of the eventlog before proceeding. I
know I have seen tis somewhere, so will have to do some research on how I
would add that logic to this process.
Best regards,
TD
--------------------------------------------------
strComputer = "SERVERXX"
Set svc = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & _
"\root\cimv2")
set obj = svc.get("win32_process")
errReturn = obj.Create("BATFILE.BAT", null, null, intProcessID)
If errReturn = 0 Then
Wscript.Echo "BATFILE has started with a process ID of " _
& intProcessID & "."
Else
Wscript.Echo "BATFILE could not be started due to error " & _
errReturn & "."
End If
on error resume next
bDone = false
do while bDone = false
set obj = svc.get("win32_process='" & intProcessID & "'")
if err <> 0 then
bDone = true
wscript.echo "Process has finished or terminated"
err.clear
else
wscript.sleep 1000
end if
loop
------------------------------------------------------------
"Philip Nunn [MSFT]" <pn...@online.microsoft.com> wrote in message
news:e1cFA6Q2...@TK2MSFTNGP10.phx.gbl...