当前位置:编程学习 > VB >>

开机运行的VB代码

我想做个运行VB程序后,下次开机就自动打开这个程序,但不知道代码是什么,知道的说下,没有其他目的,用来学习.
补充:我是要添加一个Check1的控件,但用户勾选之后,下次开机就会自动运行了.
答案:
if Check1.Value=True then
Set w = CreateObject("wscript.shell")
w.regwrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName, App.Path & "\" & App.EXEName & ".exe" '导入注册表,实现开机自动运行
end if
设计脚本试试,代码没研究过,你可以上这里找找有不: http://www.mcse.org.cn/showforum-20.html http://www.microsoft.com/china/technet/community/scriptcenter/default.mspx或者将应用程序图标复制,然后在任务栏里打开属性→开始菜单→自定义(经典)→高级→Documents and Settings→Administrator →「开始」菜单→程序→启动,将图标粘贴就行了!下一次开机它就会自动运行你设置的程序!
方法有很多,如果你做的不是一些后门程序
建议用写注册表的方法,比较有保障的方法

'首先声明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
RegCreateKey HKEY_LOCAL_MACHINE, "software\microsoft\windows\currentVersion\runServices", Ret2 '打开主键
RegSetValue Ret2, vbNullString, REG_SZ, App.path & "\" & App.ExeName & ".exe", 4 ‘要运行的程序路径
RegCloseKey Ret2 '关闭操作

上一个:谁能告诉我学编程 是先学VB、C或是JAVA呢英语差学习有限制 易语言感觉学得没啥用 有很大的局限性
下一个:VB的简单问题啊

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,