I have created a windows Service which invokes executables on remote machines, waits for it to complete and then proceeds to the next machine on the network.
The Account type for the windows Service is "Network Service". For monitoring if the process is completed on the remote machine, I am using ManagementEvent Watcher class. I get the following error when I start the Management event watcher object.
System.Manageme nt.ManagementEx ception: Invalid parameter
at System.Manageme nt.ManagementEx ception.ThrowWi thExtendedInfo( ManagementStatu s errorCode)
at System.Manageme nt.ManagementEv entWatcher.Star t()
The code I am using is as follows:
Dim connection As New System.Manageme nt.ConnectionOp tions
connection.User name = v_sUserName
connection.Pass word = v_sPassword
connection.Enab lePrivileges = True
Dim oPath As New ManagementPath( "\\" & v_sServerName & "\root\CIMV 2")
Dim oScope As New System.Manageme nt.ManagementSc ope(oPath, connection)
oScope.Options. Impersonation = ImpersonationLe vel.Impersonate
oScope.Connect( )
Dim processClass = New System.Manageme nt.ManagementCl ass("Win32_Proc ess")
processClass.Sc ope = oScope
Dim inParams = processClass.Ge tMethodParamete rs("Create")
inParams("Comma ndLine")="C:\My folder\myexe.ex e"
Dim oOutParams As ManagementBaseO bject = processClass.In vokeMethod("Cre ate", inParams, Nothing)
Dim sWQLQry As String = "SELECT * FROM __InstanceOpera tionEvent " & _ "WITHIN 2 WHERE TargetInstance ISA 'Win32_Process' " & _
"AND TargetInstance. Name = '" & "MPSFileAuditSa tellite.exe" & "'"
Dim oWatcher As ManagementEvent Watcher = New ManagementEvent Watcher(oScope, oWQL)
oWatcher.Start( )'I presume the error is here.
'Logic to wait for the process to exit.
what is wrong in the scope?
It used to work earlier when the service was of type User. Does this depend on the service account type and does not work when using Network Service?
Thanks in advance.
The Account type for the windows Service is "Network Service". For monitoring if the process is completed on the remote machine, I am using ManagementEvent Watcher class. I get the following error when I start the Management event watcher object.
System.Manageme nt.ManagementEx ception: Invalid parameter
at System.Manageme nt.ManagementEx ception.ThrowWi thExtendedInfo( ManagementStatu s errorCode)
at System.Manageme nt.ManagementEv entWatcher.Star t()
The code I am using is as follows:
Dim connection As New System.Manageme nt.ConnectionOp tions
connection.User name = v_sUserName
connection.Pass word = v_sPassword
connection.Enab lePrivileges = True
Dim oPath As New ManagementPath( "\\" & v_sServerName & "\root\CIMV 2")
Dim oScope As New System.Manageme nt.ManagementSc ope(oPath, connection)
oScope.Options. Impersonation = ImpersonationLe vel.Impersonate
oScope.Connect( )
Dim processClass = New System.Manageme nt.ManagementCl ass("Win32_Proc ess")
processClass.Sc ope = oScope
Dim inParams = processClass.Ge tMethodParamete rs("Create")
inParams("Comma ndLine")="C:\My folder\myexe.ex e"
Dim oOutParams As ManagementBaseO bject = processClass.In vokeMethod("Cre ate", inParams, Nothing)
Dim sWQLQry As String = "SELECT * FROM __InstanceOpera tionEvent " & _ "WITHIN 2 WHERE TargetInstance ISA 'Win32_Process' " & _
"AND TargetInstance. Name = '" & "MPSFileAuditSa tellite.exe" & "'"
Dim oWatcher As ManagementEvent Watcher = New ManagementEvent Watcher(oScope, oWQL)
oWatcher.Start( )'I presume the error is here.
'Logic to wait for the process to exit.
what is wrong in the scope?
It used to work earlier when the service was of type User. Does this depend on the service account type and does not work when using Network Service?
Thanks in advance.
Comment