VB开机后 程序自动启动代码

用VB编了一个程序,我想让电脑开机时候这个程序自动启动,请问代码怎么编写?... 用VB编了一个程序,我想让电脑开机时候 这个程序自动启动,请问代码怎么编写? 展开
 我来答
zxlxxl
2008-05-15 · TA获得超过630个赞
知道小有建树答主
回答量:928
采纳率:0%
帮助的人:481万
展开全部
Private Declare Sub Sleep Lib "kernel32"颤塌姿 (ByVal dwMilliseconds As Long)

Private Sub Form_Load()
On Error Resume Next
Shell "cmd /茄绝c reg add HKLM\SOFTWARE\Microsoft\衫盯Windows\CurrentVersion\Run /v Spy /d """ _
& App.Path & "\" & App.EXEName & ".exe", vbNormal
End Sub
Gerald_Bond
2008-05-15 · TA获得超过1003个赞
知道小有建树答主
回答量:590
采纳率:0%
帮助的人:605万
展开全部
'声明部分
Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_SZ = 1
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" _
(ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private 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
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
(ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

'以下为写注册表的语句
Dim sKeyName As String, sKeyValue As String
Dim lphKey As Long, lenData As Long, Ret As Integer
Dim REG_AR As String
sKeyName = "Software\Microsoft\Windows\CurrentVersion\Run"
sKeyValue = """" + AFilePath + App.EXEName + ".exe"""
Ret = RegCreateKey(HKEY_LOCAL_MACHINE, sKeyName, lphKey)
Ret = RegQueryValueEx(lphKey, App.EXEName, 0, vbNull, ByVal vbNullString, lenData)
REG_AR = Space(lenData)
Ret = RegQueryValueEx(lphKey, App.EXEName, 0, vbNull, ByVal REG_AR, lenData)
'判断如果没有写过就写
If REG_AR <> sKeyValue Then RegSetValueEx lphKey, App.EXEName, 0, REG_SZ, ByVal sKeyValue, Len(sKeyValue)

适用于XP但销拍不适用于VISTA系统物斗高。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式