-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
91 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 无参使用时输出所有进程的 pid|绝对路径,有参使用时输出指定pid进程的路径 | ||
// 编译:csc ProcessHelperExt.cs /o /platform:x64 | ||
using System; | ||
using System.Diagnostics; | ||
|
||
if (args.Length > 1) | ||
return 1; | ||
|
||
try | ||
{ | ||
if (args.Length == 1) | ||
{ | ||
int pid = int.Parse(args[0]); | ||
Process p; | ||
try { p = Process.GetProcessById(pid); } | ||
catch (System.ArgumentException) { return 3; } // 不存在pid对应的进程 | ||
Console.WriteLine(p.MainModule.FileName); | ||
} | ||
else | ||
foreach (var p in Process.GetProcesses()) | ||
try { Console.WriteLine("{0}|{1}", p.Id, p.MainModule.FileName); } | ||
catch (System.ComponentModel.Win32Exception) { } // 跳过权限不够的进程 | ||
|
||
return 0; | ||
} | ||
catch { return 2; } |