43

I'm currently running a startup script in form of a bat file successfully in Windows 7 (I've inserted a new registry key entry with the bat file path as value in

Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run).

Now I need to run another bat file at startup, but with elevated rights (as administrator), and without manually confirming a prompt.

How can I achieve this, preferrably without external programs?

joe
  • 12,279
  • 12
  • 67
  • 104
simon
  • 1,614
  • 3
  • 17
  • 24
  • Does this one have a solution? http://serverfault.com/questions/429364/how-to-run-a-command-as-administrator-on-windows7-from-a-command-line – Radek Sep 18 '12 at 06:55
  • 1
    I'm confused. Isn't the ability to bypass the UAC prompt a huge security concern? Doesn't that defeat the purpose of the prompt even existing? – Kyle Delaney May 02 '18 at 20:07
  • The answer https://superuser.com/questions/770420/schedule-a-task-with-admin-privileges-without-a-user-prompt-in-windows-7/770439#770439 is useful in this case; in particular "Run with highest privileges" is really important. – Basj Oct 16 '20 at 15:01

8 Answers8

28

See this article : Run UAC restricted programs without the UAC prompt.

This article shows how to use the Task Scheduler to launch startup programs with elevated privileges. Some small changes may be required in your case, but the article is well-written with screenshots.

The answer Schedule a task with admin privileges without a user prompt in windows 7 is useful in this case; in particular "Run with highest privileges" is really important.

harrymc
  • 455,459
  • 31
  • 526
  • 924
  • 4
    It'd be nice if this wasn't just a link. :) – Ƭᴇcʜιᴇ007 Dec 01 '16 at 17:51
  • 1
    @Ƭᴇcʜιᴇ007: There are lots of full tutorials for this well-known procedure, still valid today since Vista. This is a very old answer and I probably would have answered with more detail today, but I am also not sure I agree with the latest tendency on SU to insist on long tutorial-like answers. Not every answer needs to be a mini-tutorial, and this answer does describe the principe and the link is to a solid website. – harrymc Dec 01 '16 at 20:23
  • 3
    I feel like this could become a battle of titans! But actually, I do agree with @Ƭᴇcʜιᴇ007 on this: Links are good, but they can go bad, rendering an answer such as this meaningless in the future. – music2myear Dec 19 '16 at 16:56
  • 1
    @music2myear: The [google query](https://www.google.fr/search?q=Task+Scheduler+startup+programs+elevated+privileges&btnG=Search&num=30&safe=off&client=firefox-b) has about 369,000 results! Many are of a much better quality than I could/would do. – harrymc Dec 19 '16 at 17:32
  • 3
    Then instead of posting an “answer” that is essentially a just lmgtfy, you could have just posted a link to the Google query as comment to the original answer. But then, you don’t get rep for posting comments, now do you? – Synetech May 11 '17 at 00:19
  • @Synetech: Not the type of answer I would write today, 8 years later, but it was and is still useful. But then, posting comments that most people don't read, how does it help? – harrymc May 11 '17 at 07:29
  • The link is dead. However the same author wrote another article saying that the technique in the new one is better than the old one: [Run UAC restricted programs without the UAC prompt](https://www.techrepublic.com/article/run-uac-restricted-programs-without-the-uac-prompt/ "Run UAC restricted programs without the UAC prompt | TechRepublic") – Ooker Aug 20 '22 at 05:16
  • @Ooker: Thanks - I replaced the link in my answer. – harrymc Aug 20 '22 at 07:38
4

Make two batch files:

StartAs.bat contains something along the lines of:

runas /user:SomeLocalAdminAccount c:\Users\MyUser\StartupWhat.bat

StartWhat.bat contains the commands that you want to run.

Gaff
  • 18,569
  • 15
  • 57
  • 68
vana.yp
  • 49
  • 1
  • 1
    Still asks that the file be run with elevated priveledges – Joe Taylor Sep 27 '11 at 13:45
  • This worked great for me but I additionally had to add the flag /savecred. With that flag set, when you run the command the 1st time it asks you for the admin password and saves it to the windows credential manager store. After that, it works without prompt on subsequent runs. – Ocean Airdrop Mar 02 '22 at 11:09
3

Have you thought of a different approach? Either a pure group policy for the equivelent registry setting, else setting the batch file to run as a group policy. It maybe that you could even run it as a computer script, rather than a user script.

Start with gpedit.msc. However, it does need Ultimate or one of the other top end editions.

Guy Thomas
  • 3,288
  • 10
  • 35
  • 48
3

hstart.exe - 3rd party start.exe replacement at http://www.ntwind.com/software/hstart.html

The invocation is a bit of a pain, but it works really well.

ClioCJS
  • 137
  • 1
  • 1
  • 14
  • 1
    Please exercise caution when recommending software. As written, your answer may be seen as spam. Your answer should include a description of the software and how it addresses the question. More information: [How do I recommend software in my answers?](http://meta.superuser.com/q/5329) – bwDraco Oct 03 '15 at 00:04
  • 1
    Thanks, but no thanks. I don't consider it my responsibility if people falsely assume incorrect things due to their own pessimism and bitterness. I had this problem, and that was my solution to it. – ClioCJS Oct 03 '15 at 17:46
2

AutoExnt utility, from the Resource Kit.

The AutoExNT service permits an administrator to configure a Windows based computer to run a custom batch file when first starting the computer. Also, a user or administrator is not required to be logged on at the time this custom batch file runs.

joe
  • 12,279
  • 12
  • 67
  • 104
1

runas /user:SomeLocalAdminAccount

Here must be like this:

runas /noprofile /user:mymachine\administrator cmd

runas /profile /env /user:mydomain\admin "mmc %windir%\system32\dsa.msc

runas /env /user:user@domain.microsoft.com "notepad \"my file.txt\""
studiohack
  • 13,468
  • 19
  • 88
  • 118
1

Maybe UACPass (free) will solve it:

  • Install the program.
  • Open the UACPass window.
  • Drag to it the program you are pretending to run at boot.

Done. This program should now run as admin without UAC prompt.
The program even has an option for add to startup :-D .

Your program will only run after logon (or so I think).

Sopalajo de Arrierez
  • 6,603
  • 11
  • 63
  • 97
-1

You can also make a shortcut and specify that the shortcut's file should be run elevated.

(It's in some advanced options box.)

riking
  • 11
  • This doesn't work for shortcuts to bat files. Try it. – Joe Taylor Sep 27 '11 at 13:43
  • @JoeTaylor And how about creating a shortcut to cmd.exe and giving the bat file in the cmdline? – Werner Henze Nov 27 '13 at 17:43
  • @werner Henze - have you tried it? – Joe Taylor Dec 02 '13 at 13:01
  • @JoeTaylor: _This doesn't work for shortcuts to bat files._ What exactly do you mean with this? The "run as admin" Checkbox is available for shortcuts to a bat file and for shortcuts to cmd.exe (both tested a few minutes ago). But: the questioner does not want the UAC prompt, and the Checkbox will Trigger the UAC prompt (depending on the UAC Settings). – Werner Henze Dec 02 '13 at 13:13
  • The run as elevated, whilst surpressing UAC prompts does not work in the way that the answer intends it to. That's what I meant. Therefore it is not the answer the OP was looking for. – Joe Taylor Dec 02 '13 at 13:18