VB里怎样写语句使原程序列入开机启动项?
发布网友
发布时间:2023-12-30 16:25
我来回答
共2个回答
热心网友
时间:2024-06-14 01:39
这个问题你可以使用以下的两个办法解决:
1:如果你对windows的注册表非常熟悉的话,你可以使用这个方法
对把程序放入开机启动项的原理你也必须弄的非常的清楚。
所以我给出以下代码,这是一个在一个公共模块中实现的代码段。
关于你愿意在按钮单击事件中实现,你可以稍稍的改动以下代码!!!
Option Explicit
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_DYN_DATA = &H80000006
Public Const REG_NONE = 0
Public Const REG_SZ = 1
Public Const REG_EXPAND_SZ = 2
Public Const REG_BINARY = 3
Public Const REG_DWORD = 4
Public Const REG_DWORD_BIG_ENDIAN = 5
Public Const REG_MULTI_SZ = 7
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
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
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
Sub Main()
Dim hKey As Long, SubKey As String, Exe As String
SubKey = "Software\Microsoft\Windows\CurrentVersion\Run"
Exe = "notepad"
RegCreateKey HKEY_CURRENT_USER, SubKey, hKey
RegSetValueEx hKey, "记事本", 0, REG_SZ, ByVal Exe, _
LenB(StrConv(Exe, vbFromUnicode)) + 1
RegCloseKey hKey
MsgBox "notepad 程序已经被设定成 Windows 启动时自动执行的程序!"
End Sub
2:第二种方法比较的简单:将你的程序拷到启动项里面去:
copy(aa.exe ,启动项目录)
启动项目录对administrator用户是:
C:\Documents and Settings\Administrator\「开始」菜单\程序\启动
对别的用户你可以以此类推。
热心网友
时间:2024-06-14 01:38
关注