回 帖 发 新 帖 刷新版面

主题:注册表定位器代码

注册表定位器代码


我们在操作注册表时,要在左边的目录树查找许久,很费神。本定位器可以减轻用户的负担,你只要在文本框中输入要查找的子键全路径(注意最后要输入一个英文“\”,表示路径最后是目标子键),回车或点击命令按纽,就可以自动打开注册表编辑器直接定位到你指定的子键上。代码如下:


Option Explicit


Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long


Private Sub Command1_Click()
On Error GoTo 100
Dim Hwnd As Long, ws
Hwnd = FindWindow(vbNullString, "注册表编辑器")
If Hwnd Then PostMessage Hwnd, &H10, 0&, 0& '如果找到窗口就关闭
Set ws = CreateObject("wscript.shell")
ws.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\LastKey", Text1 '打开的注册表将定位到文本框表示的子键
Shell "regedt32.exe", 1
100
Set ws = Nothing
End Sub


Private Sub Text1_Click()
Text1.SelStart = 0: Text1.SelLength = Len(Text1)
End Sub


Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Command1_Click
End Sub


本代码在XP和32位win7旗舰版上均已通过。

回复列表 (共1个回复)

沙发

专程前来顶贴

我来回复

您尚未登录,请登录后再回复。点此登录或注册