0

The script below was wrote to check whether if teamviewer is installed or not, and for what architecture and it will retrive it ClientID, transform it to decimal and print it to a file.

Everytime, whether is installed or not, the result of this script is "Teamviewer not installed"

I Could not find any mistake of logic in this script.

reg query "HKLM\Software\TeamViewer" /v "ClientID"
    if %ERRORLEVEL% == 1 (
        reg query "HKLM\Software\Wow6432Node\TeamViewer" /v "ClientID"
            if %ERRORLEVEL% == 1 (
                echo TEAMVIEWER NOT INSTALLED >> %computername%.nfo
            ) else (
                for /f "tokens=3" %%a in ('reg query "HKLM\Software\Wow6432Node\TeamViewer" /v "ClientID"') do (
                    set /a decimal=%%a + 0
                    echo TEAMVIEWER ID: >> %computername%.nfo
                    echo %decimal% >> %computername%.nfo
                )
            )
    ) else (
        for /f "tokens=3" %%a in ('reg query "HKLM\Software\TeamViewer" /v "ClientID"') do (
            set /a decimal=%%a + 0
            echo TEAMVIEWER ID: >> %computername%.nfo
            echo %decimal% >> %computername%.nfo
        )
    )
  • Try /s recursive query: reg query "HKLM\Software\TeamViewer" /s /v "ClientID" – Greg Askew May 18 '17 at 20:55
  • Delayed Expansion. – JosefZ May 18 '17 at 21:06
1

Expansion takes place before any command is executed inside a block of code. Basically, anything placed within a group of parenthesis.

Because the errorlevel variable is already expanded before the second reg query command is executed, the result of the second reg query doesn't affect the expression of the if command that is placed within parenthesis.

Luckily, the errorlevel variable has a special feature. It can be used by the if command without expanding it.

:: This is true when %errorlevel% >= 1
if errorlevel 1 (

:: This is true when %errorlevel% <= 0
if not errorlevel 1 (

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.