Board logo

标题: 不用WMI枚举键值→VBS [打印本页]

作者: baomaboy     时间: 2007-4-14 05:32    标题: 不用WMI枚举键值→VBS

看了一下时间,应该是2000年的东西了,如果没记错,应该取自“电脑爱好者”

作用是枚举并可选择性删除“运行”的历史记录。
删除:HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMR下的键值。
注意:“重启”或“注销”或结束“explorer进程”后看效果。

键下值集具规律性,所以不用WMI可枚举。

[ Last edited by baomaboy on 2008-3-25 at 12:12 AM ]
作者: kich     时间: 2007-4-14 07:13
兄收藏了这么多的VBS好东西啊??
顶啊!!
作者: electronixtar     时间: 2007-4-14 23:31
MRU的命名有规律的,呵呵
作者: baomaboy     时间: 2007-4-15 00:14


  Quote:
Originally posted by electronixtar at 2007-4-14 23:31:
MRU的命名有规律的,呵呵



好像用shell.RegRead只能读取已知键值,而WMI才是真正的枚举。

RunMRU键下键名规律为a、b、c、d.......
并且还有MRUList的值提供读取范围

由此规律 键下键名都成了已知项。

  Quote:
'Script to modify the MRU list for Start>Run,        Steve Yandl, Sept 11, 2000
Dim shell, dict, path, Ordering, Counter, TLimit, Letter, RunLine, k, i, s, DumpIt, Purge, Zap, Alphabet, Keepers, l, Newref
Dim TheLine
Set shell=CreateObject("Wscript.Shell")
Set dict = CreateObject("Scripting.Dictionary")
path="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU"
On Error Resume Next
'Find out what is presently there and populate the dictionary object with the values
Ordering=shell.RegRead(path&"\MRUList")
If Err.Number<>0 Then MsgBox "There are no entries to clear":Set shell=Nothing:Set dict=Nothing:WScript.Quit
If Ordering="" Then MsgBox "There are no entries to clear":Set shell=Nothing:Set dict=Nothing:WScript.Quit
Counter=0
TLimit=Len(Ordering)
Do While Counter<TLimit
Counter=Counter+1
Letter=Mid(Ordering,Counter,1)
RunLine=shell.RegRead(path&"\"&Letter)
dict.add Letter, RunLine
Loop
          k=dict.keys
          For i = 0 To dict.Count -1 ' Iterate the array.
          TheLine=Left(dict.Item(k(i)),Len(dict.Item(k(i)))-2)
          s = s &k(i)&" >>         "& TheLine &vbCRLF ' Create return string.   
          Next
'Let the user pick items to dump
DumpIt=InputBox("ENTER INDEX LETTERS FOR ANY RUN LINES TO DELETE (Reboot after OK)"&vbCRLF&_
vbCRLF&"Index >> Run Line"&vbCRLF&s,"Kill These")
Purge=Len(DumpIt)
'Delete bum keys or escape program
          If Purge>0 Then
          For i = 0 To dict.Count -1 ' Iterate the array.
          shell.RegDelete path&"\"&k(i)        
          Next
          Else
          Set dict=Nothing
          Set shell=Nothing
          WScript.Quit
          End If
'Dump entries in the record we don't want back in the registry
          For j=1 To Purge
          Zap=Mid(DumpIt,j,1)
          dict.Remove Zap
          Next
'Reset the MRU list for remaining values and write them back to the registry
Alphabet="abcdefghijklmnopqurstvwxyz"
Keepers=Left(Alphabet,(TLimit-Purge))
shell.RegWrite path&"\MRUList",Keepers
'
         l=dict.keys
         For i = 0 To dict.Count-1
         Newref=Mid(Keepers,i+1,1)
         shell.RegWrite path&"\"&Newref,dict.Item(l(i))
         Next
Set dict=Nothing
Set shell=Nothing

 

[ Last edited by baomaboy on 2008-3-25 at 12:14 AM ]
作者: kich     时间: 2007-4-15 00:19
强,看完上述评论后,反正我是在云里雾里,先不管,保存下来先!
我想我还没到那个地步吧!!
多谢!
作者: tttest     时间: 2007-5-15 11:39
能给个分析吗?
作者: zhoushijay     时间: 2007-5-15 14:14
始终不能领悟WMI
作者: 77720666     时间: 2007-5-15 14:38
XP下试了只删了一项记录后就不行了~按照提示删除所有记录后查看运行记录只删了一项~再运行就提示“There are no entries to clear”
查看 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU 所有键值都没了~
作者: baomaboy     时间: 2007-5-15 15:46


  Quote:
Originally posted by 77720666 at 2007-5-15 14:38:
XP下试了只删了一项记录后就不行了~按照提示删除所有记录后查看运行记录只删了一项~再运行就提示“There are no entries to clear”
查看 HKEY_CURRENT_USER\So ...

输入a 就删除a对应的值这一项没什么错误啊,不明白你所谓的“就不行了~”是什意思,另外你说的全是正常现象。
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU 所有键值都没了~" 全部删除当然所有值都没了。更当然“There are no entries to clear”了。

(Reboot after OK)已经提示你重启后看效果了,你自己没注意而已。另外你不重启的话“注销”结束“explorer”进程都可以。