Starting Windows - how to start a program as an administrator from a batch file

In Windows 8.1, I try to run the program from a batch file that is called at startup, and I want the program to run as an administrator. That's what I'm doing:

  • I have prog.exe program in c: \ program \ MyProgram directory
  • EXE is marked as "Run as administrator"
  • There is a batch file RunexE.bat in the c: \ program \ MyProgram directory. It contains all kinds of things, and at the end it contains the line "start prog.exe"
  • under "C: \ programdata \ Microsoft \ Windows \ Start Menu \ Programs \ StartUp" there is a shortcut for RunEXE.BAT.
  • When rebooting the PC, I expect the shortcut to run RunexE.BAT, which in turn will launch PROG.EXE.

But this does not happen. There is a short β€œsound” sound, as if Windows displayed a message asking you to confirm that the program should work as an administrator, but nothing is visible on the screen.

a) If I mark the shortcut and exe NOT to run as administrator, then the EXE starts.
b) If I mark the shortcut and exe to run as administrator, then the exe does not start.
c) If I mark the shortcut NOT to run as administrator and EXE to run as administrator, then the EXE starts , but it does not start as an administrator .
d) Launching a shortcut for EXE. (No party). Label not marked as administrator, exe marked: exe does not work.
e) Launch shortcut for exe. (No party). Label not marked as administrator, EXE not marked: EXE is running, but not as administrator.

I tried to completely disable UAC - the same results. I also tried using another exe instead of a batch with the same results.

So - is there a way to run the shortcut for EXE at startup that will launch the EXE as an administrator?

+5
source share
2 answers

You can do this using the task scheduler.

Open the Win + R startup dialog and run the following command:

 %SystemRoot%\system32\taskschd.msc 

Hit Create Task...

  • Set name (I installed it FooBar)
  • Check Run with highest privileges
  • Go to the Actions , New.... tab, go to prog.exe
  • Save task

Go to your .bat file and in the place where you want to run prog.exe add

 schtasks /run /tn "FooBar" 

The bat file should not be run as an administrator (if he does not need it), prog.exe will start without any prompts.

+6
source

It is easy to pick up a script package if you have powershell on your computer:

 net file 1>nul 2>nul && goto :run || powershell -ex unrestricted -Command "Start-Process -Verb RunAs -FilePath '%comspec%' -ArgumentList '/c %~fnx0 %*'" 
0
source