Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Monitoring Remote Process for Completion Status

6 views
Skip to first unread message

Tim Davidge

unread,
Feb 18, 2003, 12:27:39 PM2/18/03
to
People,

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


[MS] Scott McNairy

unread,
Feb 18, 2003, 1:47:34 PM2/18/03
to
Many ways to do this, one is a ExecNotificationQuery query similar to
this...
"select * from __instanceDeletionEvent within 2 where targetInstance isa
'win32_process' and targetInstance.PID = " & intPID

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...

Tim Davidge

unread,
Feb 18, 2003, 2:36:49 PM2/18/03
to
Hi Scott,

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

unread,
Feb 20, 2003, 1:12:34 PM2/20/03
to
Bump, hoping for a response.


"Tim Davidge" <tdavidge@no_spam.hotmail.com> wrote in message

news:DabdLT4...@newsgroup.korea.com...

Philip Nunn [MSFT]

unread,
Feb 20, 2003, 1:33:00 PM2/20/03
to
I guess I'm not sure what you mean by 'not checking status'.

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...

Tim Davidge

unread,
Feb 21, 2003, 12:35:33 PM2/21/03
to
Hi Philip,

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...

0 new messages