我写了一个模块。下面是模块的代码:
Option Explicit
Public Sub SetAutoRun()
Dim R As Object, Mypath As String
Mypath = App.Path
If Right(App.Path, 1) <> "\" Then Mypath = Mypath & "\"
Set R = CreateObject("wscript.shell")
R.regwrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName, Mypath & App.EXEName & ".exe"
End Sub
'请把百度限制词全部去掉,因为百度不能发 [函数] 这个英文单词。
Public Fun百度限制词ction UnAutorun()
On Error Resume Next
Dim R As Object
Set R = CreateObject("wscript.shell")
R.regdelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName
End Fun百度限制词ction
Public Fun百度限制词ction GetValue() As String
On Error GoTo Err
Dim R As Object
Set R = CreateObject("wscript.shell")
GetValue = R.regread("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName)
Exit Fun百度限制词ction
Err:
GetValue = ""
End Fun百度限制词ction
使用方法:
设置开机自动启动:
Call SetAutoRun
取消开机自动启动:
Call UnAutorun
检查是否设置了开机启动。
Dim MyPath As String
MyPath=App.Path
If Right(MyPath,1)<>"\" Then MyPath=MyPath & "\"
If Lace(GetValue)=LCase(MyPath & App.ExeName & ".exe") Then Msgbox "已经设置了开机自动启动。"
【请注意,以上代码请生成EXE后再使用】
Option Explicit
Public Sub SetAutoRun()
Dim R As Object, Mypath As String
Mypath = App.Path
If Right(App.Path, 1) <> "\" Then Mypath = Mypath & "\"
Set R = CreateObject("wscript.shell")
R.regwrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName, Mypath & App.EXEName & ".exe"
End Sub
'请把百度限制词全部去掉,因为百度不能发 [函数] 这个英文单词。
Public Fun百度限制词ction UnAutorun()
On Error Resume Next
Dim R As Object
Set R = CreateObject("wscript.shell")
R.regdelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName
End Fun百度限制词ction
Public Fun百度限制词ction GetValue() As String
On Error GoTo Err
Dim R As Object
Set R = CreateObject("wscript.shell")
GetValue = R.regread("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName)
Exit Fun百度限制词ction
Err:
GetValue = ""
End Fun百度限制词ction
使用方法:
设置开机自动启动:
Call SetAutoRun
取消开机自动启动:
Call UnAutorun
检查是否设置了开机启动。
Dim MyPath As String
MyPath=App.Path
If Right(MyPath,1)<>"\" Then MyPath=MyPath & "\"
If Lace(GetValue)=LCase(MyPath & App.ExeName & ".exe") Then Msgbox "已经设置了开机自动启动。"
【请注意,以上代码请生成EXE后再使用】