【发布时间】:2019-05-29 12:45:21
【问题描述】:
我编写了一个程序来消除崩溃后 .xml 文件中的 NULL 或零等意外错误,但代码的“重新启动”部分不起作用。当我在 Visual Studio Code 中运行代码时一切都很好,但是当我使用 dotnet publish 函数中的 .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 没有错误:
未处理的异常:System.ComponentModel.Win32Exception:请求的操作需要提升 在 System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) 在 System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
【问题讨论】:
-
以管理员身份运行您的主应用程序
-
请将错误复制/粘贴为文本,而不是屏幕截图。
-
可能是file system redirection 弄乱了您的程序文件路径...但我不这么认为,因为异常消息的“需要提升”部分。这可能意味着您需要以管理员身份运行程序。