使用API...很简单!!
Option Explicit
Public Declare Function RegSetValueEx Lib "advapi32.dll" _
Alias "RegSetValueExA" _
(ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal Reserved As Long, _
ByVal dwType As Long, lpData As Any, _
ByVal cbData As Long) As Long
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias _
"RegCreateKeyA" (ByVal hKey As Long, _
ByVal lpSubKey As String, _
phkResult As Long) As Long
Public Const REG_SZ = 1
Public Const HKEY_LOCAL_MACHINE = &H80000002
Sub Main()
Dim Xm As String
Dim Bux As Long
Dim I_am As String
Dim LuJing As String
If Right(App.Path, 1) <> "\" Then
LuJing = App.Path & "\"
Else
LuJing = App.Path
End If
I_am = LuJing & "test.exe" '用APP.FILENAM也可以
Xm = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
RegCreateKey HKEY_LOCAL_MACHINE, Xm, Bux
RegSetValueEx Bux, "test", 0, REG_SZ, ByVal I_am, LenB(I_am)
MsgBox "添加至HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" & _
vbCrLf & "成功!!"
End Sub