my goal is to read a key value from the registry, which shows me the patch of the used SSH/Telnet client (most likely Putty) of the user. On Windows XP I could use:
@echo off FOR /F "tokens=1 delims= " %%A IN ('REG QUERY "HKEY_CURRENT_USERSoftwareMicrosoftWindowsShellNoRoamMUICache" ^| findstr "SSH"') DO SET putty=%%A FOR /F "tokens=1 delims=" %%A IN ('echo %putty%') DO SET putty=%%A start "Putty" "%putty%" "my.domain.com" "myport" -telnet
On Windows 10 the MUICache path changed to HKEY_CURRENT_USERSoftwareClassesLocal SettingsSoftwareMicrosoftWindowsShellMuiCache, which is not the problem.
The problem is, that on Windows XP the result rows of REG QUERY where separated by TAB, in Windows 10 the separation is done by using 4 space characters.
Lets say the Result line looks like…:
C:FirstName LastNamePuttyputty_0.77.exe.FriendlyAppName REG_SZ SSH, Telnet, Rlogin, and SUPDUP client
Note: It might contains spaces in the key(path)
… how can I extract the path and assign it to a variable called “putty”?
With perl regex this would be simple to match…
/^(.*?).FriendlyAppName/
… but I can only rely on what is already installed on the user system.