<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; VBScript: поиск и удаление ключей реестра]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=4382</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=4382&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «VBScript: поиск и удаление ключей реестра».]]></description>
		<lastBuildDate>Fri, 16 Apr 2010 06:11:26 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[VBScript: поиск и удаление ключей реестра]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=34815#p34815</link>
			<description><![CDATA[<p><span class="bbu">Скрипт для поиска и удаления искомых ключей реестра.</span><br />1. Запрос искомой фразы для поиска.<br />2. Вывод результатов в окне Блокнота <strong>с возможностью исключения</strong> параметров по желанию пользователя.<br />3. Сохранение файла отчёта в текущей директории по выбору пользователя.<br /></p><div class="codebox"><pre><code>Option Explicit
Dim sSearchFor, st, st0, sRegTmp, sOutTmp, eRegLine, iCnt, sRegKey, aRegFileLines, stroca, isDel, delLine, delLines, resbox
Dim wssh : Set wssh = CreateObject(&quot;WScript.Shell&quot;)
Dim FSO : Set FSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)

sSearchFor = InputBox(&quot;Введите в поле искомое слово.&quot; &amp;vbcrlf&amp;vbcrlf&amp; &quot;Задавая искомую фразу, будьте осторожны: Убедитесь в уникальности имени удаляемого параметра...&quot;, &quot;Реестр | fate (modified by Lucky)&quot;)
If sSearchFor = &quot;&quot; Then Cleanup()
 
Dim StartTime : StartTime = Timer
 
sRegTmp = wssh.Environment(&quot;Process&quot;)(&quot;Temp&quot;) &amp; &quot;\RegTmp.tmp &quot;
sOutTmp=&quot;RegDel &quot;&amp;sSearchFor&amp;&quot;.txt&quot;

wssh.Run &quot;regedit /e /a &quot; &amp; sRegTmp, , True 
aRegFileLines = Split(FSO.GetFile(sRegTmp).OpenAsTextStream(1, 0).Read(FSO.GetFile(sRegTmp).Size), vbcrlf) &#039;делим текст данных на строки
FSO.DeleteFile(sRegTmp)

Dim txt : Set txt = fso.OpenTextFile(sOutTmp,2,True)
txt.WriteLine &quot;&lt;fate (modified by Lucky) | Реестр&gt;&quot;
txt.WriteLine &quot;&lt;Ниже перечислены найденные ветки&gt;&quot;&amp;vbcrlf&amp;&quot;&lt;Вы можете удалить здесь те строки, которые хотели бы оставить в реестре...&gt;&quot;

For Each eRegLine in aRegFileLines
On Error Resume Next
  If InStr(1, eRegLine, &quot;[&quot;, 1) &gt; 0 Then         &#039;проверяем: это раздел (если есть [) или параметр.
    sRegKey = eRegLine
  end if
  If InStr(1, eRegLine, sSearchFor, 1) &gt;  0 Then &#039;если в строке найдено искомая фраза, работаем с ней:
    If sRegKey &lt;&gt; eRegLine Then
      st0=Split(eRegLine,&quot;=&quot;)           &#039;делим пераметр на то что левее &quot;=&quot; (имя) и правее &quot;=&quot; (значение)
      st=Replace(st0(0),&quot;&quot;&quot;&quot;,&quot;&quot;)        &#039;берем лишь имя параметра для построения пути
      stroca=Mid(sRegKey,2)
      stroca=Replace (stroca,&quot;]&quot;,&quot;&quot;,1)  &#039;исключяем знаки ] из строки Раздела
      txt.WriteLine stroca &amp;&quot;\&quot;&amp; st     &#039;запись строки в обрабатываемый файл
    else
      stroca=Mid(sRegKey,2) 
      stroca=Replace (stroca,&quot;]&quot;,&quot; &quot;,1)
      stroca =Trim(stroca)
      txt.WriteLine stroca &amp; &quot;\&quot;        &#039;запись строки в обрабатываемый файл
    End If
    iCnt = iCnt + 1
  End If
Next

txt.Close
Erase aRegFileLines
 
If iCnt &lt; 1 Then
  wssh.Popup &quot;Поиск длился  &quot; &amp; FormatNumber(Timer - StartTime, 0) &amp; &quot; сек. &quot; &amp; _
             &quot;По запросу &quot; &amp; chr(34) &amp; sSearchFor &amp; chr(34) &amp; _
             &quot; ничего не найдено.&quot;,, &quot;Реестр | fate (modified by Lucky)&quot;, 4096
  FSO.DeleteFile(sOutTmp)
  Cleanup()
End If
 
wssh.Popup &quot;Поиск длился &quot; &amp; FormatNumber(Timer - StartTime, 0) &amp; &quot; сек. &quot; &amp; _
          iCnt &amp; &quot; совпадений по запросу &quot; &amp; chr(34) &amp; sSearchFor &amp; chr(34),, _
          &quot;Реестр | fate (modified by Lucky)&quot;, 4096
 
wssh.Run &quot;NotePad &quot; &amp; sOutTmp, 3, True &#039;открытие NotePad с отчётом об удалении

delLines = Split(FSO.OpenTextFile(sOutTmp,1).ReadAll, vbcrlf)
For Each delLine in delLines
  if Left(delLine,1)&lt;&gt;&quot;&lt;&quot; then
   Err.Clear
   wssh.RegDelete delLine                   &#039;удаление строки в реестре
   If Err.Number&lt;&gt;0 then
      Err.Clear : wssh.RegRead delLine
      if Err.Number=0 then
        resbox=resbox&amp;delLine&amp;vbCrLf&amp;vbCrLf
      end if
   End if
  end if
Next
if resbox&lt;&gt;&quot;&quot; then resbox=&quot;Следующие строки удалить не удалось:&quot;&amp;vbCrLf&amp;resbox

isDel=wssh.Popup(resbox&amp;&quot;Хотите сохранить файл отчета удаляемых строк?&quot;,, _
                 &quot;Отчёт | fate (modified by Lucky)&quot;, 36)
if isDel=7 then FSO.DeleteFile(sOutTmp)
Cleanup()
 
Sub Cleanup()
  Set wssh = Nothing
  Set FSO = Nothing
  WScript.Quit
End Sub</code></pre></div><p>Авторы скрипта — <strong>Lucky</strong> и <strong>fate</strong>.</p>]]></description>
			<author><![CDATA[null@example.com (The gray Cardinal)]]></author>
			<pubDate>Fri, 16 Apr 2010 06:11:26 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=34815#p34815</guid>
		</item>
	</channel>
</rss>
