捕获进程的GUID在运行时启动

时间:2013-12-01 23:59:56

标签: c# guid

我不确定如何获取我在运行时启动的进程的GUID。例如:

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.WorkingDirectory = @"C:\MyDir";
proc.StartInfo.FileName = "MyApp.exe";
proc.StartInfo.Arguments = "E F G H";
proc.Start();

我在另一个暴露当前应用程序的GUID的线程中找到了这段代码:

var assembly = typeof(Program).Assembly;
var attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
var id = attribute.Value;

但我不确定如何将此应用于proc或者如果proc中有一个属性将显示其GUID。如何获得proc的GUID?

2 个答案:

答案 0 :(得分:0)

进程没有GUID。

您可以使用Reflection:

从托管程序集中的已知类检索属性
Assembly.Load(path).GetType("Namespace.Type")
                   .GetCustomAttributes(typeof(GuidAttribute), true)[0]

答案 1 :(得分:0)

如果您要查找流程的ID,可以使用proc.Id获取该属性。

请参阅Process.Id Property documentation

相关问题