.net - 是否可以确定哪个进程启动了我的 .Net 应用程序?

标签 .net windows process-management

我正在 .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/

相关文章:

.net - 比较 .Net 和 VB6 应用程序的内存占用

.net - 为什么不能在PowerShell中的事件处理程序中设置表单的DialogResult?

c - 在C中获取当前进程CPU使用率

android - 您可以跟踪 Android 应用程序何时终止吗?

c - 插入排序什么都不做

windows - 跟踪每个进程的 CPU 和内存使用情况

c# - 按 Enter 键单击一个 LinkLabel

c# - 加载资源: 403 forbidden with . js优化失败

c++ - 如何在启用自动隐藏的情况下检测 Windows 中任务栏的高度和方向?

windows - 批处理文件 : get the creation date of a folder