1

To help my computer boot faster, I created a simple batch file that will open the programs I want, rather than do it all on startup, when I sometimes don't want them to.

@ECHO OFF

cd "C:\Users\Aaron\Documents\Documents"
start SSS.lnk

cd "C:\Program Files (x86)\puush"
start puush.exe

cd "C:\Users\Aaron\AppData\Roaming\Google\Google Talk\"
start googletalk.exe

cd "C:\Users\Aaron\AppData\Local\Facebook\Messenger\2.1.4651.0\"
start FacebookMessenger.exe

cd "C:\Program Files\Synergy\"
start synergy.exe

cd "C:\Program Files (x86)\Skype\Phone\"
start Skype.exe

cd "C:\Program Files (x86)\Miranda IM\"
start miranda32.exe

However,

cd "C:\Users\Aaron\Documents\Documents"
start SSS.lnk

is a service that's set to Manual, and I start that myself, and it requires to be run as administrator to start. Is there anything to add in front of that to run just that as administrator?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Aaron
  • 3,135
  • 20
  • 51
  • 78
  • possible duplicate of [How can I auto-elevate my batch file, so that it requests from UAC admin rights if required?](http://stackoverflow.com/questions/7044985/how-can-i-auto-elevate-my-batch-file-so-that-it-requests-from-uac-admin-rights) – parvus Jul 29 '14 at 09:26

3 Answers3

4

You might wish to have a look at Runas.

Short answer: You can use runas.exe:

C:\>runas /user:<localmachinename>\administrator cmd

or

runas.exe /user:administrator "full qualified path to your exe"

For the last cmd, you can add /savecred to save the administrator's password (not that I'm saying this is a good idea).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Najzero
  • 3,164
  • 18
  • 18
  • Okay. Now if I wanted to combine that with "cd "C:\Users\Aaron\Documents\Documents" start SSS.lnk" ? – Aaron Mar 01 '13 at 06:47
  • 2
    `runas.exe /user:administrator "start C:\Users\Aaron\Documents\Documents\SSS.lnk"` should do the trick – Najzero Mar 01 '13 at 06:48
  • http://www.computerperformance.co.uk/win8/windows8-administrator-activate.htm - you can also replace user:administrator with a user having admin rights. – Najzero Mar 01 '13 at 06:55
  • Right. I changed it to my login "email@gmail.com" and now I get: RUNAS ERROR: Unable to run - start C:\Users\Aaron\Documents\Documents\SSS.lnk 2: The system cannot find the file specified. – Aaron Mar 01 '13 at 06:56
  • I changed it to runas.exe /user:talormanda@gmail.com "C:\Users\Aaron\Documents\Documents\SynergyService.bat" it is suppose to start a service but it failed. It will launch .exe 's however, but they are not being run as admin. – Aaron Mar 01 '13 at 07:11
  • Are you asking if you can bypass the UAC prompt? You can't. That's the whole point of having UAC in the first place. – Bill_Stewart Mar 12 '13 at 15:44
2

Workaround: Create a shortcut to your script. Go to properties, shortcut, advanced. Check "run as administrator".

There you go; every time you access via shortcut it will open as administrator.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • I came here to write this as answer :) This works like charm. Most answers think of _runas_ which asks password. This is the way to go about it without knowing Admin password. – Atul Oct 27 '19 at 06:38
0

There some misunderstoods:

  1. How to get localmachinename

    There are many ways, some of them are:

    a. c:\>hostname or

    b. c:\>echo %computername%

  2. You can't use runas [...] command if you don't have set password to your Windows.

    1327: Logon failure: user account restriction. Possible reasons are blank passwords not allowed, logon hour restrictions, or a policy restriction has been enforced.

AntonyMan
  • 31
  • 4