Page 1 of 1

Batch file / command line disable UAC without restart?

Posted: 28 Sep 2013 21:14
by Rydell
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...

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

Posted: 29 Sep 2013 04:34
by aGerman
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

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

Posted: 29 Sep 2013 17:20
by Rydell
Would there be a way to make it prompt like a normal installer instead of just giving me access denied errors?

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

Posted: 29 Sep 2013 17:39
by aGerman
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

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

Posted: 29 Sep 2013 19:26
by Dos_Probie
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");

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

Posted: 30 Sep 2013 04:29
by Adrianvdh
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 )

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

Posted: 30 Sep 2013 05:41
by Dos_Probie
@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..