I`m at my wits end here, it gets too complex for me.
We have a CAD system where you can set two license bundles for usage.
And based on availability and applications you use in CAD either one can be used.
Now I want to check the licenses set before the CAD is started to avoid unnecessary CAD start which end in an error since none of the selected licenses are available.
But it gets more complex. If a user starts the CAD a second time and already uses a license bundle on the same PC it can be used multiple times, so this also has to be checked compared.
And the next step is to inform the user if his pre-selected licenses are not available: Ask him if the registry settings should be changed and to start CAD with other licenses, or if he wants to try starting CAD anyhow or he could cancel the CAD start.
I tried doing this by splitting up some of the tasks. Checking registry to find out the pre-selected User Bundles, Checking license usage and availability from the flexlm license server and lastly to use this information in the main batch file.
But this is getting much too complicated for me so I made a Visio flowchart to visualize all possible/necessary choices and possibilities.
And I`m not too good with complex batch loops either.
I cannot upload our real license server responses but I will create text files to show the answer I usually get for each license check (sorry).
And I will also upload my other batch files and the Visio file I made.
The best outcome would be if I can get one batch file which does all the above mentioned tasks.
And I call it in my batch file where I start the CAD.
I uploaded the Visio file and the text files:https://gofile.io/?c=dAKjDb
I would be really thankful for help input.
Best regards
Code: Select all
@echo off
REM Check user registry to find out license bundles
for /f "tokens=1 delims=," %%a in ('%SYSTEMROOT%\system32\reg.exe query
"HKEY_CURRENT_USER\Software\Siemens_PLM_Software\Common_Licensing"
/v "NX_BUNDLES" 2^>NUL ^| find /i "NX_BUNDLES"') do set USER_BUNDLE_1="%%a"
SET USER_BUNDLE_1==%USER_BUNDLE_1:"=%
FOR /F "tokens=4 delims= " %%A IN ("%USER_BUNDLE_1%") DO set USER_BUNDLE_1=%%A
for /f "tokens=2,* delims=," %%a in ('%SYSTEMROOT%\system32\reg.exe query
"HKEY_CURRENT_USER\Software\Siemens_PLM_Software\Common_Licensing"
/v "NX_BUNDLES" 2^>NUL ^| find /i "NX_BUNDLES"') do set USER_BUNDLE_2="%%a"
SET USER_BUNDLE_2=%USER_BUNDLE_2:"=%
ECHO 1 %USER_BUNDLE_1%
ECHO 2 %USER_BUNDLE_2%
REM Check license usage and availability
REM Check BUNDLE_1
FOR /F "tokens=6,11 delims= " %%A IN ('PATH\UGFLEXLM\lmutil.exe lmstat -a -c 28000@LIC_SERVER -f BUNDLE_1 ^| findstr /C:"Users of BUNDLE_1:"') DO (
set BUNDLE_1_AVAIL=%%A
set BUNDLE_1_USED=%%B
)
PATH\UGFLEXLM\lmutil.exe lmstat -a -c 28000@LIC_SERVER -f BUNDLE_1 | findstr /R /C:%USERNAME%
If %ERRORLEVEL% EQU 0 SET USER_HAS_BUNDLE_1=YES
If %ERRORLEVEL% EQU 1 SET USER_HAS_BUNDLE_1=NO
REM Check BUNDLE_2
FOR /F "tokens=6,11 delims= " %%A IN ('PATH\UGFLEXLM\lmutil.exe lmstat -a -c 28000@LIC_SERVER -f BUNDLE_2 ^| findstr /C:"Users of BUNDLE_2:"') DO (
set BUNDLE_2_AVAIL=%%A
set BUNDLE_2_USED=%%B
)
PATH\UGFLEXLM\lmutil.exe lmstat -a -c 28000@LIC_SERVER -f BUNDLE_2 | findstr /R /C:%USERNAME%
If %ERRORLEVEL% EQU 0 SET USER_HAS_BUNDLE_2=YES
If %ERRORLEVEL% EQU 1 SET USER_HAS_BUNDLE_2=NO
REM Check BUNDLE_3
FOR /F "tokens=6,11 delims= " %%A IN ('PATH\UGFLEXLM\lmutil.exe lmstat -a -c 28000@LIC_SERVER -f BUNDLE_3 ^| findstr /C:"Users of BUNDLE_3:"') DO (
set BUNDLE_3_AVAIL=%%A
set BUNDLE_3_USED=%%B
)
PATH\UGFLEXLM\lmutil.exe lmstat -a -c 28000@LIC_SERVER -f BUNDLE_3 | findstr /R /C:%USERNAME%
If %ERRORLEVEL% EQU 0 SET USER_HAS_BUNDLE_3=YES
If %ERRORLEVEL% EQU 1 SET USER_HAS_BUNDLE_3=NO
REM Check BUNDLE_4
FOR /F "tokens=6,11 delims= " %%A IN ('PATH\UGFLEXLM\lmutil.exe lmstat -a -c 28000@LIC_SERVER -f BUNDLE_4 ^| findstr /C:"Users of BUNDLE_4:"') DO (
set BUNDLE_4_AVAIL=%%A
set BUNDLE_4_USED=%%B
)
PATH\UGFLEXLM\lmutil.exe lmstat -a -c 28000@LIC_SERVER -f BUNDLE_4 | findstr /R /C:%USERNAME%
If %ERRORLEVEL% EQU 0 SET USER_HAS_BUNDLE_4=YES
If %ERRORLEVEL% EQU 1 SET USER_HAS_BUNDLE_4=NO
REM Check BUNDLE_5
FOR /F "tokens=6,11 delims= " %%A IN ('PATH\UGFLEXLM\lmutil.exe lmstat -a -c 28000@LIC_SERVER -f BUNDLE_5 ^| findstr /C:"Users of BUNDLE_5:"') DO (
set BUNDLE_5_AVAIL=%%A
set BUNDLE_5_USED=%%B
)
PATH\UGFLEXLM\lmutil.exe lmstat -a -c 28000@LIC_SERVER -f BUNDLE_5 | findstr /R /C:%USERNAME%
If %ERRORLEVEL% EQU 0 SET USER_HAS_BUNDLE_5=YES
If %ERRORLEVEL% EQU 1 SET USER_HAS_BUNDLE_5=NO
REM Check BUNDLE_6
FOR /F "tokens=6,11 delims= " %%A IN ('PATH\UGFLEXLM\lmutil.exe lmstat -a -c 28000@LIC_SERVER -f BUNDLE_6 ^| findstr /C:"Users of BUNDLE_6:"') DO (
set BUNDLE_6_AVAIL=%%A
set BUNDLE_6_USED=%%B
)
PATH\UGFLEXLM\lmutil.exe lmstat -a -c 28000@LIC_SERVER -f BUNDLE_6 | findstr /R /C:%USERNAME%
If %ERRORLEVEL% EQU 0 SET USER_HAS_BUNDLE_6=YES
If %ERRORLEVEL% EQU 1 SET USER_HAS_BUNDLE_6=NO
REM List Free Licenses
if 1%BUNDLE_1_USED% LSS 1%BUNDLE_1_AVAIL% SET /a BUNDLE_1_FREE=%BUNDLE_1_AVAIL%-%BUNDLE_1_USED%
if defined BUNDLE_1_FREE ECHO %BUNDLE_1_FREE% BUNDLE_1 licenses are available
if 1%BUNDLE_4_USED% LSS 1%BUNDLE_4_AVAIL% SET /a BUNDLE_4_FREE=%BUNDLE_4_AVAIL%-%BUNDLE_4_USED%
if defined BUNDLE_4_FREE ECHO %BUNDLE_4_FREE% BUNDLE_4 licenses are available
if 1%BUNDLE_5_USED% LSS 1%BUNDLE_5_AVAIL% SET /a BUNDLE_5_FREE=%BUNDLE_5_AVAIL%-%BUNDLE_5_USED%
if defined BUNDLE_5_FREE ECHO %BUNDLE_5_FREE% BUNDLE_5 licenses are available
if 1%BUNDLE_2_USED% LSS 1%BUNDLE_2_AVAIL% SET /a BUNDLE_2_FREE=%BUNDLE_2_AVAIL%-%BUNDLE_2_USED%
if defined BUNDLE_2_FREE ECHO %BUNDLE_2_FREE% BUNDLE_2 licenses are available
if 1%BUNDLE_3_USED% LSS 1%BUNDLE_3_AVAIL% SET /a BUNDLE_3_FREE=%BUNDLE_3_AVAIL%-%BUNDLE_3_USED%
if defined BUNDLE_3_FREE ECHO %BUNDLE_3_FREE% BUNDLE_3 licenses are available
if 1%BUNDLE_6_USED% LSS 1%BUNDLE_6_AVAIL% SET /a BUNDLE_6_FREE=%BUNDLE_6_AVAIL%-%BUNDLE_6_USED%
if defined BUNDLE_6_FREE ECHO %BUNDLE_6_FREE% BUNDLE_6 licenses are available
if %BUNDLE_1_AVAIL% == %BUNDLE_1_USED% if %BUNDLE_4_AVAIL% == %BUNDLE_4_USED% if %BUNDLE_2_AVAIL% == %BUNDLE_2_USED% if %USER_HAS_BUNDLE_1% == NO if %USER_HAS_BUNDLE_4% == NO if %USER_HAS_BUNDLE_2% == NO goto NOLICENSE
REM Check license in reference to selected bundles
goto EOF
:NOLICENSE
set NO_NX_STD_LIC_AVAILABLE=YES
ECHO NO LICENSES AVAILABE OR IN USE BY YOU, TRY LATER OR CONTACT IT DEPARTMENT TO CHECK LICENCE USAGE.
REM check if seleted bunlde is available or allrady used
if %USER_BUNDLE_1%==USER_BUNDLE_1 if defined USER_BUNDLE_1_FREE goto NX_LICENSE_AVAILABLE
if %USER_BUNDLE_1%==USER_BUNDLE_2 if defined USER_BUNDLE_2_FREE goto NX_LICENSE_AVAILABLE
if %USER_BUNDLE_1%==USER_BUNDLE_3 if defined USER_BUNDLE_3_FREE goto NX_LICENSE_AVAILABLE
if %USER_BUNDLE_1%==USER_BUNDLE_4 if defined USER_BUNDLE_4_FREE goto NX_LICENSE_AVAILABLE
if %USER_BUNDLE_1%==USER_BUNDLE_5 if defined USER_BUNDLE_5_FREE goto NX_LICENSE_AVAILABLE
if %USER_BUNDLE_1%==USER_BUNDLE_6 if defined USER_BUNDLE_6_FREE goto NX_LICENSE_AVAILABLE
if %USER_BUNDLE_2%==USER_BUNDLE_1 if defined USER_BUNDLE_1_FREE goto NX_LICENSE_AVAILABLE
if %USER_BUNDLE_2%==USER_BUNDLE_2 if defined USER_BUNDLE_2_FREE goto NX_LICENSE_AVAILABLE
if %USER_BUNDLE_2%==USER_BUNDLE_3 if defined USER_BUNDLE_3_FREE goto NX_LICENSE_AVAILABLE
if %USER_BUNDLE_2%==USER_BUNDLE_4 if defined USER_BUNDLE_4_FREE goto NX_LICENSE_AVAILABLE
if %USER_BUNDLE_2%==USER_BUNDLE_5 if defined USER_BUNDLE_5_FREE goto NX_LICENSE_AVAILABLE
if %USER_BUNDLE_2%==USER_BUNDLE_6 if defined USER_BUNDLE_6_FREE goto NX_LICENSE_AVAILABLE
REM check if seleted bunlde is allrady used by %username%
if %USER_BUNDLE_1%==USER_BUNDLE_1 if %USER_HAS_USER_BUNDLE_1%==YES goto NX_LIC_ALLR_IN_USE
if %USER_BUNDLE_1%==USER_BUNDLE_2 if %USER_HAS_USER_BUNDLE_2%==YES goto NX_LIC_ALLR_IN_USE
if %USER_BUNDLE_1%==USER_BUNDLE_3 if %USER_HAS_USER_BUNDLE_3%==YES goto NX_LIC_ALLR_IN_USE
if %USER_BUNDLE_1%==USER_BUNDLE_4 if %USER_HAS_USER_BUNDLE_4%==YES goto NX_LIC_ALLR_IN_USE
if %USER_BUNDLE_1%==USER_BUNDLE_5 if %USER_HAS_USER_BUNDLE_5%==YES goto NX_LIC_ALLR_IN_USE
if %USER_BUNDLE_1%==USER_BUNDLE_6 if %USER_HAS_USER_BUNDLE_6%==YES goto NX_LIC_ALLR_IN_USE
if %USER_BUNDLE_2%==USER_BUNDLE_1 if %USER_HAS_USER_BUNDLE_1%==YES goto NX_LIC_ALLR_IN_USE
if %USER_BUNDLE_2%==USER_BUNDLE_2 if %USER_HAS_USER_BUNDLE_2%==YES goto NX_LIC_ALLR_IN_USE
if %USER_BUNDLE_2%==USER_BUNDLE_3 if %USER_HAS_USER_BUNDLE_3%==YES goto NX_LIC_ALLR_IN_USE
if %USER_BUNDLE_2%==USER_BUNDLE_4 if %USER_HAS_USER_BUNDLE_4%==YES goto NX_LIC_ALLR_IN_USE
if %USER_BUNDLE_2%==USER_BUNDLE_5 if %USER_HAS_USER_BUNDLE_5%==YES goto NX_LIC_ALLR_IN_USE
if %USER_BUNDLE_2%==USER_BUNDLE_6 if %USER_HAS_USER_BUNDLE_6%==YES goto NX_LIC_ALLR_IN_USE
REM warning if first and second bundle are not free
:CHANGE_USER_BUNDLE
REM Changes user Bundle to available license bundles
reg add HKEY_CURRENT_USER\Software\%REGTEST%\Common_Licensing /v NX_BUNDLES /d "%BUNDLE_1%,%BUNDLE_2%" /f
I stopped here because it got too complex for me....
:EOF