我编写了一个程序,以消除崩溃后.xml文件中的意外错误(如NULL或零),但是代码的“重新启动”部分无法正常工作。当我在Visual Studio Code中运行代码时,一切都很好,但是当我使用dotnet publish函数中的.exe文件时,程序就会崩溃。
我已经尝试将UAC设置为0,UseShellExecute是/否,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时不会出错:
未处理的异常:System.ComponentModel.Win32Exception:请求的操作需要提升 在System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) 在System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
答案 0 :(得分:1)
您需要以管理员身份(具有提升的权限)运行主应用程序。
如果您可以以提升的用户身份运行应用程序,则无需提供
p.StartInfo.UserName = "User";
p.StartInfo.Domain = "Domain";
参数。