internal void ExecuteWsatProcess(string arguments) { ProcessStopTraceHandler handler; Utilities.Log("ExecuteWsatProcess(" + arguments + ")"); try { ManagementBaseObject inParams = processClass.GetMethodParameters(MethodCreate); inParams[InputParameters.CommandLine] = GetDeploymentPath() + " " + arguments; WqlEventQuery wqlEventQuery = new WqlEventQuery(QueryProcessExitEvent); ManagementEventWatcher watcher = new ManagementEventWatcher(managementScope, wqlEventQuery); handler = new ProcessStopTraceHandler(); watcher.EventArrived += new EventArrivedEventHandler(handler.Arrived); watcher.Start(); ManagementBaseObject outParams = processClass.InvokeMethod( MethodCreate, inParams, null); if (outParams.Properties[OutputParameters.ProcessId].Value == null || outParams.Properties[OutputParameters.ReturnValue].Value == null) { throw new WsatAdminException(WsatAdminErrorCode.REMOTE_MISSING_WSAT, SR.GetString(SR.ErrorRemoteWSATMissing)); } // the process ID when executing a remote command uint processID = (uint)outParams.Properties[OutputParameters.ProcessId].Value; uint result = (uint)outParams.Properties[OutputParameters.ReturnValue].Value; if (result != 0) { throw new WsatAdminException(WsatAdminErrorCode.REMOTE_MISSING_WSAT, SR.GetString(SR.ErrorRemoteWSATMissing)); } handler.ProcessId = processID; int totalDelay = 0; while (!handler.IsArrived && totalDelay < autoEventTimeout) { totalDelay += delayInAutoEventTimeout; System.Threading.Thread.Sleep(delayInAutoEventTimeout); } watcher.Stop(); } catch (WsatAdminException) { throw; } #pragma warning suppress 56500 catch (Exception e) { if (Utilities.IsCriticalException(e)) { throw; } throw new WsatAdminException(WsatAdminErrorCode.REMOTE_EXECUTION_ATTEMPT_ERROR, SR.GetString(SR.ErrorAttemptRemoteExecution, e.Message)); } if (handler.IsArrived && handler.ReturnCode != 0) { throw new WsatAdminException((WsatAdminErrorCode)handler.ReturnCode, SR.GetString(SR.ErrorRemoteExecution, handler.ReturnCode)); } else if (!handler.IsArrived) { throw new WsatAdminException(WsatAdminErrorCode.REMOTE_TIMEOUT, SR.GetString(SR.ErrorRemoteTimeout)); } Utilities.Log("ExecuteWSATProcess successfully quitted."); }