2015-05-01 95 views
2

我想寫一個註冊查詢批處理文件,查找不包含的東西的關鍵數據。目前,此代碼搜索密鑰Dependent Files(REG_MULTI_SZ)並將輸出寫入文件。我需要它忽略包含「**。GPD *」的Dependent Files內的任何數據。批處理文件註冊查詢與邏輯運算符(不)

如何將邏輯運算符合併到簡單的REG QUERY中?

@echo off 
set file=c:\Temp\regcomplist.txt 
for /f "Tokens=*" %%g in (%file%) do (
    echo %%g>> c:\Temp\regquery.txt 
    REG QUERY "\\%%g\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3\Lexmark Universal v2 XL" /v "Dependent Files">> c:\Temp\regquery.txt 
    echo.>> c:\Temp\regquery.txt 
    echo.>> c:\Temp\regquery.txt 
) 
+2

將您的'reg query'命令輸入到'find/i/v「.GPD」'或'find/i/v「**。GPD *」'或任何合適的。 – rojo

+0

這是有用的,但我怎麼找到哪裏依賴值沒有* GPD * –

+0

DOH ...這是什麼/ v是:: FACEPALM :: –

回答

1

使用所述命令由rojo作爲建議的批次代碼是:

@echo off 
set "ListFile=C:\Temp\regcomplist.txt" 
set "ResultsFile=C:\Temp\regquery.txt" 
for /f "delims=" %%g in (%ListFile%) do (
    echo %%g>>%ResultsFile% 
    %SystemRoot%\System32\reg.exe query "\\%%g\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3\Lexmark Universal v2 XL" /v "Dependent Files" | %SystemRoot%\System32\find.exe /i /v "**.GPD*">>%ResultsFile% 
    echo.>>%ResultsFile% 
    echo.>>%ResultsFile% 
) 

添加信息註冊表值Dependent FilesREG_MULTI_SZ類型後,我到一個計算機具有打印機安裝(我的一個沒有),並將此打印機的註冊表項以regedit導出到.reg文件。接下來,我將此註冊表文件導入到我的計算機的註冊表中,並執行一次reg query以獲取此密鑰,以瞭解如何將多行值寫入控制檯reg

然後我可以開發下面的批註文件。

@echo off 
setlocal EnableDelayedExpansion 

set "Printer=Lexmark Universal v2 XL" 
set "ListFile=C:\Temp\regcomplist.txt" 
set "ResultsFile=C:\Temp\regquery.txt" 
if exist "%ResultsFile%" del "%ResultsFile%" 

rem Run the procedure GetPrinterFiles on each computer of list file. 
for /f "delims=" %%g in (%ListFile%) do (
    echo %%g>>%ResultsFile% 
    call :GetPrinterFiles "%%g" 
    echo.>>%ResultsFile% 
    echo.>>%ResultsFile% 
) 
endlocal 
rem Exit this batch file. 
goto :EOF 

rem Get multiline string with the file names from registry and parse that 
rem string with procedure GetFileNames if the printer is installed at all. 

:GetPrinterFiles 
for /F "skip=2 tokens=3*" %%A in ('%SystemRoot%\System32\reg.exe query "\\%~1\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3\%Printer%" /v "Dependent Files" 2^>nul') do (
    if "%%A"== "REG_MULTI_SZ" (
     call :GetFileNames "%%B" 
     goto :EOF 
    ) 
) 
rem Document in results file that printer is not installed on this computer. 
echo Error: %Printer% not installed.>>%ResultsFile% 

rem Exit procedure GetPrinterFiles and return to main loop above. 
goto :EOF 

rem The file names are passed from procedure GetPrinterFiles in a long string 
rem with \0 as separator between the file names. This long string is split 
rem into individual file names by the FOR loop below. Each file name is 
rem assigned to an environment variable. A case-sensitive comparison is 
rem made between value of this variable having all ".GPD" case-insensitive 
rem removed with unmodified value of this variable. If modified variable 
rem value is equal unmodified variable value, ".GPD" is not present in any 
rem case in file name resulting in writing the file name into the results 
rem file. Otherwise this file containing ".GPD" in any case is ignored. 

:GetFileNames 
set "FilesList=%~1" 
for %%F in ("%FilesList:\0=","%") do (
    set "FileName=%%~F" 
    if "!FileName:.GPD=!" == "!FileName!" (
     echo !FileName!>>%ResultsFile% 
    ) 
) 
rem Exit procedure GetFileNames and return to GetPrinterFiles procedure above. 
goto :EOF 

由於去rojo爲他的separating variable with a symbol into different parts回答我展示瞭如何通過輸出REG\0分離的所有文件名處理長字符串。

+0

這輸出亞洲字符憖檔湩湥浡൥ഊഊ伊䑃㝔㌰㠲㌴ഷഊ㌴ഷഊ等任何想法? –

+0

美麗!是否可以僅使用Lexmark Universal V XL輸出缺少相關文件的設備?我只需要一個損壞的驅動程序的機器列表,沒有別的。你的回答是史詩般的,非常感謝你! –

+0

當然可以檢查__C中缺少哪些文件:\ Windows \ Sysnative \ spool \ drivers \ x64__及其子目錄,然後將結果文件寫入僅有缺少1個或多個文件的計算機以及缺少哪些文件。 – Mofi