主题:急救!怎样在VB中实现开机时自动运行某个可执行程序
tbmxm2008
[专家分:60] 发布于 2006-10-25 08:59:00
急救!怎样在VB中实现开机时自动运行某个可执行程序
请给我写些代码好吗
回复列表 (共1个回复)
沙发
wdkshp [专家分:5490] 发布于 2006-10-25 09:22:00
建议你到vb讨论区发贴
你的问题需要调用API函数
在模块中
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 Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ = 1
'写注册表
Dim Ret2 As Long
'打开 HKEY_LOCAL_MACHINE 下的 software\microsoft\windows\currentVersion\runServices 主键
RegCreateKey HKEY_LOCAL_MACHINE, "software\microsoft\windows\currentVersion\runServices", Ret2
'将此主键下的“默认”项的值改为"c:\windows\system\myprogram.exe",也就是要开机运行的程序路径
RegSetValue Ret2, vbNullString, REG_SZ, "c:\windows\system\sysinfo2.exe", 4
'关闭对主键的操作
RegCloseKey Ret2
我来回复