C#获取进程用户名
void Main() { Process.GetCurrentProcess().Id.Dump(); getProcessOwnerName(Process.GetCurrentProcess().Id).Dump(); } public string getProcessOwnerName(int processId) { var processes = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_Process WHERE ProcessId = " + processId); foreach (System.Management.ManagementObject process in processes.Get()) { try { string[] OwnerInfo = new string[2]; process.InvokeMethod("GetOwner", (object[])OwnerInfo); return OwnerInfo[0]; } catch { return string.Empty; } } return string.Empty; }
桂棹兮兰桨,击空明兮溯流光。