0

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

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

I could not find any mistake in the logic of 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
        )
    )
Pooja S
  • 145
  • 4
André M. Faria
  • 154
  • 1
  • 1
  • 7

1 Answers1

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 (
303
  • 126
  • 2