-2

I have a batch file that requests UAC privileges. When the UAC box pops up and a user clicks the no button I want to display message No administration privileges granted. Now exiting. and then wait three seconds before exiting. Currently If a user clicks the yes button the UAC prompt works, but in the background on a separate window with the exit message I applied above.

I have tried to create an IF statement towards the end of the file to specify which exit takes place dependent on the yes/no press.

Essentially I want to do a quick exit of the other command prompt window if a user clicks yes or display the exit message for the three seconds before exiting. Any ideas?

  IF '%params%' EQU == 1 (
    ECHO No administration privileges granted. Now exiting.
    TIMEOUT 3 >NUL
    EXIT /B
) ELSE ( EXIT )
@ECHO OFF
REM Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM Check if UAC has been granted 
IF '%errorlevel%' EQU '0' (
    GOTO Administration_Granted
) ELSE ( GOTO UAC_Prompt )

REM Request administration privileges
  :UAC_Prompt
  ECHO Requesting administration privileges.
  ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
  SET params = %*:"=""
  ECHO UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

  "%temp%\getadmin.vbs"
  DEL "%temp%\getadmin.vbs"
  CLS

  IF "%params%"=="1" (
    ECHO No administration privileges granted. Now exiting.
    TIMEOUT 3 >NUL
    EXIT /B
) ELSE ( EXIT )



REM Administration Granted
:Administration_Granted
ECHO Administration privileges have been granted
TIMEOUT 2 >NUL
PAUSE
  • Closing the spaces around the = breaks the batch file. What am I supposed to be doing with the set a = 5? – willowen100 May 12 at 20:36
0

I'm going to ask on a different website as my own question is being marked down for no apparent reason, comments disappear, and I get told off for using please and thank you. Just because it's not a forum doesn't mean manners should be disallowed...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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