---
title: "不用API，也能玩注册表--vb !(downmoon原创）"
author: "netxdiy"
date: "2003-02-26T08:48:00Z"
tags: []
slug: "api-vb-downmoon"
draft: false
lastmod: "2012-09-27T11:35:39Z"
id: 1687243
url: "https://netxdiy.iteye.com/blog/1687243"
---

不用API，也能玩注册表--vb !(downmoon原创）

补充： 需新建四个command ,  
名称依次为  
write\_reg  
read\_reg  
del\_reg  
reg\_run  
对应Caption为：  
建立新键  
读取注册表  
删除新键  
启动自运行

OK！

代码如下：

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)' \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' 请务必引用“WindowsScriptHostObjectModel"Lib  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) '  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) '  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' Note:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) '  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' 需引用“WindowsScriptHostObjectModel"Lib  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' "HKLM"指"HKEY\_LOCAL\_MACHINE"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' "HKCU"指"HKEY\_CURRENT\_USER"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' 其它几个注册表主键依次类推，但必须大写  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' 适用于vb6简体中文版  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' 可以读出瑞星的安装ID  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) '  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' byDownmoon  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) '  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' QQ:23409408  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) '  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' 1000sun@163.com  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) '  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' 2003-2-16  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) '  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ' \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) Option Explicit  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) Dim mynumber As Integer  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) Private Reg  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif) Private Subdel\_reg\_Click() Sub del\_reg\_Click()  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Dim Cancel As Integer  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Dim mydelete As String  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) If MsgBox ( " Areusuretodelete " & vbTab & " HKLMSOFTWARERisingRavMyRising " & vbTab & " ? " ,vbYesNo, " 确认前先保存注册表！！！ " ) = vbNo Then  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Cancel = True  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Else  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) mydelete = Reg.RegDelete( " HKLMSOFTWARERisingRavMyRising " )  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) MsgBox " AlreadyDeleted!!!! " & vbTab & Chr ( 13 ) & " HKLMSOFTWARERisingRavMyRising====D: isingRavRav.exe "  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) End If  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif) EndSub  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif) Private SubForm\_Load() Sub Form\_Load()  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) mynumber = 0  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Set Reg = New IWshShell\_Class  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif) EndSub  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif) Private SubForm\_Unload() Sub Form\_Unload(Cancel As Integer )  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) ilovedownmoon.Caption = " 再见 "  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) If ilovedownmoon.WindowState &lt;&gt; 1 Then  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Dim I As Long  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) For I = 50 To ilovedownmoon.Height  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) If ilovedownmoon.Height &gt; 400 Then  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) ilovedownmoon.Height = ilovedownmoon.Height - 30  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) End If  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Next I  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) For I = 50 To ilovedownmoon.Width  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) If ilovedownmoon.Width &gt; 500 Then  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) ilovedownmoon.Width = ilovedownmoon.Width - 30  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) End If  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Next I  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) End If  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) End  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif) EndSub  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif) Private Subread\_reg\_Click() Sub read\_reg\_Click()  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) MsgBox ( " ^\_^!YourrisingIDis: " & Chr ( 13 ) & Chr ( 13 ) & Chr ( 13 ) & vbTab & Reg.RegRead( " HKLMSOFTWARERisingRavNetID " ) & Chr ( 13 ) & Chr ( 13 ) & Chr ( 13 ) & Chr ( 13 ) & vbTab & " OK？ " )  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif) EndSub  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif) Private Subreg\_run\_Click() Sub reg\_run\_Click()  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) On Error Resume Next  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Dim myrun As String  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Dim mynorun As String  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) If mynumber 2 = 0 Then  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) myrun = Reg.RegWrite( " HKLMSOFTWAREMicrosoftWindowsCurrentVersionRuncdplayer " , " C:WINNTsystem32cdplayer.exe " , " REG\_SZ " )  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) MsgBox ( Chr ( 13 ) & vbTab & " added " & Chr ( 13 ) & vbTab & vbTab & " C:WINNTsystem32cdplayer.exe " & Chr ( 13 ) & vbTab & " intoAutoRun! " )  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) reg\_run.Caption = " 取消自运行 "  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) ' 测试  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) ' Label1.Caption=mynumber  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) GoTo num  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Else  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) mynorun = Reg.RegDelete( " HKLMSOFTWAREMicrosoftWindowsCurrentVersionRuncdplayer " )  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) MsgBox ( Chr ( 13 ) & vbTab & " Deleted " & Chr ( 13 ) & vbTab & vbTab & " C:WINNTsystem32cdplayer.exe " & Chr ( 13 ) & vbTab & " outofAutoRun! " )  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) reg\_run.Caption = " 启动自运行 "  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) ' 测试  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) ' Label1.Caption=mynumber  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) GoTo num  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) End If  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) num:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) mynumber = mynumber + 1  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif) EndSub  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif) Private Subwrite\_reg\_Click() Sub write\_reg\_Click()  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Dim Cancel As Integer  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Dim mytest As String  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) If MsgBox ( " Reallywrite " & vbTab & " HKLMSOFTWARERisingRavMyRising " & vbTab & " ? " ,vbYesNo, " 确认前先保存注册表！！！ " ) = vbNo Then  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Cancel = True  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Else  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) mytest = Reg.RegWrite( " HKLMSOFTWARERisingRavMyRising " , " D: isingRavRav.exe " , " REG\_SZ " )  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) ' REG\_SZ表示键的类型，为缺省值。  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) MsgBox " HKLMSOFTWARERisingRavMyRising====D: isingRavRav.exe " & vbTab & Chr ( 13 ) & " Writed!!!!! "  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) End If  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif) EndSub