template-cmd/script.cmd
2023-01-05 19:59:52 +03:00

36 lines
628 B
Batchfile

pushd "%~dp0"
@echo off
goto :Start
--------------------------------------------------
Returning current username if privileged rights are exist
or
returning error, if privileged rights are not exist
Positional parameters:
[1] qn - execution without pauses
Administrator rights required.
--------------------------------------------------
:Start
set basename=%~n0
:Admin_Check
openfiles >nul 2>&1
if %errorLevel% == 0 (
set code=0
) else (
set code=5
cls
echo Restart this as Administrator!
goto :Exit
)
:Show_Username
echo Running %basename% as %username%
:Exit
if "%~1" NEQ "qn" pause
popd
exit %code%