2014-10-01 2 views
0

현재 특정 문자열이 포함되거나 이름이 지정된 모든 레지스트리 키를 삭제하기 위해 배치 파일 작업을하고 있습니다 (예 :이 작업의 위험성을 알고 있음). 몇 가지 문제가 있습니다."문자열"이 포함 된 모든 레지스트리 키를 일괄 처리로 삭제합니다.

내가 사용하려고 시도 된 코드는 :이 레지스트리의 매우 미리 정해진 영역에 대한 작동

@echo off 
set "key=HKEY_LOCAL_MACHINE\SOFT-EXT" 
set "search=string" 
for /f "delims=" %%a in ('reg query "%key%" /s^| findstr "%search%"') do reg delete "%key%" /v "%%~a" 

- 나에게 유일한 단점 내 스크립트가 전체 SOFTWARE 레지스트리 하이브를 구문 분석 할 필요가 있다는 것입니다 외부 드라이브에서로드됩니다. 현재 발생하는 상황은 스크립트가 약 20 초 동안 실행되고 명령 프롬프트에서 반환되지 않습니다. 그 다음, 줄 번호에 값이 증가하면서 FINDSTR: Line 50300 too long을 포함하는 줄이 계속 표시됩니다. 몇 가지 간단한 독서를 통해 findstr은 많은 데이터 바이트 만 관리 할 수 ​​있으며이 레지스트리 하이브 (약 80-100MB)의 방대한 크기 때문에 분명히 오버로드되고 있다고 생각합니다. 가끔 문자열을 포함하는 레지스트리 키가 HKLM\SOFTWARE\Classes\CSID\{###-###-###}\Example 지명 할 수 있기 때문에

는 하나, 그러나이 작동하지 않습니다 나는 두 조건 &&들과 ||에 추가 쿼리를 가지고 루프에 대한 변경을 시도,이 문제를 해결하려면 DWORD는 Name이고 데이터 값은 string입니다.

배치 파일로 수행하고 싶은 작업을 수행 할 수있는 방법이 있습니까? 필자는 PowerShell을 사용하는 것이 가능하다고 믿습니다. 그러나 현재 작업하고있는 환경은 PowerShell 또는 VB 스크립팅을 지원하지 않습니다.

+1

find 대신 findstr을 사용해보십시오. –

+0

죄송합니다 - 실제로 코드에서 findstr입니다. 나는 잘못 입력했다. – John

답변

1

내가 당신이 원하는 것을 정말 확실하지 않다 :

당신이 정말 레지스트리를 값 질문의 제목에 작성된는 Regedit를에 트리의 왼쪽에 표시 키, 또는 레지스트리를 삭제 하시겠습니까 종류 : ? (REG_SZ?)은 오른쪽에 표시되며 Regedit입니다.

의 레지스트리 값을 삭제 하시겠습니까?은 레지스트리 키를 삭제하는 것보다 훨씬 어렵습니다.

다음은 레지스트리 키를 검색하는 데 사용되는 코드이며 Action=Find으로 나열하거나 주석 처리 된 배치 코드의 맨 위에 Action=Delete으로 삭제하는 배치 코드입니다.

여기에 게시 된 Action=Find으로이 배치 코드를 먼저 실행하고 Action=Delete을 사용하여 삭제 된 레지스트리 키를 찾아 보는 것이 좋습니다.

@echo off 
setlocal 

rem Change value "Find" to "Delete" to really delete all found keys. 
set "Action=Find" 

rem Define the root key for the search. 
set "RegKey=HKEY_LOCAL_MACHINE\SOFTWARE" 

rem Define the string which must be found in name of a key to delete. 
rem It should not contain characters interpreted by FINDSTR as regular 
rem expression character, see help output on entering FINDSTR /? in a 
rem command prompt window. 
set "Search=ABCDEFGHIJKLM" 

rem Check if specified registry key exists at all. 
%SystemRoot%\System32\reg.exe query "%RegKey%" 1>nul 2>nul 
if not errorlevel 1 goto RunSearch 

echo. 
echo Registry key "%RegKey%" not found. 
goto EndBatch 

:RunSearch 
rem Exporting everything of defined root key to a temporary text file. 
echo Exporting registry key "%RegKey%" ... 
%SystemRoot%\System32\reg.exe query "%RegKey%" /s >"%TEMP%\RegExport.tmp" 2>nul 

rem The backslash is the escape character in regular expressions. Therefore 
rem it is necessary to escape this character in root registry key to get a 
rem working regular expression search string as long as the root registry 
rem key and the search string do not contain other characters with special 
rem registry expression meaning. 
set "RegKey=%RegKey:\=\\%" 

rem Interesting are only lines in exported registry which contain the 
rem search string in last key of a registry key path. In other words 
rem the deletion of a key is always done only on root key containing in 
rem name the search string and not also on all subkeys to improve speed. 

if /I "%Action%"=="Delete" (
    echo Searching for keys containing "%Search%" and delete all found ... 
) else (
    echo Searching for keys containing "%Search%" and list all found ... 
) 

rem The expression below works only correct if whether RegKey nor 
rem Search contains characters with a regular expression meaning. 
set "FoundCounter=0" 
set "DeleteCounter=0" 
for /f "delims=" %%K in ('%SystemRoot%\System32\findstr.exe /R "^%RegKey%.*%Search%[^\\]*$" "%TEMP%\RegExport.tmp" 2^>nul') do (
    echo %%K 
    set /A FoundCounter+=1 
    if /I "%Action%"=="Delete" (
     %SystemRoot%\System32\reg.exe delete "%%K" /f >nul 
     if not errorlevel 1 set /A "DeleteCounter+=1" 
    ) 
) 
del "%TEMP%\RegExport.tmp" 

set "FoundPlural=" 
if not %FoundCounter%==1 set "FoundPlural=s" 
set "DeletePlural=" 
if not %DeleteCounter%==1 set "DeletePlural=s" 

echo. 
if /I "%Action%"=="Delete" (
    echo Deleted %DeleteCounter% key%DeletePlural% of %FoundCounter% key%FoundPlural% containing "%Search%". 
) else (
    echo Found %FoundCounter% key%FoundPlural% containing "%Search%". 
) 

:EndBatch 
endlocal 
echo. 
echo Exit with any key ... 
pause >nul 
+0

나는 명확하지 않다는 것에 대해 사과드립니다.'string'이라는 이름의 레지스트리 키를 모두 제거해야합니다. 예를 들어 (문자열이 "Adobe"인 경우) HKLM \ SOFTWARE \ Adobe \ Adobe Bridge' 및 'HKCR \ .pdfxml - 컨텐츠 유형 : application/vnd.adobe.pdfxml'모두 제거해야합니다. – John

관련 문제