C#中:如何获得运行进程的完整路径? [英] C#: How to get the full path of running process?

查看:953
本文介绍了C#中:如何获得运行进程的完整路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种情况正在改变其他应用程序的某些设置一个应用程序(它是通过双击运行(无需安装)一个简单的C#应用​​程序)。

更改设置后我需要重新启动其他应用程序,以便它反映了更改的设置。

那么做,我要杀死正在运行的进程,并重新启动的过程中,但问题是杀戮,我无法找到后工序。 (原因是系统不知道该EXE文件。)

有没有办法找出正在运行的进程或EXE的路径,如果它正在运行?

我不希望如果它正在运行获取路径,杀proccess并开始再次别的手动给路径,即....稍后我会处理


解决方案

 使用System.Diagnostics程序;
 变种过程= Process.GetCurrentProcess(); //或者你使用任何方法
 字符串FULLPATH = process.MainModule.FileName;
 //完整路径有exe文件的路径。

有一个接球这个API,如果你正在运行32位程序的code,你不能够访问64位应用程序的路径,所以你必须编译并运行应用程序你作为64位应用程序。 (项目属性 - >建设 - >目标平台 - > 64)

I am having a application that is changing some settings of other application (it is a simple C# application that run by double clicking (no setup required)).

After changing the settings I need to restart the other application so that it reflects the changed settings.

So to do, I have to kill the running process and start the process again, But the problem is after killing I am not able to find the process. (Reason is system do not know where the exe file is..)

Is there any way to find out the path of running process or exe, if it is running?

I do not want to give path manually, i.e. if it is running get the path, kill the proccess and start again else .... I will handle later

解决方案

 using System.Diagnostics;
 var process = Process.GetCurrentProcess(); // Or whatever method you are using
 string fullPath = process.MainModule.FileName;
 //fullPath has the path to exe.

There is one catch with this API, if you are running this code in 32 bit application, you'll not be able to access 64-bit application paths, so you'd have to compile and run you app as 64-bit application. (Project Properties -> Build -> Platform Target -> x64)

这篇关于C#中:如何获得运行进程的完整路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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