我正在.Net中开发控制台应用程序,我想根据应用程序从cmd.exe或explorer.exe启动的信息稍微更改一下行为.可能吗?
Process this_process = Process.GetCurrentProcess(); int parent_pid = 0; using (ManagementObject MgmtObj = new ManagementObject("win32_process.handle='" + this_process.Id.ToString() + "'")) { MgmtObj.Get(); parent_pid = Convert.ToInt32(MgmtObj["ParentProcessId"]); } string parent_process_name = Process.GetProcessById(parent_pid).ProcessName;