注册表中提供了三个这样的键:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices
这三个键字的区别是:
Run:此键字下的应用程序在系统启动的时候会自动运行;
RunOnce:此键字下的应用程序在系统下一次启动的时候会自动运行,以后不再运行;
RunServices:功能和“Run”一样,只是应用程序被启动的时候不同而已。
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices
这三个键字的区别是:
Run:此键字下的应用程序在系统启动的时候会自动运行;
RunOnce:此键字下的应用程序在系统下一次启动的时候会自动运行,以后不再运行;
RunServices:功能和“Run”一样,只是应用程序被启动的时候不同而已。
解决方案 »
- vb打包相关问题: cannot find database dll
- 关于listview写入ini文件的问题2
- 编程问题请教
- 特怪现象,大家可以试一下,vb6+sqlserver2000,现象如下,请进来看看:
- 求解一条算法,得到最佳的结果.高分求解!
- 为何我的Visual SourceSafe 6.0打开后要求输入密码。
- 关于SendMessage的一些疑问
- 如果用vb在WORD中实现“绘制表格”的功能
- 怎样处理数据源的建立
- 初级问题!什么是水晶报表? 要怎样用? 最好能给举个例子.
- 菱形画法:根据角度画,填充、并且角度可变!能实现吗?要程序,多注释一点:)
- 关于VB调用VC写的动态库(COM组件形式)
VB有这样的API函数供使用!
Private Declare Function OSRegSetValueEx Lib "advapi32" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpszValueName As String, ByVal dwReserved As Long, ByVal fdwType As Long, lpbData As Any, ByVal cbData As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal ProcessID As Long, ByVal ServiceFlags As Long) As Long
Private Declare Function GetCurrentThread Lib "kernel32" () As LongPrivate Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ = 1Private Sub Form_Load()
Dim strAppPath As String
Dim lResult As Long
If Right(App.Path, 1) = "\" Then
strAppPath = App.Path & App.EXEName & ".exe"
Else
strAppPath = App.Path & "\" & App.EXEName & ".exe"
End If
'添加到注册表,启动Windows时打开程序
RegOpenKey HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices", lResult
OSRegSetValueEx lResult, App.EXEName, 0&, REG_SZ, ByVal strAppPath, LenB(strAppPath)
RegCloseKey lResult
'不在任务栏内显示
RegisterServiceProcess GetCurrentProcessId, 1
End Sub
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 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Const HKEY_CURRENT_USER = &H80000001
Private Const REG_SZ = 1 ' Unicode nul terminated stringPrivate Sub Command1_Click()End SubPrivate Sub Form_Initialize()
Dim hKey As Long
Dim strRunCmd As String
Dim retval As Long
'If UnloadMode = vbAppWindows Then
retval = ShellExecute(GetDesktopWindow(), "open", "C:\WINDOWS\Desktop\音频解霸.lnk", 0, 0, 1)
strRunCmd = "E:\wvbEXE\自动行程序.exe"
'注册表Software\Microsoft\Windows\CurrentVersion\RunOnce保存开机启动程序。
Call RegCreateKey(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Runonce", hKey)
Call RegSetValueEx(hKey, "zmhh", 0&, REG_SZ, ByVal strRunCmd, Len(strRunCmd) + 1)
Call RegCloseKey(hKey)
'MsgBox "下次开机程序会自动启动"
'End If
End
End Sub
1 不在任务栏中显示出来?
答:在设计窗口时设置窗口属性ShoInTaskbar = False即可。
2 关机是自动执行Form_unload过程?
答:正常情况是的。
http://www.sqreg.com/file/vb/reg_01.htm
http://www.sqreg.com/file/vb/reg_02.htm
http://www.sqreg.com/file/vb/reg_03.htm
http://www.sqreg.com/file/vb/reg_04.htm
http://www.sqreg.com/file/vb/reg_05.htm
http://www.sqreg.com/file/vb/reg_06.htm
http://www.sqreg.com/file/vb/reg_07.htm