2
votes

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)

1
run your main application as AdministratorDerviş Kayımbaşıoğlu
Please copy/paste error as text, not as a screenshot.abatishchev
It could be file system redirection messing with your Program Files path... but I don't really think so because of the "requires elevation" part of the exception message. That likely means you need to run your program as administrator.Joel Coehoorn

1 Answers

1
votes

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.