方法一:创建快捷方式
Private Sub Command1_Click() Dim str As String Set WshShell = CreateObject("Wscript.shell") str = WshShell.SpecialFolders("Startup") '启动文件夹的路径 If Dir(str & "\vb管理软件.lnk") = "" Then Set oMyShortcut = WshShell.CreateShortcut(str + "\vb管理软件.lnk") oMyShortcut.TargetPath = App.Path & "\" & App.EXEName & ".exe" oMyShortcut.Save End If End Sub
方法二:注册方式
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 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 RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Private Sub Command1_Click() Const HKEY_LOCAL_MACHINE = &H80000002 Const REG_SZ = 1 Dim Ret2 As Long '打开 HKEY_LOCAL_MACHINE 下的 software\microsoft\windows\currentVersion\run RegCreateKey HKEY_LOCAL_MACHINE, "software\microsoft\windows\currentVersion\run", Ret2 '将此主键下的 "默认" 值改为你的 exe 全路径" RegSetValue Ret2, vbNullString, REG_SZ, App.Path & "\" & App.EXEName & ".exe", 4 '关闭对主键的操作 RegCloseKey Ret2 End Sub
转载声明:本站发布文章及版权归原作者所有,转载本站文章请注明文章来源!