I am trying to use the below batch script to activate Windows in my organization where different departments have different computer name group for different Windows keys. Unfortunately it does not work. (The batch started and closed when ran). Anyone please help me to modify it.
@echo off
setlocal
set group1=HR-16,DD-89,CC-05
set key1=AAAAA.BBBBB.CCCCC.DDDDD.EEEE
call :ActivateWindows %group1% %key1%
set group2=CF-05,RB-09,NO-15
set key2=BBBBB.CCCCC.DDDDD.EEEE.11111
call :ActivateWindows %group2% %key2%
set group3=AB-50,XY-23,LM-46
set key3=BBBBB.CCCCC.DDDDD.EEEE.22222
call :ActivateWindows %group3% %key3%
cscript %windir%\system32\slmgr.vbs /ato
endlocal
exit /b %errorlevel%
:ActivateWindows [group] [key]
for %%G in (%~1) do for %%K in (%~2) do (
if "%computername:~0,5%"=="%%G" if "%computername:~-2%"=="-X" (
echo Activating Group: %%G and Key: %%K
cscript //nologo %windir%\system32\slmgr.vbs /ipk %%K
)
)
goto :eof
REVISED
@echo off
setlocal
set group1=HR-16,DD-89,CC-05
set key1=AAAAA.BBBBB.CCCCC.DDDDD.EEEE
call :ActivateWindows "%group1%" %key1%
set group2=CF-05,RB-09,NO-15
set key2=BBBBB.CCCCC.DDDDD.EEEE.11111
call :ActivateWindows "%group2%" %key2%
set group3=AB-50,XY-23,LM-46
set key3=BBBBB.CCCCC.DDDDD.EEEE.22222
call :ActivateWindows "%group3%" %key3%
cscript %windir%\system32\slmgr.vbs /ato
endlocal
exit /b %errorlevel%
:ActivateWindows [group] [key]
for %%G in (%~1) do for %%K in (%~2) do (
if "%computername:~0,5%"=="%%G" if "%computername:~-2%"=="-X" (
echo Activating Group: %%G and Key: %%K
cscript //nologo %windir%\system32\slmgr.vbs /ipk %%K
)
)
goto :eof
Combined into one master batch to let user to choose btw manual input key and the preset key. The Input choice is fine but the Preset choice not works.
@echo off
REM Windows Activation
echo ================================
echo Choices:
echo. [1] = Input Key
echo. [2] = Pre-Set Key
echo ================================
goto choice
:choice
Echo ComputerName : %computername%
Choice /n /c 12 /m "Activation Choice : "%1
if "%errorlevel%"=="1" goto input
If "%errorlevel%"=="2" goto preset
:input
echo %errorlevel%
Echo Activate Windows
echo. =================================
set /p key="Input Windows KEY : "
echo. =================================
echo. %key%
echo. Press ENTER to continue if correct
pause
cscript %windir%\system32\slmgr.vbs /ipk %key%
ping /n 3 localhost>nul 2>&1
cscript %windir%\system32\slmgr.vbs /ato
ping /n 3 localhost>nul 2>&1
cscript %windir%\system32\slmgr.vbs /xpr
ping /n 3 localhost>nul 2>&1
goto end
:preset
set group1=HR-16,DD-89,CC-05
set key1=AAAAA.BBBBB.CCCCC.DDDDD.EEEE
call :ActivateWindows "%group1%" %key1%
set group2=CF-05,RB-09,DS-60
set key2=BBBBB.CCCCC.DDDDD.EEEE.11111
call :ActivateWindows "%group2%" %key2%
set group3=AB-50,XY-23,LM-46
set key3=BBBBB.CCCCC.DDDDD.EEEE.22222
call :ActivateWindows "%group3%" %key3%
cscript %windir%\system32\slmgr.vbs /ato
endlocal
exit /b %errorlevel%
:ActivateWindows [group] [key]
for %%G in (%~1) do for %%K in (%~2) do (
if "%computername:~0,5%"=="%%G" if "%computername:~-2%"=="-X" (
echo Activating Group: %%G and Key: %%K
cscript //nologo %windir%\system32\slmgr.vbs /ipk %%K
)
)
goto :eof
CodePudding user response:
call :ActivateWindows "%group1%" %key1%
(same for 2&3)
, is a separator, like Space so the subroutine sees
HR-16
DD-89
CC-05
AAAAA.BBBBB.CCCCC.DDDDD.EEEE
as its parameters