VB如何让程序随开机启动
- 提问者网友:了了无期
- 2021-04-24 19:39
- 五星知识达人网友:封刀令
- 2021-04-24 20:33
这有很多种方法 我就给你介绍种常用的吧 记到给我加分哟
\'*************************************************************************
\'**函 数 名: SetAutoRun
\'**输 入: ByVal Autorun(Boolean) -
\'**输 出: 无
\'**功能描述: 随WINDOWS自动启动/取消启动模块
\'**调用方法: Call SetAutoRun(True/False)
\'*************************************************************************
模块代码
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 Declare Function RegCloseKey Lib \"advapi32.dll\" (ByVal hKey As Long) As Long
Public Declare Function RegDeleteValue Lib \"advapi32.dll\" Alias \"RegDeleteValueA\" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Public Const REG_SZ = 1
Public Const HKEY_LOCAL_MACHINE = &H80000002
模块代码结束
Public Sub SetAutoRun(ByVal Autorun As Boolean)
Dim KeyId As Long
Dim MyexePath As String
Dim regkey As String
MyexePath = App.Path & \"\\\" & App.EXEName & \".exe\" \'获取程序位置
regkey = \"Software\\Microsoft\\Windows\\CurrentVersion\\Run\" \'键值位置变量
Call RegCreateKey(HKEY_LOCAL_MACHINE, regkey, KeyId) \'建立
If Autorun Then
RegSetValueEx KeyId, \"MySoftware\", 0&, REG_SZ, ByVal MyexePath, LenB(MyexePath)
Else
RegDeleteValue KeyId, \"MySoftware\"
End If
RegCloseKey KeyId
End Sub
调用方法
SetAutoRun(ByVal Autorun As Boolean)
- 1楼网友:北城痞子
- 2021-04-24 21:34
回答者: