Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm alway using the following code for automatically prompting UAC.It works fine on Windows Vista/7/2008.But it seems that on Windows 8 the script can't get the administrator privilege even the UAC prompts and I click yes.Anything changed?

:: Get Administrator Privilege on Windows Vista/7/2008
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
IF '%errorlevel%' NEQ '0' (
    ECHO Requesting administrative privileges...
    GOTO UACPrompt
) ELSE ( GOTO gotAdmin )

:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B

:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Turns out there is nothing to do with the administrator privilege.The problem is about the default System PATH variables on some of my Windows 8 machines.C:\windows\system32 is not included in the system path,so all the administration cmds can't be executed unless the currenty directory is C:\Windows\system32.

Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

C:\Windows\system32>net stop wuauserv
The Windows Update service is stopping.
The Windows Update service was stopped successfully.


C:\Windows\system32>cd %userprofile%

C:\Users\itadmin>net start wuauserv
'net' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\itadmin>set PATH
Path=.;C:\Program Files\Java\jre7\BIN;C:\Program Files\jre1.7.0_21;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

C:\Users\itadmin>

As a solution , I added the following line into the batch:

SET PATH=%PATH%;C:\Windows\System32\
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.