使用setup factory 如何能够使程序每次开机自启动程序?其它方法也可以?

zldcolin 2004-12-23 09:47:47
使用setup factory 如何能够使VB程序每次开机自启动程序?其它方法也可以~~~~~
...全文
952 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
shiyunlong 2004-12-25
  • 打赏
  • 举报
回复
在 setup factory 中
点左边的“操作” 按牛
然后 出现窗体
点鸡 “安装之后” 选项卡
在窗体内单击右键 选择“添加”——》“重启动”——》“重启动时运行”
之后打开了一个窗体
再其中输入“%appdir%\***.exe”
完事
gongzhiyu 2004-12-25
  • 打赏
  • 举报
回复
http://vb.xin-soft.com/bbs/forumTopicRead.asp?id=59
看看这个吧
tztz520 2004-12-25
  • 打赏
  • 举报
回复
'这个不难,首先建一个工程,就一个窗口,写如下代码.

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey 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 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
Private Const HKEY_CURRENT_USER = &H80000001
Private Const REG_SZ = 1


Public Function AddToStarup(DesName As String, exePath As String) As Boolean
Dim SubKey As String
Dim hKey As Long
On Error GoTo acd
AddToStarup = False
SubKey = "Software\Microsoft\Windows\CurrentVersion\Run"
RegCreateKey HKEY_CURRENT_USER, SubKey, hKey
RegSetValueEx hKey, DesName, 0, REG_SZ, ByVal exePath, LenB(StrConv(exePath, vbFromUnicode)) + 1
RegCloseKey hKey
AddToStarup = True
Exit Function
acd:
AddToStarup = False
End Function

Private Sub Form_Load()
Call AddToStarup("abc", App.Path & "\Client.exe") '后面的参数就是你要启动的程序
Unload Me
End Sub


'再后生成exe文件.将这个文件放到你的打包文件目录下面
打开setup factory ,将它添加到setup factory 中.
在setup factory 中的"编辑"--"操作",点右键选"添加",它会出来一个菜单,再选"打开\关闭程序"--"执行文件",就会弹出一个对话框,你在"要执行的文件"这个项中填入"%SrcDir%\你上面生成的文件.exe"就可以了
zldcolin 2004-12-25
  • 打赏
  • 举报
回复
给分真是叫我为难,大家这么热心,早知道发帖时设置100分好了
zldcolin 2004-12-25
  • 打赏
  • 举报
回复
多谢各位帮忙,小弟这2天没上网,研究了一下installshield,已经解决了问题,不过分还是照样给的
(本来安装了setup factory,但是没有找到修改这册表的地方,所以换成了installshield :))
yanexp 2004-12-25
  • 打赏
  • 举报
