Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows startup - how to run a program as administrator from a batch file

On Windows 8.1, I am trying to start a program from a batch file which is called during startup and I want the program to run as Administrator. Here is what I do:

  1. I have a program prog.exe under c:\program files\MyProgram
  2. The EXE is flagged to "Run as Administrator"
  3. Under c:\program files\MyProgram there is a batch file called RunEXE.bat. It contains all sorts of things and the end it contains a line "start prog.exe"
  4. under "C:\programdata\Microsoft\Windows\Start Menu\Programs\StartUp" there is a shortcut to RunEXE.BAT.
  5. When I reboot the PC I expect the shortcut to launch the RunEXE.BAT which in turn will run PROG.EXE.

But it does not happen. There is a short "bleep" sound as if Windows is displaying a message asking to confirm the program should run as Administrator but nothing is visible on the screen.

a) If I flag the shortcut & exe NOT to run as admin, then the EXE is launched.
b) If I flag the shortcut & exe to run as admin, then the EXE is not launched.
c) If I flag the shortcut to NOT to run as admin and the EXE to run as admin then the EXE is launched but it does not run as administrator.
d) Startup shortcut to the EXE. (No batch). Shortcut not flagged to run as administrator, EXE is flagged: EXE not running.
e) Startup shortcut to the EXE. (No batch). Shortcut not flagged to run as administrator, EXE not flagged: EXE is running but not as administrator.

I tried disabling the UAC completely - same results. I also tried to have another EXE instead of the batch, with the same results.

So - is there a way to have a shortcut to an EXE from startup which will run an EXE as administrator?

like image 835
yaronkl Avatar asked Apr 15 '15 00:04

yaronkl


1 Answers

You can do it with help of the Task Scheduler.

Open Run dialog Win + R and run following command:

%SystemRoot%\system32\taskschd.msc

Hit Create Task...

  1. Set name (i set it FooBar)
  2. Check Run with highest privileges
  3. Switch to Actions tab, New...., browse to your prog.exe
  4. Save task

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

schtasks /run /tn "FooBar"

Bat file doesn't have to run as administrator (if it doesn't need to), prog.exe will start elevated without any prompts.

like image 79
Xeevis Avatar answered Nov 18 '22 15:11

Xeevis