永发信息网

VB如何让程序随开机启动

答案:2  悬赏:50  手机版
解决时间 2021-04-25 18:25
  • 提问者网友:了了无期
  • 2021-04-24 19:39
VB如何让程序随开机启动 哪位大哥能讲详细点
最佳答案
  • 五星知识达人网友:封刀令
  • 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
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  6

回答者:

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