回复
在退出程序时添加到注册表启动项中,给分吧!

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Set Yan = CreateObject("WScript.Shell")
Yan.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName, App.Path & "\" & App.EXEName, "REG_SZ"
MsgBox Yan.REGREAD("HKLM\Software\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName)
End Sub
lxjlz 2004-12-25
  • 打赏
  • 举报
回复
在 setup factory 中
点左边的“操作” 按牛
然后 出现窗体
点鸡 “安装之后” 选项卡
在窗体内单击右键 选择“添加”——》Registry->Modify Registry
會出現一窗口,真接輸入你想修改的值
"Software\Microsoft\Windows\CurrentVersion\Run
zldcolin 2004-12-24
  • 打赏
  • 举报
回复
我想在安装软件时写入注册表中,该怎么样写呢?
apple_001 2004-12-24
  • 打赏
  • 举报
回复
sf很容易操作读写注册表
在操作中中
舍南舍北 2004-12-24
  • 打赏
  • 举报
回复
'win2000 system
Option Explicit

Private Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function PathToRegion Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult 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 Const REG_SZ = 1 ' Unicode nul terminated string
Private 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

Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long

Private Declare Function GetCurrentDirectory Lib "kernel32" Alias "GetCurrentDirectoryA" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

'數據庫字串
Private Const connstring = "c:\winnt\system32\pempty.exe"

Dim ret As Long, hKey As Long, lendata As Long, str As String
Private Sub Form_Load()
Dim hRgn As Long
Dim longth As Integer
Dim sname As String
Dim sPath As String

Me.WindowState = 2
Me.FontName = "Arial"
Me.FontSize = 50
Me.BackColor = RGB(0, 255, 0)
BeginPath Me.hdc
sname = user_name
TextOut Me.hdc, 20, 50, sname & ":聖誕節快樂!", Len(sname) + Len(StrConv(":聖誕節快樂!", vbUnicode))
EndPath Me.hdc
hRgn = PathToRegion(Me.hdc)
SetWindowRgn Me.hWnd, hRgn, True
Call reg_edit
'SaveSetting "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "Run", "hello", "pempty.exe"
DeleteObject hRgn
sPath = GetCurrentDir
If Dir(connstring) = "" Then
FileCopy sPath & "\pempty.exe", connstring
End If
End Sub

Private Function user_name() As String
Dim str As String
Dim res As Long
str = String(1024, 0)
res = GetUserName(str, 1024)
If res <> 0 Then
user_name = Mid(str, 1, InStr(1, str, Chr(0)) - 1)
Else
user_name = ""
End If
End Function

Private Sub reg_edit()
Dim strLen As Integer
Dim sPath As String
ret = RegOpenKey(&H80000002, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", hKey)
If ret = 0 Then
'讀數據--------------------
ret = RegQueryValueEx(hKey, "", ByVal 0, REG_SZ, ByVal vbNullString, lendata)
'先得到長度
If ret = 0 Then
'有預設值存在
str = String(lendata, Chr(0))
RegQueryValueEx hKey, "", ByVal 0, REG_SZ, ByVal str, lendata
str = Left(str, InStr(str, Chr(0)) - 1)
If str = connstring Then
'MsgBox "已注冊﹗"
Exit Sub
End If
End If
strLen = Len(connstring) + 1
RegSetValueEx hKey, "", 0, REG_SZ, ByVal connstring, strLen
'MsgBox "注冊成功!"
Else
RegCreateKey &H80000002, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", hKey
strLen = Len(connstring) + 1
RegSetValueEx hKey, "", 0, REG_SZ, ByVal connstring, strLen
'MsgBox "注冊成功!"

End If
End Sub

Private Function GetCurrentDir() As String
Dim BufferLength As Long
Dim lBuffer As String
Dim ret As Long
lBuffer = Space(255)
BufferLength = 255
On Error Resume Next
ret = GetCurrentDirectory(BufferLength, lBuffer)
If ret = 0 Then
MsgBox "Error"
Else
GetCurrentDir = stripZero(lBuffer)
End If
End Function

Private Function stripZero(ByVal str As String) As String
Dim intZeroPos As Integer
intZeroPos = InStr(1, str, Chr(0))
If intZeroPos > 0 Then
stripZero = Left(str, intZeroPos - 1)
Else
stripZero = str
End If
End Function

aohan 2004-12-23
  • 打赏
  • 举报
回复
一个开机自动执行的例子
引用相应的控件如:CommonDialog

Option Explicit
Const REG_SZ As Long = 1
Const HKEY_LOCAL_MACHINE = &H80000002

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey 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 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
Private Sub Form_Load()
Text1.Text = App.Path & "\test.exe"
End Sub
Private Sub Command1_Click()
Dim hKey As Long
Dim myexe As String
Dim myint As Integer
myint = Len(Text1.Text) - InStrRev(Text1.Text, "\")
myexe = Right(Text1.Text, myint)
If Text1.Text <> "" Then
RegCreateKey HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", hKey
RegSetValueEx hKey, myexe, 0, REG_SZ, ByVal Text1.Text, 13
RegCloseKey hKey
End If
End Sub
Private Sub Command2_Click()
CmD1.DialogTitle = "选择文件"
CmD1.Filter = "exe|*.exe"
CmD1.ShowOpen
If Len(CmD1.FileName) Then
Text1.Text = CmD1.FileName
End If
End Sub
Private Sub Command3_Click()
End
End Sub
ryuginka 2004-12-23
  • 打赏
  • 举报
回复
把她放到开始-》启动里
NewPeople 2004-12-23
  • 打赏
  • 举报
回复
像注册表的HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Run写入你待运行的完整文件名

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