gpt4 book ai didi

c# - 无法用另一个 .exe 启动 .exe

转载 作者:太空宇宙 更新时间:2023-11-03 12:07:50 25 4
gpt4 key购买 nike

我编写了一个程序来消除意外错误,例如崩溃后 .xml 文件中的 NULL 或零,但代码的“重新启动”部分无法正常工作。当我在 Visual Studio Code 中运行代码时,一切都很好,但是当我使用 dotnet 发布函数中的 .exe 文件时,程序就崩溃了。

我已经尝试将 UAC 设置为 0 级,UseShellExecute true/false,System.Diagnostics.Process.Start();,以管理员身份运行。

static string exeAdress = @"C:\Program Files (x86)\NaturalPoint\SmartNav\SmartNAV.exe";

// Process.Start(exeAdress); // this isn't working either

Process p = new Process();
p.StartInfo.FileName = exeAdress;
p.StartInfo.UserName = "User";
p.StartInfo.Domain = "Domain";
p.StartInfo.UseShellExecute = true;
p.StartInfo.CreateNoWindow = false;

实际输出抛出异常,但我希望运行 exe 时没有错误:

Unhandled Exception: System.ComponentModel.Win32Exception: The requested operation requires elevation at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)

最佳答案

您需要以管理员身份运行您的主应用程序(具有提升的权限)。

如果您可以使用提升的用户运行您的应用程序,那么您不需要提供

p.StartInfo.UserName = "User";
p.StartInfo.Domain = "Domain";

参数。

关于c# - 无法用另一个 .exe 启动 .exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54013630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com