Batch file / command line disable UAC without restart?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Rydell
Posts: 11
Joined: 02 May 2013 17:45

Batch file / command line disable UAC without restart?

#1 Post by Rydell » 28 Sep 2013 21:14

I have a batch with a menu that performs a series of tasks for peoples Win 7 machines and I'm looking for a command to disable the UAC that doesn't require a restart. The simple line I test this with is:

IF NOT EXIST "C:\Program Files\Utilities" mkdir "C:\Program Files\Utilities"

I get an Access is Denied error unless I enter the registry fixes and restart, or manually adjust the slider to never notify. I'd like to keep the batch as streamline as possible without making them go "here and there" first. So far, I got the whole thing down and automated, and it's just come down to this being the problem. I've tried:

setlocal
set runlevel= highest

set __COMPAT_LAYER=RunAsInvoker

Neither have worked. There's GOT to be something out there...

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch file / command line disable UAC without restart?

#2 Post by aGerman » 29 Sep 2013 04:34

Thank goodness - there is no way to bypass the UAC. Microsoft did their best effort not to allow any programatically encroachments. Malware and viruses would have an easy time otherwise.
BTW: Thats the reason why every installer asks you for UAC confirmation. Otherwise it would not be able to write into HKLM or Program Files.

Regards
aGerman

Rydell
Posts: 11
Joined: 02 May 2013 17:45

Re: Batch file / command line disable UAC without restart?

#3 Post by Rydell » 29 Sep 2013 17:20

Would there be a way to make it prompt like a normal installer instead of just giving me access denied errors?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch file / command line disable UAC without restart?

#4 Post by aGerman » 29 Sep 2013 17:39

Either you right-click onto the batch file and choose "Run as administrator"
or
- create a shortcut to the batch file
- right-click > Properties
- tab "Shortcut" > button "Advanced ..."
- check "Run as administrator" > button "OK"
- "OK"

Regards
aGerman

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Batch file / command line disable UAC without restart?

#5 Post by Dos_Probie » 29 Sep 2013 19:26

Just run your batch as admin with this jscript added..

Code: Select all

@set @jscript=1/*
 @echo off&setlocal

:: ### ADMIN CHECK..
 reg query "hku\S-1-5-19" >nul 2>&1 || (
   @cscript //e:jscript //nologo "%~f0" "%~f0"
   goto :eof
 )

 < BATCH CODE HERE>
 
:eof
 // ### RUN AS ADMIN..
 */
 var strArg = WScript.Arguments(0);
 var objSH = WScript.CreateObject("Shell.Application");
 objSH.ShellExecute(strArg, "", "", "runas", "5");

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: Batch file / command line disable UAC without restart?

#6 Post by Adrianvdh » 30 Sep 2013 04:29

Or you can use this code to check your script has Admin rights:

Code: Select all

reg query "HKU\S-1-5-19" >nul 2>&1 && (
echo GOT ADMIN
pause
) || (
echo SORRY
ping localhost -n 3 >nul
exit )

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Batch file / command line disable UAC without restart?

#7 Post by Dos_Probie » 30 Sep 2013 05:41

@Adrianvdh
Your code is basically a Admin check if the current user has admin privileges prior to running the batch file, I believe
the OP wanted a way for the end user to just run his batch without doing anything extra, my solution will provide that by elevating the permissions level without the access denied popup..

Post Reply