I am looking to write a script that takes user input, then makes system wide changes. I need this to be very generic, but simply put, at the top, I need it to check to see if it’s being run ‘As an Administrator’. If it’s not, then I want to display a message to tell them that; if it is, I want it to continue on. Is there a constant way to verify this? I am not looking to start a new session as the Administrator, I just want to detect if it’s currently run as admin
Solution:
Found this on Stack Overflow:
@echo offgoto check_Permissions:check_Permissionsecho Administrative permissions required. Detecting permissions...net session >nul 2>&1if %errorLevel% == 0 ( echo Success: Administrative permissions confirmed.) else ( echo Failure: Current permissions inadequate.)pause >nul