我討厭回答我自己的問題,但對於下一個要面對這個挑戰的人,我確實找到了一個更簡單的方法來通過System.Management對象執行此操作。
在codeproject.com上有一個完整的工作應用程序和源代碼。
http://www.codeproject.com/KB/cs/Remote_process_controller.aspx
我修改了它頗有幾分我specfic目的,並獲得儘可能小的功能可按做到這一點。我分享給下一個來的人。
請注意,您需要添加對項目的參考System.Management。
private bool CheckForExpectedProcess(string userName, string password, string machineName, string logonDomain, string PartialProcessname)
{
bool ReturnValue = false;
System.Management.ManagementScope managementScope;
try
{
System.Management.ConnectionOptions connOptions = new System.Management.ConnectionOptions();
connOptions.Impersonation = System.Management.ImpersonationLevel.Impersonate;
connOptions.EnablePrivileges = true;
connOptions.Username = logonDomain + "\\" + userName;
connOptions.Password = password;
managementScope = new System.Management.ManagementScope(@"\\" + machineName + @"\ROOT\CIMV2", connOptions);
managementScope.Connect();
System.Management.ManagementObjectSearcher objSearcher = new System.Management.ManagementObjectSearcher("SELECT Name FROM Win32_Process WHERE NAME LIKE'%" + PartialProcessname + "%'");
System.Management.ManagementOperationObserver opsObserver = new System.Management.ManagementOperationObserver();
objSearcher.Scope = managementScope;
string[] sep = { "\n", "\t" };
System.Management.ManagementObjectCollection objects = objSearcher.Get();
ReturnValue = objects.Count > 0;
}
catch (Exception ex)
{
// handle error - we log it to our own system, but it's up to you.
}
return ReturnValue;
}
正是我所需要的,感謝分享...... – Moshisho