You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 6中Process.Start("powerpnt.exe")失效,如何无完整路径调用程序?

在Visual Basic .NET与.NET 6中调用外部应用的替代方法(无需完整路径)

在.NET 6及后续版本中,Process.Start(string)这一直接传入可执行文件名的重载已被标记为过时,且默认UseShellExecute属性为False,导致系统不会通过PATH环境变量查找目标程序,因此原调用方式失效。以下是无需指定完整路径的可行方案:

方法一:使用ProcessStartInfo并启用UseShellExecute

通过ProcessStartInfo配置启动参数,开启UseShellExecute后,系统会自动在PATH路径中查找指定的可执行文件,示例代码如下:

Imports System.Diagnostics

' 启动PowerPoint
Dim startInfo As New ProcessStartInfo("powerpnt.exe") With {
    .UseShellExecute = True
}
Process.Start(startInfo)

方法二:简化版重载调用

也可以直接调用带ProcessStartInfo参数的重载,写成一行代码:

Imports System.Diagnostics

Process.Start(New ProcessStartInfo("powerpnt.exe") With {.UseShellExecute = True})

注意事项

  • 确保目标应用的可执行文件路径已添加到系统的PATH环境变量中,否则即使启用UseShellExecute也无法找到程序。
  • 如果需要重定向标准输入/输出(如控制台程序交互),UseShellExecute必须设为False,这种场景下需手动遍历PATH路径查找可执行文件,无法完全依赖系统自动查找。

内容的提问来源于stack exchange,提问作者FNDevCJ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 05:05:02