C#中:如何获得运行进程的完整路径?

编程入门 行业动态 更新时间:2024-10-27 22:34:35
本文介绍了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#中:如何获得运行进程的完整路径?

本文发布于:2023-11-16 02:13:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1600073.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何获得   路径   进程   完整

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!