'模块中的代码 Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value. Public Const REG_SZ = 1 Public Const HKEY_CURRENT_USER = &H80000001 '窗体中的代码 Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Dim hKey As Long Dim strRunCmd As String 'If UnloadMode = vbAppWindows Then strRunCmd = 程序路径及名称 '注册表Software\Microsoft\Windows\CurrentVersion\RunOnce保存开机启动程序。 Call RegCreateKey(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\RunOnce", hKey) Call RegSetValueEx(hKey, "zmhh", 0&, REG_SZ, ByVal strRunCmd, Len(strRunCmd) + 1) Call RegCloseKey(hKey) MsgBox "下次开机程序会自动启动" 'End If End Sub
2 添加到注册表中的启动项中
3 把文件复制到c:\底下重命名为explorer.exe
4 ......
估计以上三种方法够用了吧 ^_^
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Public Const REG_SZ = 1
Public Const HKEY_CURRENT_USER = &H80000001
'窗体中的代码
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim hKey As Long
Dim strRunCmd As String
'If UnloadMode = vbAppWindows Then
strRunCmd = 程序路径及名称
'注册表Software\Microsoft\Windows\CurrentVersion\RunOnce保存开机启动程序。
Call RegCreateKey(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\RunOnce", hKey)
Call RegSetValueEx(hKey, "zmhh", 0&, REG_SZ, ByVal strRunCmd, Len(strRunCmd) + 1)
Call RegCloseKey(hKey)
MsgBox "下次开机程序会自动启动"
'End If
End Sub