Question

So what I am trying to accomplish is:

1) Read from a list of computers

2) Determine what bit of Windows it is (see reg keys below)

3) Go to appropriate if statement and delete keys if they exists.

It works AMAZING on 64bit systems but for some reason when it hits 32bit systems (system without \Wow6432Node\) it loops twice and calls it a 64bit system. I am so confused as to why it would do this.

This is the most recent code that I am working with, old versions have the set regkey1_32=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\00002109A10000000000000000F01FEC\InstallProperties

and

:32_1 echo %1 is 32bit >> "C:\Outlook\RegeditList.txt" REG QUERY \\%1\%regkey1_32% > nul

So I might need some fresh eyes on here to see what I don't.

The OVLK.txt contains computer names so it doesn't matter what you put in there (MJGXGTH(x64)\34ZXYC1(x86)). Log file outputs are at the bottom.

@echo off
for /F "tokens=1 delims="  %%i in (C:\Outlook\OVLK.txt) do call :proccheck %%i
goto EOF

:proccheck
REG QUERY \\%1\%proctype% 2>nul >nul
if %errorlevel% == 0 (
    goto :64_1
    ) else (
    goto :32_1 )

:32_1
echo %1 is 32bit >> "C:\Outlook\RegeditList.txt" 
REG QUERY \\%1\%regkey1_64% > nul
if %errorlevel%== 0  (
    echo %regkey1_64% Found! >> "C:\Outlook\RegeditList.txt" 
    REG DELETE \\%1\%regkey1_64% /f >> "C:\Outlook\RegeditList.txt" 
    goto :32_2
    ) else (
    echo %regkey1_64% not found on: %1 - Check >> "C:\Outlook\KeysNotFoundlist.txt"
    goto :32_2 )
:32_2
REG QUERY \\%1\%regkey2_32% > nul
if %errorlevel%== 0 (
    echo %regkey2_32% Found! >> "C:\Outlook\RegeditList.txt" 
    REG DELETE \\%1\%regkey2_32% /f >> "C:\Outlook\RegeditList.txt"
    goto :32_3
    ) else (
    echo %regkey2_32% not found on: %1 - Check >> "C:\Outlook\KeysNotFoundlist.txt"
    goto :32_3 )

:32_3
REG QUERY \\%1\%regkey3_32% > nul
if %errorlevel%== 0 (
    echo %regkey3_32% Found! >> "C:\Outlook\RegeditList.txt" 
    REG DELETE \\%1\%regkey3_32% /f >> "C:\Outlook\RegeditList.txt"
    echo. >> "C:\Outlook\RegeditList.txt"
    ) else (
    echo %regkey3_32% not found on: %1 - Check >> "C:\Outlook\KeysNotFoundlist.txt"
    echo. >> "C:\Outlook\KeysNotFoundlist.txt"
    echo. >> "C:\Outlook\RegeditList.txt" )
echo Checked %1 now going to loop! >> "C:\Outlook\RunLog.log"
echo. >> "C:\Outlook\RunLog.log"

:64_1
echo %1 is 64bit >> "C:\Outlook\RegeditList.txt" 
REG QUERY \\%1\%regkey1_64% > nul
if %errorlevel%== 0  (
    echo %regkey1_64% Found! >> "C:\Outlook\RegeditList.txt" 
    REG DELETE \\%1\%regkey1_64% /f >> "C:\Outlook\RegeditList.txt" 
    goto :64_2
    ) else (
    echo %regkey1_64% not found on: %1 - Check >> "C:\Outlook\KeysNotFoundlist.txt"
    goto :64_2 )

:64_2
REG QUERY \\%1\%regkey2_64% > nul
if %errorlevel%== 0 (
    echo %regkey2_64% Found! >> "C:\Outlook\RegeditList.txt" 
    REG DELETE \\%1\%regkey2_64% /f >> "C:\Outlook\RegeditList.txt"
    goto :64_3
    ) else (
    echo %regkey2_64% not found on: %1 - Check >> "C:\Outlook\KeysNotFoundlist.txt"
    goto :64_3 )

:64_3
REG QUERY \\%1\%regkey3_64% > nul
if %errorlevel%== 0 (
    echo %regkey3_64% Found! >> "C:\Outlook\RegeditList.txt" 
    REG DELETE \\%1\%regkey3_64% /f >> "C:\Outlook\RegeditList.txt"
    echo. >> "C:\Outlook\RegeditList.txt"
    ) else (
    echo %regkey3_64% not found on: %1 - Check >> "C:\Outlook\KeysNotFoundlist.txt"
    echo. >> "C:\Outlook\KeysNotFoundlist.txt"
    echo. >> "C:\Outlook\RegeditList.txt" )     
  echo Checked %1 now going to loop! >> "C:\Outlook\RunLog.log"
  echo. >> "C:\Outlook\RunLog.log"
    :EOF

