A license for Total Commander is stored in a file called WINCMD.KEY. Since Total Commander version 7.55, the license key can also be stored in the Windows registry. However, there was no tool (that I knew of) to easily move the license to and from the registry. So I made one myself.
I have only tested this tool on own system with Windows 11 64-bit. So it needs further testing. If you own a license, I would greatly appreciate it if you test the tool on your system and report your findings here.
The tool probably works on Windows Vista and later, except for the handling of TCMDKEY.ZIP files. To unpack TCMDKEY.ZIP files, the batch file uses the Expand-Archive cmdlet available in Powershell 5 and later. PowerShell 5 is installed by default since Windows 10 and can be installed on Windows 7 and 8, see Windows PowerShell System Requirements.
Features:
- Import a license key into the registry.
- Export a license key in the registry to a WINCMD.KEY file.
- Delete a license key in the registry.
- Support for all 3 registry locations (current user, all users 64-bit and all users 32-bit).
- It searches for licenses in registry, WINCMD.KEY files and TCMDKEY.ZIP files at known locations.
- It also searches for a license in the current folder and in the folder where the tool is installed.
- It searches for WINCMD.INI files at known locations and checks if a location for the license file is defined within.
- It tries to find out if different names are used for the WINCMD.INI file. It does so by analyzing the Total Commander registry settings and by analyzing the COMMANDER_INI environment variable. It searches for all the found ini filenames at all locations.
- It determines where Total Commander is installed by analyzing the Total Commander registry settings and the Total Commander environment variables.
- It shows all found licenses and shows which ones are the same.
- If more than 1 unique license is found, you can choose which one to import or export.
- Exported licenses are stored in subfolders of the folder where this tool is installed. Existing WINCMD.KEY files will not be overwritten.
Tip 2: This tool can also be used to show where your installed license is and to quickly scan a computer for a license.
The tool is listed below. Save the contents to the mentioned filename.
Filename:
Code: Select all
TC key.cmd
Code: Select all
@Echo off
Rem
Rem TC key.cmd v1.0 - Copy Total Commander license to/from Windows registry
Rem
Rem Created by: Forum user white on the Total Commander forum (https://www.ghisler.ch/board/)
Rem
Rem Run this tool as administrator in case you want to make registry changes that apply to all users.
Rem
Rem This tool searches for license files in a number of locations. If your license file is not found,
Rem place your license file and this tool in the same folder, or run this tool from the folder that
Rem contains your license file.
Rem
Rem Exported licenses are saved in subfolders of this tool's folder.
Rem
Rem This tool creates temporary files in the Windows temp folder. One of the temporary files contains
Rem the found license keys. Close the tool by pressing Q, or the temporary files will not be deleted.
Rem
Rem
Rem The following programming style is used to prevent errors:
Rem * No real parameters are used with Call statements, because special characters are handled poorly.
Rem * Double quotes are not stored in environment variables, or removed as soon as possible.
Rem
Rem The history of changes is included at the bottom of this file.
Rem
:Main_START
SetLocal EnableExtensions DisableDelayedExpansion
Rem Clear screen and write header
Cls
Echo.
Echo TC key.cmd v1.0 - Copy Total Commander license to/from Windows registry
Echo.
Echo Licenses:
Echo.
Rem Define global variables
Set "p_tmp=%tmp%\$$$tmp_%~n0$$$"
Set "G_f_ini_files=%p_tmp%\Ini files.txt"
Set "G_f_license_folders=%p_tmp%\License folders.txt"
Set "G_f_license_keys=%p_tmp%\License keys.txt"
Set "G_f_key_hex=%p_tmp%\tmp_tcmdkey.txt"
Set "G_f_processed_folders=%p_tmp%\Processed folders.txt"
Set "G_key_cnt=0"
Set "G_err_cnt_unp=0"
Set "G_p_export=%~dp0Export"
Set "G_p_unzip=%p_tmp%\Unzip key"
Rem Set up temp folder
If not exist "%p_tmp%" (md "%p_tmp%") else Del /q "%p_tmp%"
Echo "::WINCMD.INI::"> "%G_f_ini_files%"
If defined COMMANDER_INI For %%I in ("%COMMANDER_INI%") do (
If /i not "%%~nxI"=="WINCMD.INI" Echo "::%%~nxI::">> "%G_f_ini_files%"
)
Rem If you know different names that were used for wincmd.ini files, add them here
Rem Echo "::TC.INI::">> "%G_f_ini_files%"
Rem Process name and location of wincmd.ini file defined in registry
Rem Store unique filenames of ini files in a temporary file
Rem Process HKCU key
Set "param_1=HKCU\Software\Ghisler\Total Commander"
Set "param_2="
Call :ProcessRegistry
Set "ini_folder_1=%result%"
Rem Process HKLM key, 64bit
Set "ini_folder_2="
Call :OS_64bit || Goto PROCESS_REG_32BIT
Set "param_1=HKLM\Software\Ghisler\Total Commander"
Set "param_2=/reg:64"
Call :ProcessRegistry
Set "ini_folder_2=%result%"
:PROCESS_REG_32BIT
Rem Process HKLM key, 32bit
Set "param_1=HKLM\Software\Ghisler\Total Commander"
Set "param_2=/reg:32"
Call :ProcessRegistry
Set "ini_folder_3=%result%"
Rem Process folders where ini files and license file could be located
Rem If an ini file is found, check if it contains a location for the license file
Rem Store found licenses in a temporary file
Rem Process this tool's folder, export folders and current folder
Set "param_1=%~dp0" & Call :ProcessFolder
For /d %%i in ("%G_p_export%*") do Set "param_1=%%~i" & Call :ProcessFolder
Set "param_1=%CD%" & Call :ProcessFolder
Rem Process folders of ini files found in registry
Set "param_1=%ini_folder_1%" & Call :ProcessFolder
Set "param_1=%ini_folder_2%" & Call :ProcessFolder
Set "param_1=%ini_folder_3%" & Call :ProcessFolder
Rem Process install folder listed in registry HKCU
Set "param_1=HKCU\Software\Ghisler\Total Commander"
Set "param_2=InstallDir"
Set "param_3="
Call :RegRead
Set "param_1=%result%" & Call :ProcessFolder & Set "result=%result%" & Rem Restore value of result after the call
Rem Also process folder in the VirtualStore folder
If defined result If defined LOCALAPPDATA For %%I in (
"%result%\dummy"
) do Set "param_1=%LOCALAPPDATA%\VirtualStore%%~pI" & Call :ProcessFolder
Rem Process install folder listed in registry HKLM, 64-bit
Call :OS_64bit || Goto PROCESS_INSTALL_DIR_32BIT
Set "param_1=HKLM\Software\Ghisler\Total Commander"
Set "param_2=InstallDir"
Set "param_3=/reg:64"
Call :RegRead
Set "param_1=%result%" & Call :ProcessFolder & Set "result=%result%" & Rem Restore value of result after the call
Rem Also process folder in the VirtualStore folder
If defined result If defined LOCALAPPDATA For %%I in (
"%result%\dummy"
) do Set "param_1=%LOCALAPPDATA%\VirtualStore%%~pI" & Call :ProcessFolder
:PROCESS_INSTALL_DIR_32BIT
Rem Process install folder listed in registry HKLM, 32-bit
Set "param_1=HKLM\Software\Ghisler\Total Commander"
Set "param_2=InstallDir"
Set "param_3=/reg:32"
Call :RegRead
Set "param_1=%result%" & Call :ProcessFolder & Set "result=%result%" & Rem Restore value of result after the call
Rem Also process folder in the VirtualStore folder
If defined result If defined LOCALAPPDATA For %%I in (
"%result%\dummy"
) do Set "param_1=%LOCALAPPDATA%\VirtualStore%%~pI" & Call :ProcessFolder
Rem Process other known locations for ini files and key files
If defined COMMANDER_INI For %%I in ("%COMMANDER_INI%") do Set "param_1=%%~dpI" & Call :ProcessFolder
For %%i in (
"%APPDATA%\Ghisler"
"%COMMANDER_PATH%"
"%USERPROFILE%"
"c:\windows"
"%SystemRoot%"
"c:\totalcmd"
"c:\Total Commander"
"c:\Program Files\totalcmd"
"c:\Program Files\Total Commander"
"c:\Program Files (x86)\totalcmd"
"c:\Program Files (x86)\Total Commander"
) do Set "param_1=%%~i" & Call :ProcessFolder
Rem Also process folders in the VirtualStore folder
If not defined LOCALAPPDATA Goto Main_SEARCH_REG_FOR_KEYS
If defined COMMANDER_EXE For %%I in ("%COMMANDER_EXE%") do Set "param_1=%LOCALAPPDATA%\VirtualStore%%~pI" & Call :ProcessFolder
For %%i in (
"totalcmd"
"Total Commander"
"Program Files\totalcmd"
"Program Files\Total Commander"
"Program Files (x86)\totalcmd"
"Program Files (x86)\Total Commander"
) do Set "param_1=%LOCALAPPDATA%\VirtualStore\%%~i" & Call :ProcessFolder
:Main_SEARCH_REG_FOR_KEYS
Rem Search registry for license keys
Rem Search HKCU key
Set "param_1=HKCU\Software\Ghisler\Total Commander"
Set "param_2="
Set "param_3=Registry (current user)"
Call :RegSearchLicense
Rem Search HKLM key, 64bit
Call :OS_64bit || Goto Main_SEARCH_HKLM_32BIT
Set "param_1=HKLM\Software\Ghisler\Total Commander"
Set "param_2=/reg:64"
Set "param_3=Registry (all users, 64-bit)"
Call :RegSearchLicense
:Main_SEARCH_HKLM_32BIT
Rem Search HKLM key, 32bit
Set "param_1=HKLM\Software\Ghisler\Total Commander"
Set "param_2=/reg:32"
Set "param_3=Registry (all users, 32-bit)"
Call :RegSearchLicense
Rem Display footer
Echo.
If not "%G_err_cnt_unp%"=="0" Echo Unable to unpack the tcmdkey.zip file(s) (requires PowerShell 5)
If "%G_key_cnt%"=="0" (
Echo No license found! Place your license file and this tool in the same folder,
Echo or run this tool from the folder that contains your license file.
) else (
Echo Number of unique licenses: %G_key_cnt%
)
Rem Display menu and execute options
Rem Display menu
Echo.
Echo Choose one of these options:
Echo.
Echo 1) Import license into registry (current user)
Echo 2) Import license into registry (all users, 64-bit) (Run as administrator)
Echo 3) Import license into registry (all users, 32-bit) (Run as administrator)
Echo 4) Export license
Echo 5) Delete license from registry (current user)
Echo 6) Delete license from registry (all users, 64-bit) (Run as administrator)
Echo 7) Delete license from registry (all users, 32-bit) (Run as administrator)
Echo R) Refresh
Echo Q) Quit and remove temporary files
Rem Execute options chosen by user
Echo.
Choice /c 1234567RQ /n /m ">"
If not errorlevel 1 Goto Main_END
If errorlevel 10 Goto Main_END
If errorlevel 9 Set "quit=true" & Goto Main_END
If errorlevel 8 Goto Main_END
If errorlevel 7 Call :RegDeleteHKLM32 & Goto Main_END
If errorlevel 6 Call :RegDeleteHKLM64 & Goto Main_END
If errorlevel 5 Call :RegDeleteHKCU & Goto Main_END
If errorlevel 4 Call :ExportLicense & Goto Main_END
If errorlevel 3 Call :RegImportHKLM32 & Goto Main_END
If errorlevel 2 Call :RegImportHKLM64 & Goto Main_END
If errorlevel 1 Call :RegImportHKCU & Goto Main_END
:Main_END
Rem Clean up temp folder
If exist "%p_tmp%" rd /s /q "%p_tmp%"
Rem Quit
If defined quit Exit /b
Rem Restart
Endlocal
Goto Main_START
Rem
Rem Warning and message functions
Rem
:WrnRegDelete
Echo Before removing a license from the registry, make sure you have a copy of the license somewhere.
Exit /b
:MsgNotAvailableOn32bit
Echo This function is not available on a 32-bit operating system.
Exit /b
Rem
Rem Function ExpandVars
Rem
Rem Parameters: String
Rem Return value: ExpandedString
Rem
Rem Expand environment variables in a string.
Rem There must be no double quotes in the string.
Rem
:ExpandVars
For /f "tokens=*" %%i in ('Echo "%param_1%"') do Set "result=%%~i"
Exit /b
Rem
Rem Function ExportLicense
Rem
Rem Export a license key to a WINCMD.KEY file.
Rem An existing WINCMD.KEY file will not be overwritten. Create a new export folder instead.
Rem
:ExportLicense
Rem Get hex encoded license key to export
Call :GetKey
If not defined result Exit /b
Rem Determine export folder
Set "ExportLicense_p_export=%G_p_export%"
Set "ExportLicense_cnt=0"
:ExportLicense_LOOP
If not exist "%ExportLicense_p_export%\wincmd.key" Goto ExportLicense_EXPORT
Set /a "ExportLicense_cnt=%ExportLicense_cnt% + 1"
Set "ExportLicense_p_export=%G_p_export% (%ExportLicense_cnt%)"
Goto ExportLicense_LOOP
:ExportLicense_EXPORT
Rem Export license key to file
If not exist "%ExportLicense_p_export%" md "%ExportLicense_p_export%"
Rem Write hex encoded key to a temporary file
Echo %result%> "%G_f_key_hex%"
Rem Convert hex encoded file to binary file
>nul 2>&1 Certutil -decodehex "%G_f_key_hex%" "%ExportLicense_p_export%\wincmd.key"
Rem Clean up temp file
If exist "%G_f_key_hex%" Del /q "%G_f_key_hex%"
Rem Report result to user
If exist "%ExportLicense_p_export%\wincmd.key" (
Echo License exported to: "%ExportLicense_p_export%\wincmd.key"
) else (
Echo Export failed!
)
Pause
Set "ExportLicense_p_export="
Set "ExportLicense_cnt="
Exit /b
Rem
Rem Function GetKey
Rem
Rem Return value: LicenseKey
Rem
Rem Get license key from temporary file. If there are more than one license, ask the user which one to use.
Rem
:GetKey
Set "result="
Rem Determine which license to get
Set "GetKey_key_idx="
If "%G_key_cnt%"=="0" Goto GetKey_END
If "%G_key_cnt%"=="1" (Set "GetKey_key_idx=1") else Set /p GetKey_key_idx="Enter a license number shown on screen: "
If defined GetKey_key_idx Set "GetKey_key_idx=%GetKey_key_idx:"=%" & Rem Remove quotes
Rem Get the license key from file, use Find so it also works when batch file is started in Unicode command prompt (cmd.exe /u)
If exist "%G_f_license_keys%" For /f "delims=[] tokens=2" %%i in (
'Find "[%GetKey_key_idx%]" ^<"%G_f_license_keys%"'
) do Set "result=%%i"
:GetKey_END
If not defined result (
Echo License "%GetKey_key_idx%" not found!
Pause
)
Set "GetKey_key_idx="
Exit /b
Rem
Rem Function IniRead
Rem
Rem Parameters: FileName SettingName
Rem Return value: Value
Rem
Rem Read value of a setting from an ini file.
Rem Quick and dirty implementation. Section headers are ignored.
Rem Double quotes in the value will be removed.
Rem
:IniRead
Set "result="
If not defined param_1 Exit /b
If not defined param_2 Exit /b
If not exist "%param_1%" Exit /b
Rem Use the Find command first, because Find can handle files containing null characters and files in UTF16 LE format
For /f "tokens=1* delims==" %%i in (
'2^>nul Find /i "%param_2%" "%param_1%" ^| Findstr /i /r "^[ ]*%param_2%[ ]*="'
) do Set "result=%%j"
If not defined result Exit /b
Rem Trim and remove quotes, but keep spaces inside quotes
Set "result=%result:"=[double quote]%" & Rem Prevent errors by replacing quotes with markers
Set "param_1=%result%"
Call :Trim
If defined result Set "result=%result:[double quote]=%" & Rem Remove markers
Exit /b
Rem
Rem Function OS_64bit
Rem
Rem Exitcode:
Rem 0 (OS is 64-bit)
Rem 1 (OS is 32-bit)
Rem
Rem Determine if Operating System is 64-bit or 32-bit.
Rem
:OS_64bit
If "%processor_architecture%"=="x86" If not defined processor_architew6432 Exit /b 1
Exit /b 0
Rem
Rem Function ProcessFolder
Rem
Rem Parameters: Folder
Rem
Rem Process folder where ini file and license file could be located.
Rem Search license in the folder.
Rem If an ini file is found, process the ini file.
Rem
:ProcessFolder
If not defined param_1 Exit /b
If "%param_1:~-1,1%"=="\" Set "param_1=%param_1:~0,-1%" & Rem Strip trailing backslash
If not defined param_1 Exit /b
If not exist "%param_1%" Exit /b
Rem Check if folder already processed
>nul 2>&1 Find /i "::%param_1%::" "%G_f_processed_folders%"
If not errorlevel 1 Exit /b
Echo "::%param_1%::">> "%G_f_processed_folders%"
Rem Search license
Rem Set "param_1=%param_1%"
Call :SearchLicense & Set "param_1=%param_1%" & Rem Restore value of param_1 after the call
Rem Loop through possible ini filenames, use Find so it also works when batch file is started in Unicode command prompt (cmd.exe /u)
If not exist "%G_f_ini_files%" Exit /b
For /f "delims=: tokens=2" %%i in ('Find /v "" ^<"%G_f_ini_files%"') do (
Set "param_1=%param_1%\%%i"
Call :ProcessIni
)
Exit /b
Rem
Rem Function ProcessIni
Rem
Rem Parameters: FileName
Rem
Rem Determine if location of key file is defined in ini file.
Rem Search that location for license key.
Rem
:ProcessIni
If not defined param_1 Exit /b
If not exist "%param_1%" Exit /b
Rem Get KeyPath value from ini file
Rem Set "param_1=%param_1%"
Set "param_2=KeyPath"
Call :IniRead
If not defined result Exit /b
If "%result%"=="$" Exit /b & Rem If license in registry, skip
Rem Expand environment vars in folder name
Set "param_1=%result%"
Call :ExpandVars
Rem Search license
Set "param_1=%result%"
Call :SearchLicense
Exit /b
Rem
Rem Function ProcessKey
Rem
Rem Parameters: Folder KeyFile
Rem
Rem Process a license file.
Rem Store found license in a temporary file.
Rem
:ProcessKey
If not defined param_1 Exit /b
If not defined param_2 Exit /b
If not exist "%param_1%\%param_2%" Exit /b
Set "ProcessKey_file=%param_1%\%param_2%"
Rem Unpack if key file is packed
If /i not "%param_2%"=="tcmdkey.zip" Goto ProcessKey_CHECK_KEY_SIZE
If exist "%G_p_unzip%" Del /q "%G_p_unzip%"
powershell -Command ^
$ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference= 'SilentlyContinue';^
Expand-Archive -LiteralPath '%ProcessKey_file%' -DestinationPath '%G_p_unzip%'
If errorlevel 1 Echo [License ^<unknown^>] "%ProcessKey_file%" & Set /a "G_err_cnt_unp=%G_err_cnt_unp% + 1"
Rem Process unpacked key file
Set "ProcessKey_file=%G_p_unzip%\wincmd.key"
If not exist "%ProcessKey_file%" Goto ProcessKey_CLEAN_UP
:ProcessKey_CHECK_KEY_SIZE
Rem Check if file size of tmcd.key file is 1024 bytes
For %%I in ("%ProcessKey_file%") do If not "%%~zI"=="1024" Goto ProcessKey_CLEAN_UP
Rem Encode file to hex encoded
>nul 2>&1 Certutil -f -encodehex "%ProcessKey_file%" "%G_f_key_hex%" 12
If errorlevel 1 Goto ProcessKey_CLEAN_UP
Rem Store key in environment var
Set "ProcessKey_key="
If exist "%G_f_key_hex%" For /f "usebackq" %%i in ("%G_f_key_hex%") do Set "ProcessKey_key=%%i"
If not defined ProcessKey_key Goto ProcessKey_CLEAN_UP
Rem Get key index number
Set "ProcessKey_key_idx="
If exist "%G_f_license_keys%" For /f "delims=[]" %%i in (
'Find /i "%ProcessKey_key%" ^<"%G_f_license_keys%"'
) do Set "ProcessKey_key_idx=%%i"
If defined ProcessKey_key_idx Goto ProcessKey_DISPLAY_KEY_ID
Rem Process new key
Set /a "G_key_cnt=%G_key_cnt% + 1"
Set "ProcessKey_key_idx=%G_key_cnt%"
Echo [%ProcessKey_key_idx%]%ProcessKey_key%>> "%G_f_license_keys%"
:ProcessKey_DISPLAY_KEY_ID
Rem Display key id and key location
Echo [License %ProcessKey_key_idx%] "%param_1%\%param_2%"
:ProcessKey_CLEAN_UP
Set "ProcessKey_file="
Set "ProcessKey_key="
Set "ProcessKey_key_idx="
Rem Clean up temp files
If exist "%G_f_key_hex%" Del /q "%G_f_key_hex%"
If exist "%G_p_unzip%" rd /s /q "%G_p_unzip%"
Exit /b
Rem
Rem Function ProcessRegistry
Rem
Rem Parameters: KeyName Options
Rem Return value: FolderIniFile
Rem
Rem Get full ini name from registry, split into folder and filename, store unique filenames, return folder name
Rem
:ProcessRegistry
Set "result="
If not defined param_1 Exit /b
Rem Get full name of wincmd.ini file from registry
Rem Set "param_1=%param_1%"
Set "param_3=%param_2%"
Set "param_2=IniFileName"
Call :RegRead
If not defined result Exit /b
Rem Expand environment variables
Set "param_1=%result%"
Call :ExpandVars
If not defined result Exit /b
Rem Split off folder and filename
For %%I in ("%result%") do (
Set "result=%%~dpI"
Set "ProcessRegistry_fn=%%~nxI"
)
If not defined ProcessRegistry_fn Exit /b
Rem Add unique ini filename to list
>nul 2>&1 Find /i "::%ProcessRegistry_fn%::" "%G_f_ini_files%"
If errorlevel 1 Echo "::%ProcessRegistry_fn%::">> "%G_f_ini_files%"
Set "ProcessRegistry_fn="
Exit /b
Rem
Rem Function RegDeleteHKCU
Rem
Rem Delete license key from registry (for current user).
Rem
:RegDeleteHKCU
Call :WrnRegDelete
Reg delete "HKCU\Software\Ghisler\Total Commander" /v "Key"
Exit /b
Rem
Rem Function RegDeleteHKLM32
Rem
Rem Delete license key from registry (for all users, 32-bit).
Rem
:RegDeleteHKLM32
Call :WrnRegDelete
Reg delete "HKLM\Software\Ghisler\Total Commander" /v "Key" /reg:32
Exit /b
Rem
Rem Function RegDeleteHKLM64
Rem
Rem Delete license key from registry (for all users, 64-bit).
Rem
:RegDeleteHKLM64
Call :OS_64bit || (
Call :MsgNotAvailableOn32bit
Pause
Exit /b
)
Call :WrnRegDelete
Reg delete "HKLM\Software\Ghisler\Total Commander" /v "Key" /reg:64
Exit /b
Rem
Rem Function RegImportHKCU
Rem
Rem Import license key into registry (for current user).
Rem
:RegImportHKCU
Call :GetKey
If defined result Reg add "HKCU\Software\Ghisler\Total Commander" /v "Key" /t REG_BINARY /d "%result%"
Exit /b
Rem
Rem Function RegImportHKLM32
Rem
Rem Import license key into registry (for all users, 32-bit).
Rem
:RegImportHKLM32
Call :GetKey
If defined result Reg add "HKLM\Software\Ghisler\Total Commander" /v "Key" /t REG_BINARY /d "%result%" /reg:32
Exit /b
Rem
Rem Function RegImportHKLM64
Rem
Rem Import license key into registry (for all users, 64-bit).
Rem
:RegImportHKLM64
Call :OS_64bit || (
Call :MsgNotAvailableOn32bit
Pause
Exit /b
)
Call :GetKey
If defined result Reg add "HKLM\Software\Ghisler\Total Commander" /v "Key" /t REG_BINARY /d "%result%" /reg:64
Exit /b
Rem
Rem Function RegRead
Rem
Rem Parameters: KeyName ValueName Options
Rem Return value: Value
Rem
Rem Read value from registry.
Rem Double quotes in the value will be removed.
Rem
:RegRead
Set "result="
If not defined param_1 Exit /b
If not defined param_2 Exit /b
For /f "skip=2 delims=) tokens=1*" %%i in (
'2^>nul Reg query "%param_1%" /v "%param_2%" %param_3% /z'
) do Set "result=%%j"
If not defined result Exit /b
Rem Trim and remove quotes, but keep spaces inside quotes
Set "result=%result:"=[double quote]%" & Rem Prevent errors by replacing quotes with markers
Set "param_1=%result%"
Call :Trim
If defined result Set "result=%result:[double quote]=%" & Rem Remove markers
Exit /b
Rem
Rem Function RegSearchLicense
Rem
Rem Parameters: KeyName Options Description
Rem
Rem Search registry for a license.
Rem Store found license in a temporary file.
Rem
:RegSearchLicense
If not defined param_1 Exit /b
If not defined param_3 Exit /b
Set "RegSearchLicense_description=%param_3%"
Rem Get license from from registry
Rem Set "param_1=%param_1%"
Set "param_3=%param_2%"
Set "param_2=Key"
Call :RegRead
If not defined result Goto RegSearchLicense_END
Rem Get key index number
Set "RegSearchLicense_key_idx="
If exist "%G_f_license_keys%" For /f "delims=[]" %%i in (
'Find /i "%result%" ^<"%G_f_license_keys%"'
) do Set "RegSearchLicense_key_idx=%%i"
If defined RegSearchLicense_key_idx Goto RegSearchLicense_DISPLAY_KEY_ID
Rem Process new key
Set /a "G_key_cnt=%G_key_cnt% + 1"
Set "RegSearchLicense_key_idx=%G_key_cnt%"
Echo [%RegSearchLicense_key_idx%]%result%>> "%G_f_license_keys%"
:RegSearchLicense_DISPLAY_KEY_ID
Rem Display key id and key location
Echo [License %RegSearchLicense_key_idx%] %RegSearchLicense_description%
:RegSearchLicense_END
Rem Clean up
Set "RegSearchLicense_description="
Set "RegSearchLicense_key_idx="
Exit /b
Rem
Rem Function SearchLicense
Rem
Rem Parameters: Folder
Rem
Rem Search folder for license files.
Rem If found, process the license file.
Rem
:SearchLicense
If not defined param_1 Exit /b
If not exist "%param_1%\wincmd.key" If not exist "%param_1%\tcmdkey.zip" Exit /b
Rem Check if folder already processed
>nul 2>&1 Find /i "::%param_1%::" "%G_f_license_folders%"
If not errorlevel 1 Exit /b
Echo "::%param_1%::">> "%G_f_license_folders%"
Rem Process key files
Rem Set "param_1=%param_1%"
Set "param_2=wincmd.key"
Call :ProcessKey & Set "param_1=%param_1%" & Rem Restore value of param_1 after the call
Set "param_2=tcmdkey.zip"
Call :ProcessKey
Exit /b
Rem
Rem Function Trim
Rem
Rem Parameters: String
Rem Return value: TrimmedString
Rem
Rem Trim leading and trailing spaces and tab characters.
Rem Double quotes in the string are not supported (replace them before calling this function).
Rem
:Trim
Set "result=%param_1%"
:Trim_LEFT
If not defined result Exit /b
If not "%result:~0,1%"==" " If not "%result:~0,1%"==" " Goto Trim_RIGHT
Set "result=%result:~1%"
Goto Trim_LEFT
:Trim_RIGHT
If not "%result:~-1,1%"==" " If not "%result:~-1,1%"==" " Exit /b
Set "result=%result:~0,-1%"
Goto Trim_RIGHT
Rem
Rem History:
Rem
Rem 2024-06-25 Release v1.0
Rem 2024-06-25 Finalized version. Updated version number and made minor cosmetic adjustments.
Rem
Rem 2023-03-03 Release v1.0b2
Rem 2023-03-03 Improved message when unable to unpack tcmdkey.zip files.
Rem
Rem 2023-03-01 Release v1.0b1 (first release)
Rem
History:
2024-06-25 Release v1.0
2024-06-25 Finalized version. Updated version number and made minor cosmetic adjustments.
2023-03-03 Release v1.0b2
2023-03-03 Improved message when unable to unpack tcmdkey.zip files.
2023-03-01 Release v1.0b1 (first release)