Kacper Nowicki
Kacper Nowicki

Reputation: 23

Cannot launch .exe with another .exe

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

Answers (1)

Derviş Kayımbaşıoğlu
Derviş Kayımbaşıoğlu

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

Related Questions