Reputation: 23
I wrote a program to get rid of unexpected errors like NULLs or zeros in .xml file after crash but the "restart" part of code isn't working. It's all good when I run the code in Visual Studio Code but when I use .exe file from dotnet publish function the program just crashes.
I've already tried setting UAC at level 0, UseShellExecute true/false, System.Diagnostics.Process.Start();, running as administrator.
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;
Actual output is throwing exception but I expect to run the exe without errors:
Unhandled Exception: System.ComponentModel.Win32Exception: The requested operation requires elevation at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
Upvotes: 2
Views: 479
Reputation: 30545
You need to run your main application as administrator (with elevated permission).
If you can run your application with elevated user then you do not need to supply
p.StartInfo.UserName = "User";
p.StartInfo.Domain = "Domain";
parameters.
Upvotes: 1