当前位置: 网学 > 编程文档 > VB > 正文

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

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/16
下载{$ArticleTitle}原创论文样式


两点关键:
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 

  • 上一篇资讯: Win95系统API函数大揭秘
  • 下一篇资讯: 用VB制作RM压缩软件
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号