一个简单的安装程序
Public Jimbo As Integer
Public ProgramName As String
Private Sub form_load()
LblMain.Caption = "This program will install the files needed on your computer to run your application. Click next to continue..."
Command1.Caption = "Next..."
Me.Caption = "Setup..."
End Sub
Private Sub Command1_Click()
ProgramName = "Program Name"
If Jimbo = 3 Then
Unload Me: End
Else
Jimbo = Jimbo + 1
Select Case Jimbo
Case 1
LblMain.Caption = "This Setup will install " & ProgramName & ".exe and other components. Please click next to continue."
Case 2
Make_Directories
LblMain.Caption = "Click Next to copy the files into the directory 'C:\WillowSeven'"
Copy_Files
EditReg
Case 3
LblMain.Caption = "Setup Complete!": MsgBox "Complete!", , "": Command1.Caption = "Done"
End Select
End If
End Sub
Private Sub EditReg()
'This inserts files into the registry. e.g.
End Sub
Private Sub Copy_Files()
'This is where you put all the file copying Material
ChDir App.Path
FileCopy App.EXEName & ".exe", "C:\Willow seven\Program\" & ProgramName & ".exe"
End Sub
Private Sub Make_Directories()
On Error Resume Next
MkDir "C:\Willow Seven"
MkDir "C:\Willow Seven\Setup"
MkDir "C:\Willow Seven\Dll's"
MkDir "C:\Willow Seven\Ocx's"
MkDir "C:\Willow Seven\Program"
End Sub
利用API创建文件目录
作者:李志东
Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" (ByVal lpPathName As String, lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Sub Main()
'在C盘创建了"VB编程乐园"目录
Call CreateNewDirectory("C:\VB编程乐园")
MsgBox "在C盘创建了 VB编程乐园 目录"
End Sub
Public Sub CreateNewDirectory(NewDirectory As String)
Dim sDirTest As String
Dim SecAttrib As SECURITY_ATTRIBUTES
Dim bSuccess As Boolean
Dim sPath As String
Dim iCounter As Integer
Dim sTempDir As String
Dim iFlag As Integer
iFlag = 0
sPath = NewDirectory
If Right(sPath, Len(sPath)) <> "\" Then
sPath = sPath & "\"
End If