New
#1
Check for Administrator rights in Batch file.
I basically want to check if the user has Administrator rights before executing the rest of the code. I want to have something like a bit of standalone code that can be added to the top of other scripts to check for Administrator rights first!
Am I right in saying that this code . . .
. . . will not run Run_Go unless the user has elevated command privileges [Administrator rights]? Also, do I need an IF...ELSE in there instead of using Call?Code:FOR /F "tokens=1,2*" %%V IN ('bcdedit') DO SET adminTest=%%V IF (%adminTest%)==(Access) GOTO Not_Admin Call :Run_Go :Not_Admin Code goes here. :Run_Go Code goes here.
I have seen other code like this . . .
. . . that I run on a machine with Administrator rights and it said that I didn't have Administrator rights!Code:echo off goto check_Permissions :check_Permissions echo Administrative permissions required. Detecting permissions... net session >nul 2>&1 if %errorLevel% == 0 ( echo Success: Administrative permissions confirmed. ) else ( echo Failure: Current permissions inadequate. ) pause >nul
Any help will be appreciated.