0

The thing is I want to run a batch file in system context. I will just drag and drop the batch file on the exe file (icon). Now, it should automatically open psexec and run the batch file in system context. I have the code. But the only problem lies here: the cmd is not running as admin due to which psexec won't run. Please, can someone point me out where I'm going wrong

    Process process = new Process();
process.StartInfo.FileName = "psexec.exe";
process.StartInfo.Arguments = " -i -s -accepteula cmd /c \" msiexec /i " + fPath + " /qn /l*v \u0022%~dp0" + fileName + "\u0022 \"";
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = false;
process.StartInfo.Verb = "runas.exe";
process.Start();
process.WaitForExit(60000);
Owen Pauling
  • 11,349
  • 20
  • 53
  • 64
Praveen
  • 231
  • 1
  • 4
  • 15
  • Is the user running the program, running it as Administrator? – Allan S. Hansen May 18 '15 at 12:07
  • @Allan I forgot to add that info. All users who will be using it are present in administrators group. Let me know if you need more info. Thanks – Praveen May 18 '15 at 12:10
  • 2
    just being in the admin group is not enough, you have to explicitly ask the exe to request that admin elevation embed a manifest in your c# exe to always run as admin, http://stackoverflow.com/questions/2818179/how-to-force-my-net-app-to-run-as-administrator-on-windows-7 this would .. embed the manifest and you should be good to go. – user734028 May 18 '15 at 12:12
  • Allan is right. The cmd process needs to be running as admin (ie right click "Run as administrator"). – garryp May 18 '15 at 12:13
  • he doesnt want to right click, he wants to drop the batch file on the exe, when that exe launches it should be on the admin previlege, in my opinion the exe should ask for them through the windows' admin box (cuz of the embedded manifest), upon click Yes, the rest of the process will be with admin rights. – user734028 May 18 '15 at 12:15
  • OT comment: I don't think it's a good idea to circumvent windows security systems in that way – Random Dev May 18 '15 at 12:22
  • 1
    Thanks guys! http://stackoverflow.com/questions/2818179/how-to-force-my-net-app-to-run-as-administrator-on-windows-7 really did help. – Praveen May 18 '15 at 12:31

0 Answers0