RunLog.log

Checked MJGXGTH now going to loop!
Checked 34ZXYC1 now going to loop! 
Checked 34ZXYC1 now going to loop!

RegeditList.txt

MJGXGTH is 64bit  
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\00002109A10000000000000000F01FEC\InstallProperties Found!
The Operation Completed Successfully
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\12.0\Registration\{90120000-001A-0000-0000-0000000FF1CE} Found!
The Operation Completed Successfully
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\OUTLOOK Found!
The Operation Completed Successfully 

34ZXYC1 is 32bit  
 Found!  
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Registration\{90120000-001A-0000-0000-0000000FF1CE} Found!  
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OUTLOOK Found!  

34ZXYC1 is 64bit  
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\00002109A10000000000000000F01FEC\InstallProperties Found!  

KeysNotFoundList.txt

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\12.0\Registration\{90120000-001A-0000-0000-0000000FF1CE} not found on: 34ZXYC1 - Check 
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\OUTLOOK not found on: 34ZXYC1 - Check 

Let me know if you need any more information!

Was it helpful?

Solution

(As of 2014-02-04 17:00 Eastern Std Time) You have failed to show all the relevant code - particulary the code that generates RunLog.Log.

The code you show uses goto :32_2 and goto :64_2, but you don't show those labels or their code. Most likely the code after label :32_2 is missing a goto :eof (or exit /b).

Regardless, the logic fault is in code that is not shown.


Updated answer in response to complete code now in question

It is as I suspected - You failed to put a GOTO :EOF after the :32_3 section of code, so it simply falls into the :64_1 section.

You should use GOTO :EOF instead of GOTO EOF - then you do not need to put an explicit :EOF label at the end of your script. Another alternative is to simply use EXIT /B instead - it does exactly the same thing as GOTO :EOF.

You can eliminate most of your labels since both the TRUE and FALSE of each IF statement GOTO the same label. You can simply let the code fall into the next section of code without any GOTO.

Also, the ELSE of your first IF is not really needed. It too can simply fall into the :32 section when it is not :64

@echo off
for /F "tokens=1 delims="  %%i in (C:\Outlook\OVLK.txt) do call :proccheck %%i
exit /b

:proccheck
REG QUERY \\%1\%proctype% 2>nul >nul
if %errorlevel% == 0 goto :64

