我正在運行批處理文件,使用「reg查詢」命令檢查一些註冊表文件。我設置了將錯誤消息發送到錯誤日誌(ErrorLog.txt),並告訴用戶檢查主結果文本文件(REGValues.txt)中的錯誤日誌。問題是我在整個REGValues.txt文件中看到這些看似隨機的空白行。我如何避免插入這些空行?批量註冊查詢添加意外的空白行到輸出文件
這是我的代碼的一部分,剛剛過去它通常添加到空白行的地方。
mkdir c:\temp2\
SET dirname=c:\temp2\
SET filename2=REGValues.txt
SET errlog=ErrorLog.txt
:_registryValues
@echo Scanning Registry Values
@echo HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\LegalNoticeText 1>> %dirname%/%errlog%
reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\" /v LegalNoticeText /z 1>> %dirname%\%filename2% 2>> %dirname%\%errlog%
if errorLevel 1 echo Check Error Log 1>> %dirname%\%filename2%
@echo HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\LegalNoticeCaption 1>> %dirname%/%errlog%
reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\" /v LegalNoticeCaption /z>> %dirname%\%filename2% 2>> %dirname%\%errlog%
if errorLevel 1 echo Check Error Log 1>> %dirname%\%filename2%
@echo HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword 1>> %dirname%/%errlog%
reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\" /v DefaultPassword /z >> %dirname%\%filename2% 2>> %dirname%\%errlog%
if errorLevel 1 echo Check Error Log 1>> %dirname%\%filename2%
@echo HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\AdditionalBaseNamedObjectsProtectionMode 1>> %dirname%/%errlog%
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\" /v AdditionalBaseNamedObjectsProtectionMode /z >> %dirname%\%filename2% 2>> %dirname%\%errlog%
if errorLevel 0 echo Check Error Log 1>> %dirname%\%filename2%
@echo HKLM\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\EnablePortLocking 1>> %dirname%/%errlog%
reg query HKLM\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\ /v EnablePortLocking /z >> %dirname%\%filename2% 2>> %dirname%\%errlog%
if errorLevel 1 echo Check Error Log 1>> %dirname%\%filename2%
@echo HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\EnhancedSecurityLevel 1>> %dirname%/%errlog%
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\" /v EnhancedSecurityLevel /z >> %dirname%\%filename2% 2>> %dirname%\%errlog%
if errorLevel 1 echo Check Error Log 1>> %dirname%\%filename2%
@echo HKLM\SYSTEM\CurrentControlSet\Services\NTDS\Parameters\LDAPServerIntegrity 1>> %dirname%/%errlog%
reg query HKLM\SYSTEM\CurrentControlSet\Services\NTDS\Parameters\ /v LDAPServerIntegrity /z >> %dirname%\%filename2% 2>> %dirname%\%errlog%
if errorLevel 1 echo Check Error Log 1>> %dirname%\%filename2%
這裏是文本文件的樣子,我把結果太:
Check Error Log
Check Error Log
Check Error Log
Check Error Log
Check Error Log
Check Error Log
它打印出我的錯誤日誌就好:
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\LegalNoticeText
ERROR: The system was unable to find the specified registry key or value.
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\LegalNoticeCaption
ERROR: The system was unable to find the specified registry key or value.
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword
ERROR: The system was unable to find the specified registry key or value.
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\AdditionalBaseNamedObjectsProtectionMode
ERROR: The system was unable to find the specified registry key or value.
HKLM\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\EnablePortLocking
ERROR: The system was unable to find the specified registry key or value.
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\EnhancedSecurityLevel
ERROR: The system was unable to find the specified registry key or value.
你使用什麼Windows版本? – Endoro
我使用的是Windows 8,但它也發生在Windows 7上......我想我想通了。我以爲你只需要雙引號,如果我正在尋找註冊表值的空間,但沒有雙引號的值是我得到空行的地方。 – Chris
雙引號並不是解決方案,但我將問題縮小到:它發生在沒有雙引號「」的鍵上。我嘗試添加它,但它只是說沒有找到密鑰,即使之前是這樣。 – Chris