我正在获取启动应用程序的列表,并且只想获取启动时运行的应用程序的路径。启动应用程序列表还包含传递给应用程序的参数,它们的格式不同。例子是
C:\ Program Files(x86)\ Internet下载管理器\ IDMan.exe / onboot
“ C:\ Program Files \ Process Hacker 2 \ ProcessHacker.exe”-隐藏
“ C:\ Program Files \ CCleaner \ CCleaner64.exe” / MONITOR
“ C:\ Program Files(x86)\ Google \ Chrome \ Application \ chrome.exe” --no-startup-window / prefetch:5
“ C:\ Program Files(x86)\ GlassWire \ glasswire.exe”-隐藏
C:\ Program Files \ IDT \ WDM \ sttray64.exe
我正在尝试使用以下正则表达式
Regex.Matches(input, "([a-zA-Z]*:[\\[a-zA-Z0-9 .]*]*)");
请指导我如何仅提取应用程序路径而忽略所有参数和其他启动命令。
试试这个简单的方法:
string cmd = "\"C:\\Program Files (x86)\\GlassWire\\glasswire.exe\" -hide";
int index = cmd.ToLower().LastIndexOf(".exe");
string path = cmd.Substring(0, index+4);
index = path.IndexOf("\"");
if (index >= 0)
path = path.Substring(index + 1);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句