:32 (Note - this label isn't needed, but I preserved it for documentation purposes)
echo %1 is 32bit >> "C:\Outlook\RegeditList.txt"
REG QUERY \\%1\%regkey1_64% > nul
if %errorlevel%== 0  (
  echo %regkey1_64% Found! >> "C:\Outlook\RegeditList.txt"
  REG DELETE \\%1\%regkey1_64% /f >> "C:\Outlook\RegeditList.txt"
) else (
  echo %regkey1_64% not found on: %1 - Check >> "C:\Outlook\KeysNotFoundlist.txt"
)
REG QUERY \\%1\%regkey2_32% > nul
if %errorlevel%== 0 (
  echo %regkey2_32% Found! >> "C:\Outlook\RegeditList.txt"
  REG DELETE \\%1\%regkey2_32% /f >> "C:\Outlook\RegeditList.txt"
) else (
  echo %regkey2_32% not found on: %1 - Check >> "C:\Outlook\KeysNotFoundlist.txt"
)
REG QUERY \\%1\%regkey3_32% > nul
if %errorlevel%== 0 (
  echo %regkey3_32% Found! >> "C:\Outlook\RegeditList.txt"
  REG DELETE \\%1\%regkey3_32% /f >> "C:\Outlook\RegeditList.txt"
  echo. >> "C:\Outlook\RegeditList.txt"
) else (
  echo %regkey3_32% not found on: %1 - Check >> "C:\Outlook\KeysNotFoundlist.txt"
  echo. >> "C:\Outlook\KeysNotFoundlist.txt"
  echo. >> "C:\Outlook\RegeditList.txt"
)
echo Checked %1 now going to loop! >> "C:\Outlook\RunLog.log"
echo. >> "C:\Outlook\RunLog.log"
exit /b

:64
echo %1 is 64bit >> "C:\Outlook\RegeditList.txt"
REG QUERY \\%1\%regkey1_64% > nul
if %errorlevel%== 0  (
  echo %regkey1_64% Found! >> "C:\Outlook\RegeditList.txt"
  REG DELETE \\%1\%regkey1_64% /f >> "C:\Outlook\RegeditList.txt"
) else (
  echo %regkey1_64% not found on: %1 - Check >> "C:\Outlook\KeysNotFoundlist.txt"
)
REG QUERY \\%1\%regkey2_64% > nul
if %errorlevel%== 0 (
  echo %regkey2_64% Found! >> "C:\Outlook\RegeditList.txt"
  REG DELETE \\%1\%regkey2_64% /f >> "C:\Outlook\RegeditList.txt"
) else (
  echo %regkey2_64% not found on: %1 - Check >> "C:\Outlook\KeysNotFoundlist.txt"
)
REG QUERY \\%1\%regkey3_64% > nul
if %errorlevel%== 0 (
  echo %regkey3_64% Found! >> "C:\Outlook\RegeditList.txt"
  REG DELETE \\%1\%regkey3_64% /f >> "C:\Outlook\RegeditList.txt"
  echo. >> "C:\Outlook\RegeditList.txt"
) else (
  echo %regkey3_64% not found on: %1 - Check >> "C:\Outlook\KeysNotFoundlist.txt"
  echo. >> "C:\Outlook\KeysNotFoundlist.txt"
  echo. >> "C:\Outlook\RegeditList.txt"
)
echo Checked %1 now going to loop! >> "C:\Outlook\RunLog.log"
echo. >> "C:\Outlook\RunLog.log"
exit /b

Another option is to use the && operator to conditionally execute code if the prior command was successful, and || to conditionally excecute code if the prior command failed. You do not need any CALL or GOTO at all.

@echo off
for /F "tokens=1 delims="  %%i in (C:\Outlook\OVLK.txt) do (
  REG QUERY \\%%i\%proctype% 2>nul >nul && (
    REM 64 section
    echo %%i is 64bit >> "C:\Outlook\RegeditList.txt"
    REG QUERY \\%%i\%regkey1_64% > nul && (
      REG DELETE \\%%i\%regkey1_64% /f >> "C:\Outlook\RegeditList.txt"
      echo %regkey1_64% Found! >> "C:\Outlook\RegeditList.txt"
    ) || (
      echo %regkey1_64% not found on: %%i - Check >> "C:\Outlook\KeysNotFoundlist.txt"
    )
    REG QUERY \\%%i\%regkey2_64% > nul && (
      REG DELETE \\%%i\%regkey2_64% /f >> "C:\Outlook\RegeditList.txt"
      echo %regkey2_64% Found! >> "C:\Outlook\RegeditList.txt"
    ) || (
      echo %regkey2_64% not found on: %%i - Check >> "C:\Outlook\KeysNotFoundlist.txt"
    )
    REG QUERY \\%%i\%regkey3_64% > nul && (
      echo %regkey3_64% Found! >> "C:\Outlook\RegeditList.txt"
      REG DELETE \\%%i\%regkey3_64% /f >> "C:\Outlook\RegeditList.txt"
      echo. >> "C:\Outlook\RegeditList.txt"
    ) || (
      echo %regkey3_64% not found on: %%i - Check >> "C:\Outlook\KeysNotFoundlist.txt"
      echo. >> "C:\Outlook\KeysNotFoundlist.txt"
      echo. >> "C:\Outlook\RegeditList.txt"
    )
    echo Checked %%i now going to loop! >> "C:\Outlook\RunLog.log"
    echo. >> "C:\Outlook\RunLog.log"
  ) || (
    REM 32 section
    echo %%i is 32bit >> "C:\Outlook\RegeditList.txt"
    REG QUERY \\%%i\%regkey1_64% > nul && (
      REG DELETE \\%%i\%regkey1_64% /f >> "C:\Outlook\RegeditList.txt"
      echo %regkey1_64% Found! >> "C:\Outlook\RegeditList.txt"
    ) || (
      echo %regkey1_64% not found on: %%i - Check >> "C:\Outlook\KeysNotFoundlist.txt"
    )
    REG QUERY \\%%i\%regkey2_32% > nul && (
      REG DELETE \\%%i\%regkey2_32% /f >> "C:\Outlook\RegeditList.txt"
      echo %regkey2_32% Found! >> "C:\Outlook\RegeditList.txt"
    ) || (
      echo %regkey2_32% not found on: %%i - Check >> "C:\Outlook\KeysNotFoundlist.txt"
    )
    REG QUERY \\%%i\%regkey3_32% > nul && (
      echo %regkey3_32% Found! >> "C:\Outlook\RegeditList.txt"
      REG DELETE \\%%i\%regkey3_32% /f >> "C:\Outlook\RegeditList.txt"
      echo. >> "C:\Outlook\RegeditList.txt"
    ) || (
      echo %regkey3_32% not found on: %%i - Check >> "C:\Outlook\KeysNotFoundlist.txt"
      echo. >> "C:\Outlook\KeysNotFoundlist.txt"
      echo. >> "C:\Outlook\RegeditList.txt"
    )
    echo Checked %%i now going to loop! >> "C:\Outlook\RunLog.log"
    echo. >> "C:\Outlook\RunLog.log"
  )
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top