| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 839 人关注过本帖
标题:求助:如何实现程序的自启动
只看楼主 加入收藏
luohao123456
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2007-9-21
收藏
 问题点数:0 回复次数:8 
求助:如何实现程序的自启动

如何通过修改注册表实现自启动啊?
新手上路请多关照!

搜索更多相关主题的帖子: 新手上路 注册表 
2007-10-16 08:33
tanghuawei
Rank: 4
来 自:美丽的湖南
等 级:业余侠客
威 望:3
帖 子:531
专家分:220
注 册:2006-3-16
收藏
得分:0 
你意思是将VB程序开机启动?

汽车尾气检测网络系统QQ:357766186__MSN:MSNTHW19850316@
2007-10-16 08:37
随风逐流
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:passerby
等 级:版主
威 望:8
帖 子:4054
专家分:271
注 册:2007-6-13
收藏
得分:0 

最简单的方法就是把程序复制到启动文件夹里


[url=http://www./html/6/6694/]极道金丹[/url][url=http://www./html/2/2849/]九阴九阳[/url][url=http://www./html/2/2596/]凡人修仙传[/url]
2007-10-16 08:50
luohao123456
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2007-9-21
收藏
得分:0 

是开机启动!

请问启动文件夹在那里?


2007-10-16 09:20
hfox
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2007-9-18
收藏
得分:0 

用超级兔子吧,什么都解决了

2007-10-16 09:32
随风逐流
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:passerby
等 级:版主
威 望:8
帖 子:4054
专家分:271
注 册:2007-6-13
收藏
得分:0 
昏,启动文件夹很容易找到.
你自己找找,我这里是日文系统.

[url=http://www./html/6/6694/]极道金丹[/url][url=http://www./html/2/2849/]九阴九阳[/url][url=http://www./html/2/2596/]凡人修仙传[/url]
2007-10-16 09:39
心中有剑
Rank: 2
等 级:新手上路
威 望:5
帖 子:611
专家分:0
注 册:2007-5-18
收藏
得分:0 
[CODE]

Option Explicit

Public 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

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

Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long

Public Const REG_SZ = 1

Public Const HKEY_LOCAL_MACHINE = &H80000002

'*************************************************************************
'**函 数 名: SetAutoRun
'**输 入: ByVal Autorun(Boolean) -
'**输 出: 无
'**功能描述: 随WINDOWS自动启动/取消启动模块
'**全局变量:
'**调用方法: Call SetAutoRun(True/False)
'**作 者: Mr.David
'**日 期: 2006-09-05 09:07:25
'**修 改 人:
'**日 期:
'**版 本: V1.0.0
'*************************************************************************

Public Sub SetAutoRun(ByVal Autorun As Boolean)

Dim KeyId As Long
Dim MyexePath As String
Dim regkey As String

MyexePath = App.Path & "\" & App.EXEName & ".exe" '获取程序位置

regkey = "Software\Microsoft\Windows\CurrentVersion\Run" '键值位置变量

Call RegCreateKey(HKEY_LOCAL_MACHINE, regkey, KeyId) '建立

If Autorun Then

RegSetValueEx KeyId, "MySoftware", 0&, REG_SZ, ByVal MyexePath, LenB(MyexePath)

Else

RegDeleteValue KeyId, "MySoftware"

End If

RegCloseKey KeyId

End Sub

调用方法

SetAutoRun(ByVal Autorun As Boolean)

[/CODE]

2007-10-16 11:25
心中有剑
Rank: 2
等 级:新手上路
威 望:5
帖 子:611
专家分:0
注 册:2007-5-18
收藏
得分:0 
[CODE]

先引用系统里面都有的WSHom.Ocx

Option Explicit

'*************************************************************************
'**函 数 名: SetAutoRun
'**输 入: ByVal Autorun(Boolean) -
'**输 出: 无
'**功能描述: 随WINDOWS自动启动/取消启动模块
'**全局变量:
'**调用方法: Call SetAutoRun(True/False)
'**作 者: Mr.David
'**日 期: 2006-09-05 09:07:25
'**修 改 人:
'**日 期:
'**版 本: V1.0.0
'*************************************************************************

Public Sub SetAutoRun(ByVal Autorun As Boolean)

'WshShell 对象
'ProgId Wscript.Shell
'文件名 WSHom.Ocx

Dim WshShell As WshShell

Set WshShell = CreateObject("Wscript.Shell")

If Autorun Then

WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName, App.Path & "\" & App.EXEName & ".exe"

Else

WshShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName

End If

Set WshShell = Nothing

End Sub

[/CODE]

2007-10-16 11:26
心中有剑
Rank: 2
等 级:新手上路
威 望:5
帖 子:611
专家分:0
注 册:2007-5-18
收藏
得分:0 
[CODE]

'=====================================
' 注册表的读写 声明
'=====================================
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long ' 关闭RegCreateKey打开的键
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 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 RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" ( _
ByVal hKey As Long, _
ByVal lpSubKey As String) As Long '删除加入的键值

Private Const HKEY_CURRENT_MACHINE = &H80000002
Private Const REG_SZ = 1
'============================
' 添加启动写注册表
'============================
Public Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String)
Dim ret
RegCreateKey hKey, strPath, ret
RegSetValue ret, strValue, REG_SZ, strData, Len(strData)
RegCloseKey ret
End Sub
'===========================
' 删除在注册表的根键
'===========================
Public Sub delKey(hKey As Long, strPath As String, delKey As String)
Dim ret
RegCreateKey hKey, strPath, ret
RegDeleteKey ret, delKey
RegCloseKey ret
End Sub
'============================
' 判断是否加为启动项
'============================
Public Sub makeRun(X As Boolean)
If X Then
SaveString HKEY_CURRENT_MACHINE, _
"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN", _
App.EXEName, App.Path & "\" & App.EXEName & ".exe"
MsgBox "成功加入启动项", , "提示"
Else
delKey HKEY_CURRENT_MACHINE, _
"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN", _
App.EXEName
MsgBox "成功删除启动项", , "提示"
End If
End Sub

Private Sub Command1_Click()
makeRun True
End Sub

Private Sub Command2_Click()
makeRun False
End Sub

[/CODE]

2007-10-16 11:31
快速回复:求助:如何实现程序的自启动
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016645 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved