自动开始上次关机时关闭的应用

2008-02-23 06:56:05来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

两点关键:
1 检测是 Windows 关闭引起的 QueryUnload 事件。
2 改写 Software\Microsoft\Windows\CurrentVersion\RunOnce

声明:
Declare Function RegCloseKey Lib "advapi32.dll" Alias "RegCloseKey" (ByVal hKey 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 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.

在主 Form 中增加:

Public Const REG_SZ = 1
Public Const HKEY_CURRENT_USER = &H80000001

Private Sub Form_QueryUnload (Cancel as Integer, UnloadMode as Integer)
Dim hKey As Long
Dim strRunCmd As String
If UnloadMode = VBAppWindows Then
strRunCmd = App.Path & "\" & App.EXEName & ".EXE"
Call RegCreateKey(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\RunOnce", hKey)
Call RegSetValueEx(hKey, "MyApp", 0&, REG_SZ, ByVal strRunCmd, Len(strRunCmd) 1)
Call RegCloseKey(hKey)
Endif
End Sub

上一篇: VB千里行-让程序在后台运行
下一篇: 解决Visual Basic非正常退出一例

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:处理加了密码的MDB文件

下一篇:算法从哪学起