简单问题!马上给分
zjzty 2004-03-08 03:35:15 我写了一个程序!现在要求这个程序开机时自动运行!(要求用写注册表的方式)
我有了写注册表的代码如下,可是这段代码应该怎么执行啊!我希望在安装我的程序的时候执行下面的程序!应该怎么做啊 谢谢
Private Declare Function RegCreateKey& Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey&, ByVal lpszSubKey$, lphKey&)
Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_SZ = 1
'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
Public Function AutoRun() As Boolean
'声明变量
Dim sKeyName As String, sKeyValue As String, sKeyValueIcon As String
Dim Ret As Integer, lphKey As Long
On Error GoTo errHandle
sKeyName = "Software\Microsoft\Windows\CurrentVersion\Run"
sKeyValue = "你的应用程序路径及应用程序名称"
Ret = RegCreateKey&(HKEY_LOCAL_MACHINE, sKeyName, lphKey)
Ret = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)
AutoRun = True
Exit Function
errHandle:
AutoRun = False
End Function