模块代码

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

‘*************************************************************************
‘**函 数 名: SetAutoRun
‘**输 入: ByVal Autorun(Boolean) –
‘**输 出: 无
‘**功能描述: 随WINDOWS自动启动/取消启动模块
‘**全局变量:
‘**调用方法: Call SetAutoRun(True/False)

‘*************************************************************************

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)

 

By binbin

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注