Re: Return Code from Win32_Process's Create method



Unfortunately the return code is only supported in the
Win32_ProcessStopTrace class. However that class also shipped on Win2k3
Servers.

Alternatively, not sure how you are running the executable but you could use
a script similar to this... Perhaps even as your target of the create
method you are already using, storing the iReturn value somewhere that it
can be retrieved by your original script. Just a thought.

set ws = CreateObjecT("Wscript.shell")
set args = wscript.arguments

if args.Count <> 1 then
wscript.echo "Invalid argument count"
wscript.quit 1
else
wscript.echo "Going to execute " & args(0)
iReturn = ws.Run (args(0), 1, true)
wscript.echo "Return Code = " & iReturn
wscript.echo "Hex Value is = 0x" & hex(iReturn)
end if

--
Scott McNairy
Microsoft MVP - Windows Server Management Infrastructure


"Cosmo" <Cosmo@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9CFB7D94-ADD8-41B3-B594-53775475569B@xxxxxxxxxxxxxxxx
> How can I obtain the return code of a remotely executed process when using
> Win32_Process's objWMIService.Create method. Note: I have Win2000 and 2003
> servers, so I can't use Win32_ProcessStopTrace class, as mentioned in
> http://www.microsoft.com/technet/scriptcenter/resources/scriptshop/default.mspx.
>
> My code is below:
> ' *************************
> Sub Execute_Remote_Process(byVal strComputer)
> Dim objWMIService, intProcessID, intReturnCode
>
> On Error Resume Next ' /* Disable error checking
> Set objWMIService = GetObject("winmgmts:\\" & strComputer &
> "\root\cimv2:Win32_Process")
>
> If Err.Number = 0 Then
> ' /* WMI Binding okay, so now execute the process
> On Error Goto 0 ' /* Re-enable error checking
>
> intReturnCode = objWMIService.Create(strProcess, null, null, intProcessID)
> Select Case intReturnCode
> Case 0
> Wait_Until_Process_Completes strComputer, intProcessID
> Case Access_Denied
> Wscript.Echo "Process could not be started due to an Access Denied error"
> Case Process_Insufficient_Privilege
> Wscript.Echo "Process could not be started due to Insufficient
> Privileges."
> Case Unknown_Failure
> Wscript.Echo "Process could not be started due to an Unknown Failure"
> End Select
> Else
> Wscript.Echo "WMI Binding Error: Process execution could not occurs due to
> WMI Insufficient Privileges." _
> & vbcrlf & "Confirm the user account running this script has local
> admin rights on the target computer."
> End If
> End Sub
>
> ' *************************
> Sub Wait_Until_Process_Completes(ByVal strComputer, ByVal intProcessID)
>
> Dim objWMIMonitor, colMonitorProcess, objLatestEvent
>
> Set objWMIMonitor = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
>
> ' /* Set polling to 1 second
> Set colMonitorProcess = objWMIMonitor.ExecNotificationQuery("SELECT * FROM
> __InstanceOperationEvent Within 1 WHERE TargetInstance ISA
> 'Win32_Process'")
> WScript.Echo "Waiting for " & Quotes & strProcess & Quotes & " with PID of
> " & intProcessID & " on " & strComputer & " to complete ..."
> Do
> ' /* Loop & query every 1 second until process Completes
> Set objLatestEvent = colMonitorProcess.NextEvent
> Loop Until objLatestEvent.Path_.Class = "__InstanceDeletionEvent" And
> objLatestEvent.TargetInstance.ProcessId = intProcessID
> Set colMonitorProcess = Nothing
> End Sub
> ' *************************
>


.



Relevant Pages

  • Re: Execute permission denied on object xp_SQLagent_notify
    ... On my server the xp_sqlagent* stored procedures are granted execute to ... The account is public in master and db_owner in msdb. ... same settings on 10 servers. ... EXECUTE permission denied on object 'xp_sqlagent_is_starting', ...
    (microsoft.public.sqlserver.security)
  • RE: DBD::Oracle and ORA-600 [16365] errors
    ... > programand execute them in the same manner as an on-line ... Basically, the database would run out of servers and fail, and there was ... So, MTS was the ideal solution, apart from this crash issue:-/ ...
    (perl.dbi.users)
  • Dont Understand login script location..
    ... created a login script under the "Default domain policy" OU, ... the servers, but how do you get it to execute on w98 systems, the following ...
    (microsoft.public.windows.server.scripting)
  • EVENT ID:1000, SOURCE: USERINIT ERROR
    ... the MSKB site. ... "could not execute the following script ... Also my logon.bat script works just fine with my ... servers and PC's, but on every PC and server I get that error msg. ...
    (microsoft.public.win2000.general)
  • Run Logon Script on Workstations Only
    ... I am creating a script that I want to run at logon in a Windows NT ... but want it to execute on Windows 2000 or XP Professional ... Workstations only, not on Servers. ...
    (microsoft.public.scripting.vbscript)