为什么这个循环两次为32位系统?

时间:2014-02-04 20:42:32

标签: batch-file registry batch-processing remote-access regedit

所以我想要完成的是:

1)从计算机列表中读取

2)确定它的Windows位(参见下面的reg键)

3)转到相应的if语句并删除密钥(如果存在)。

它在64位系统上运行令人惊叹,但出于某种原因,当它遇到32位系统(没有\Wow6432Node\的系统)时,它会循环两次并称之为64位系统。我很困惑为什么会这样做。

这是我正在使用的最新代码,旧版本具有set regkey1_32=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\00002109A10000000000000000F01FEC\InstallProperties

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

所以我可能需要一些新的眼睛来看看我没有。

OVLK.txt包含计算机名称,因此您放入的内容无关紧要(MJGXGTH(x64)\ 34ZXYC1(x86))。日志文件输出位于底部。

@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 

如果您需要更多信息,请与我们联系!

1 个答案:

答案 0 :(得分:1)

(截至2014-02-04 17:00 Eastern Std Time)您未能显示所有相关代码 - 特别是生成RunLog.Log的代码。

您展示的代码使用goto :32_2goto :64_2,但您不会显示这些标签或其代码。标签:32_2之后的代码很可能缺少goto :eof(或exit /b)。

无论如何,逻辑错误都在未显示的代码中。


更新了答案以回应现在有问题的完整代码

我怀疑 - 您未能在GOTO :EOF部分代码后面加:32_3,因此它只会落入:64_1部分。

您应该使用GOTO :EOF而不是GOTO EOF - 然后您不需要在脚本末尾添加明确的:EOF标签。另一种方法是简单地使用EXIT /B - 它与GOTO :EOF完全相同。

您可以删除大多数标签,因为每个IF语句的TRUE和FALSE都是相同的标签。你可以简单地让代码落入下一部分代码而不需要任何GOTO。

此外,您的第一个IF的ELSE并不是真正需要的。当它不是:64

时,它也可以简单地落入:32部分
@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

另一种选择是使用&&运算符在先前命令成功时有条件地执行代码,并且||在先前命令失败时有条件地执行代码。你根本不需要任何CALL或GOTO。

@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"
  )
)