Цитата(atvin @ 27.8.2007, 23:25 ) | | Это не работает. Возвращает пустую строку. |
MSDN:
| Цитата | If you did not use the Start method to start a process, the StartInfo property does not reflect the parameters used to start the process. For example, if you use GetProcesses to get an array of processes running on the computer, the StartInfo property of each Process does not contain the original file name or arguments used to start the process.
|
| Код | private static string GetProcessOwner(Process process) { try { ManagementObject classInstance = new ManagementObject("root\\CIMV2", String.Format("Win32_Process.Handle='{0}'", process.Id), null); ManagementBaseObject outParams = classInstance.InvokeMethod("GetOwner", null, null);
return String.Format("{0}\\{1}", outParams["Domain"], outParams["User"]); } catch (ManagementException err) { Console.WriteLine("An error occurred while trying to execute the WMI method: {0}" + err.Message); }
return String.Empty; }
|
Если WMI не устраивает, то см. WinAPI ф-цию CreateToolhelp32Snapshot (declared in Tlhelp32.h)
|