我正在 .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;
关于.net - 是否可以确定哪个进程启动了我的 .Net 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53501/