c# - 如何确保 Process.Start 不会抛出 Win32Exception "File not found"
问题描述
我通过引用仅文件名的可执行文件生成 ProcessStartInfo,而不提供绝对路径。我希望操作系统通过使用 PATH 环境变量来解析具体位置。
但是,在某些安装中,PATH 变量设置不正确,并且在通过调用启动进程Process.Start()
时会抛出一个
System.ComponentModel.Win32Exception
该系统找不到指定的文件
是否有编程选项来检查 Process.Start 是否可以预先工作?
我尝试使用File.Exists(fileName)
,但这仅适用于位于应用程序工作目录中的文件。
在命令提示符下,您可以使用以下调用来确定它是否有效:
//example where a file is found
C:\>where calc.exe
C:\Windows\System32\calc.exe
//example where a file is not found
C:\>where foo.exe
INFO: Could not find files for the given pattern(s).
.net 中是否有类似的东西可以预先确定文件路径是否可以解析,以便 Process.Start() 不会抛出?
解决方案
推荐阅读
- java - Spark 中的复制是如何工作的?
- python - Django:自定义 LoginView 未对用户进行身份验证
- wordpress - 在 Wordpress 中创建重定向规则
- python - 如何向现有 JSON 文件添加嵌套未知数量级别的新 JSON 节点?
- visual-studio-code - 在编辑器中折叠部分时是否可以折叠降价预览?
- objective-c - 如何在 Swift 代码中使用 Facebook Places SDK
- node.js - Squeelize 无法访问外键
- java - RecyclerView 项目的属性在使用 DataBinding 时自动更改
- google-sheets - 根据表的内容在第 1 行查找结果
- python - PyMongo 对列表中的项目进行全文搜索