流程的开始时间 [英] Starting time of a process

查看:54
本文介绍了流程的开始时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#代码检索进程的开始时间?如果可能的话,我还想知道如何使用Widows内置的功能来做到这一点.

How do I retrieve the starting time of a process using c# code? I'd also like to know how to do it with the functionality built into Widows, if possible.

推荐答案

 public DateTime GetProcessStartTime(string processName)
 {
        Process[] p = Process.GetProcessesByName(processName);
        if (p.Length <= 0) throw new Exception("Process not found!");
        return p[0].StartTime;
 }

如果您知道进程的ID,则可以使用Process.GetProcessById(int processId).另外,如果进程在网络上的另一台计算机上,则对于GetProcessesByName()和GetProcessById()都可以将计算机名称指定为第二个参数.

If you know the ID of the process, you can use Process.GetProcessById(int processId). Additionaly if the process is on a different machine on the network, for both GetProcessesByName() and GetProcessById() you can specify the machine name as the second paramter.

要获取进程名称,请确保该应用程序正在运行.然后转到应用程序"选项卡上的任务管理器,右键单击您的应用程序,然后选择继续处理".在流程"标签中,您将看到流程名称突出显示.在C#代码中的.exe之前使用名称.例如Windows窗体应用程序将列为"myform.vshost.exe".在代码中您应该说

To get the process name, make sure the app is running. Then go to task manager on the Applications tab, right click on your app and select Go to process. In the processes tab you'll see your process name highlighted. Use the name before .exe in the c# code. For e.g. a windows forms app will be listed as "myform.vshost.exe". In the code you should say

 Process.GetProcessesByName("myform.vshost"); 

这篇关于流程的开始时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