You can handle parameters in a much simpler way. Your subroutine does not need to know the name of the global variable. You can pass it as one of the variables.
Example script, tested under Windows XP.
@echo off
:: Test if the current user is a local adminisrator.
:: Assume the users is not an administrator.
SET ISADMIN=FALSE
::Test current user.
call :ADMINTEST %USERNAME% ISADMIN
echo %ISADMIN%
pause
Goto END
::------------------------------------------------------------------------------
:: This routine will test if the User ID passed in parameter1 is a member
:: of the local administrators group. It will return "TRUE" in parameter 2
:: if the User ID is an admin.
:ADMINTEST
SETLOCAL
net localgroup administrators | find "%1%"
if %ERRORLEVEL% EQU 0 (
ENDLOCAL & SET "%~2=TRUE"
)
GOTO:EOF
::------------------------------------------------------------------------------
:END
Parametes
Example script, tested under Windows XP.
@echo off
:: Test if the current user is a local adminisrator.
:: Assume the users is not an administrator.
SET ISADMIN=FALSE
::Test current user.
call :ADMINTEST %USERNAME% ISADMIN
echo %ISADMIN%
pause
Goto END
::------------------------------------------------------------------------------
:: This routine will test if the User ID passed in parameter1 is a member
:: of the local administrators group. It will return "TRUE" in parameter 2
:: if the User ID is an admin.
:ADMINTEST
SETLOCAL
net localgroup administrators | find "%1%"
if %ERRORLEVEL% EQU 0 (
ENDLOCAL & SET "%~2=TRUE"
)
GOTO:EOF
::------------------------------------------------------------------------------
:END