VB中如何让程序开机启动?

VB中如何让程序开机启动?,第1张

启动程序如下所示。

1:一种就是在安装软体时往注册表里添加,一种简单粗暴写个快捷方式丢到启动目录里,可以在安装软体时写个脚本bat解决。

2:以在注猜衡册表里添加启动项,前提前亩是有足够的权限,也可以创建一个快捷方式放在startup目录中,也也可以把程序注册成windows 服务, 运行方式为auto。慧兆森

3:vb中写一个代码让电脑一开机程序就运行Private Sub Form_Load() Set w = CreateObject("wscript.shell")w.regwrite"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" &App.EXEName, App.Path &"\" &App.EXEName &".exe"End Sub。

给你提供我用到的代厅迅码:\x0d\x0a'初始化全局变量\x0d\x0aOption Explicit\x0d\x0aPublic pathini As String\x0d\x0aPublic mark As Integer '控制是否族芹自启动的标志变量(1自启动,0不自启动)\x0d\x0a'添加删除兆伏毕自启动项目的API函数声明\x0d\x0aPublic Const HKEY_CLASSES_ROOT = &H80000000\x0d\x0aPublic Const HKEY_CURRENT_USER = &H80000001\x0d\x0aPublic Const HKEY_LOCAL_MACHINE = &H80000002\x0d\x0aPublic Const HKEY_USERS = &H80000003\x0d\x0aPublic Const HKEY_PERFORMANCE_DATA = &H80000004\x0d\x0aPublic Const HKEY_CURRENT_CONFIG = &H80000005\x0d\x0aPublic Const HKEY_DYN_DATA = &H80000006\x0d\x0aPublic Const REG_NONE = 0\x0d\x0aPublic Const REG_SZ = 1\x0d\x0aPublic Const REG_EXPAND_SZ = 2\x0d\x0aPublic Const REG_BINARY = 3\x0d\x0aPublic Const REG_DWORD = 4\x0d\x0aPublic Const REG_DWORD_BIG_ENDIAN = 5\x0d\x0aPublic Const REG_MULTI_SZ = 7\x0d\x0aDeclare Function RegOpenKey Lib 'advapi32.dll' Alias 'RegOpenKeyA' (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long\x0d\x0aDeclare Function RegCreateKey Lib 'advapi32.dll' Alias 'RegCreateKeyA' (ByVal hKey As Long,ByVal lpSubKey As String, phkResult As Long) As Long\x0d\x0aDeclare Function RegCloseKey Lib 'advapi32.dll' (ByVal hKey As Long) As Long\x0d\x0aDeclare 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\x0d\x0aDeclare 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\x0d\x0aDeclare Function RegDeleteValue Lib 'advapi32.dll' Alias 'RegDeleteValueA' (ByVal hKey As Long, ByVal lpValueName As String) As Long\x0d\x0a'在注册表中添加删除自启动项目的模块\x0d\x0aSub Main()\x0d\x0a' 定义hKey 为句柄变量、SubKey为注册表RUN项目变量、Exe为程序名变量\x0d\x0aDim hKey As Long, SubKey As String, Exe As String\x0d\x0a'将程序设定成随 Windows 启动而启动\x0d\x0a'取程序所在路径,判断是否为根目录并分别加上程序全名并赋值给变量Exe\x0d\x0aIf Right(App.Path, 1) = '\' Then\x0d\x0aExe = App.Path App.EXEName '.exe' ' 根目录情况\x0d\x0aElse: Exe = App.Path '\' App.EXEName '.exe' ' 非根目录情况\x0d\x0aEnd If\x0d\x0aSubKey = 'Software\Microsoft\Windows\CurrentVersion\Run' ' 设置项目\x0d\x0aRegCreateKey HKEY_LOCAL_MACHINE, SubKey, hKey ' 取得句柄\x0d\x0aRegSetValueEx hKey, '时间助手', 0, REG_SZ, ByVal Exe, LenB(StrConv(Exe, vbFromUnicode)) 1 ' 写入键值\x0d\x0aRegCloseKey hKey ' 关闭句柄\x0d\x0aEnd Sub\x0d\x0a自己看吧,很简单的,修改一下就可以用了.

分类: 电脑/网络 >>程序设计 >>其他编程语言

问题描述:

如果要让程式记录启动次数,以及用户可以设置启动等待时间!那么请写出你的初步构思方法,例如需要用到什么函数,什么控件,通过什么来记数,计时,如何让它在系统启动时自动运行等等!

在这里先谢谢了!

解析:

1.记录启动次数:用户savesetting和getsetting语句可以将应用程序配置信息保存在注册中

2.等待时间:可以用Timer控件现实

3.重启系统:用API函数exitWindowsEx

VB声明

Declare Function ExitWindowsEx Lib "user32" Alias "ExitWindowsEx" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

说明

退出windows,并用特定的选项重新启动

返回值

Long,非零表示成功,零表示失败。会设置GetLastError

参数说明:

uFlags 指定下述一个或多个标志(用OR运算符合并到一起)

EWX_FORCE 强迫中止没有响应的进程

EWX_LOGOFF 中止进程,然后注销

EWX_SHUTDOWN 关掉系统电源手歼孙(如果可能的话,ATX电源就可以)

EWX_REBOOT 重新引导系统

EWX_SHUTDOWN 关闭系统

dwReserved Long,保留,设为零

4.在系统启动时自动运行

可以创建一个快捷方式复制到启动菜单中

也可以通过设置注册表中的RUN项来实,以下API可以访问注册

RegCreateKey

VB声明

Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, pResult As Long) As Long

说毕链明

在指定的项下创建一个新项。如指定的项已经存在,那么函数会打开现有的项

RegOpenKey

VB声明

Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, pResult As Long) As Long

说明

打开一个现有的注册表项

RegSetValue

VB声明

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

说明

设置指定项或改配子项的默认值

RegQueryValue

VB声明

Declare Function RegQueryValue Lib "advapi32.dll" Alias "RegQueryValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpValue As String, lpcbValue As Long) As Long

说明

取得指定项或子项的默认(未命名)值

可以在网上找到相关API帮助,自己写吧


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12322709.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存