如何做成注册mscomm32.ocx的BAT程序
发布网友
发布时间:2022-04-26 18:55
我来回答
共1个回答
热心网友
时间:2023-10-22 03:22
'看看可不可以,要改一下的,不过思路就是这样的了
Private Sub cmdInstall_Click()
Dim SrcFileName As String
Dim DstFileName As String
Dim ErrStr As String
SrcFileName = App.Path & "\mscomm32.ocx "
DstFileName = "C:\winnt\system32\mscomm32.ocx "
If myCopyFile(SrcFileName, DstFileName, ErrStr) = True Then
ShellExecute hWnd, "open ", "regsvr32.exe ", "mscomm32.ocx ", 0, 0
end if
End Sub
Private Function myCopyFile(ByVal SrcFileName As String, ByVal DstFileName As String, Optional ByRef ErrStr As String) As Boolean
On Error GoTo myErr
Dim fs As Object
Set fs = CreateObject( "Scripting.FileSystemObject ") '创建文件系统对象
If Not fs.FileExists(SrcFileName) Then
Err.Raise "1001 ", , "文件( " & SrcFileName & ")不存在 "
End If
Set fs = CreateObject( "Scripting.FileSystemObject ") '创建文件系统对象
If fs.FileExists(DstFileName) Then
fs.DeleteFile DstFileName, True
End If
fs.CopyFile SrcFileName, DstFileName '复制文件到目标文件夹
myCopyFile = True
Exit Function
myErr:
myCopyFile = False
ErrStr = Err.Description
End Function