⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 利用windows的API来注册自动OCX
💻 FRM
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmMain 
   Caption         =   "注册/反注册 OCX DLL TLB"
   ClientHeight    =   3360
   ClientLeft      =   2205
   ClientTop       =   3255
   ClientWidth     =   7650
   ClipControls    =   0   'False
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   3360
   ScaleWidth      =   7650
   Begin VB.CommandButton Command1 
      Caption         =   "注册本目录"
      Height          =   375
      Left            =   6280
      TabIndex        =   5
      Top             =   50
      Width           =   1215
   End
   Begin MSComDlg.CommonDialog cdl 
      Left            =   5520
      Top             =   1800
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.ListBox List1 
      Height          =   2400
      Left            =   120
      TabIndex        =   4
      Top             =   840
      Width           =   7335
   End
   Begin VB.OptionButton op 
      Caption         =   "反注册(&U)"
      Height          =   180
      Index           =   1
      Left            =   2520
      TabIndex        =   3
      Top             =   120
      Width           =   1215
   End
   Begin VB.OptionButton op 
      Caption         =   "注册(&R)"
      Height          =   180
      Index           =   0
      Left            =   600
      TabIndex        =   2
      Top             =   120
      Value           =   -1  'True
      Width           =   1095
   End
   Begin VB.TextBox txtPath 
      Height          =   270
      Left            =   120
      TabIndex        =   1
      Top             =   480
      Width           =   6855
   End
   Begin VB.CommandButton cmdFile 
      Caption         =   "..."
      BeginProperty Font 
         Name            =   "System"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   7080
      TabIndex        =   0
      Top             =   420
      Width           =   435
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'
' Brad Martinez, http://www.mvps.org
'
' Demonstrates how to register and unregister type libraries in VB code
'

Private Sub Command1_Click()
Dim sDir As String
sDir = Dir(App.Path & "\*.*")
'sDir = Dir("F:\Public\", vbDirectory)

Do While sDir <> ""
sDir = App.Path & "\" & sDir
'sDir = "F:\Public\" & sDir

DoEvents
            txtPath.Text = sDir
        If op(0).Value Then
            If LCase(Right(sDir, 3)) = "ocx" Or LCase(Right(sDir, 3)) = "dll" Then
                If RegServer(sDir) Then
                    List1.AddItem sDir & "  注册成功!"
                Else
                    List1.AddItem sDir & "  注册失败!"
                End If
            ElseIf LCase(Right(sDir, 3)) = "tlb" Then
                If RegTypelib(sDir) Then
                    List1.AddItem sDir & "  注册成功!"
                Else
                    List1.AddItem sDir & "  注册失败!"
                End If
            End If
        Else
            If LCase(Right(sDir, 3)) = "ocx" Or LCase(Right(sDir, 3)) = "dll" Then
                If UnRegServer(sDir) Then
                    List1.AddItem sDir & "  反注册成功!"
                Else
                    List1.AddItem sDir & "  反注册失败!"
                End If
            ElseIf LCase(Right(sDir, 3)) = "tlb" Then
                If UnregTypelib(sDir) Then
                    List1.AddItem sDir & "  反注册成功!"
                Else
                    List1.AddItem sDir & "  反注册失败!"
                End If
            End If
        End If

sDir = Dir
Debug.Print sDir
Loop
List1.AddItem "注册完毕"
End Sub

Private Sub Form_Load()
  'cmdRegister.Enabled = False
  'cmdUnregister.Enabled = False
End Sub

Private Sub cmdFile_Click()
    With cdl
        
        

        ' 设置过滤条件。
        .Filter = "所有文件 (*.*)|*.*|DLL 文件;OCX 文件;TLB文件|*.dll;*.ocx;*.tlb"
        ' 指定缺省的过滤条件索引。
        .FilterIndex = 2

        ' 此“打开”对话框具有类似于资源管理器的对话框模板,
        ' 支持长文件名和多重选择,并显示“帮助”按钮。
        .Flags = cdlOFNExplorer Or _
                cdlOFNLongNames Or _
                cdlOFNAllowMultiselect Or _
                cdlOFNHelpButton

        ' 显示“打开”对话框。
        .ShowOpen
        If .FileName = "" Then Exit Sub
        Dim strPath As String
        Dim strFileName() As String
        ' 调用GetMultiFiles方法,以获得文件的路径和文件名。
        Call GetMultiFiles(.FileName, strPath, strFileName())
        ' 清除列表框。
        List1.Clear
        ' 将通用对话框返回的文件字符串加入到列表框中。
        'List1.AddItem .FileName
        ' 在列表框中插入一空行。
        'List1.AddItem ""
    End With
    
    Dim i As Integer
    ' 通过下列循环将文件名及其全路径加入到列表框中。
    For i = LBound(strFileName) To UBound(strFileName)
    DoEvents
        txtPath.Text = strPath & "\" & strFileName(i)
        If op(0).Value Then
            If LCase(Right(strPath & "\" & strFileName(i), 3)) = "ocx" Or LCase(Right(strPath & "\" & strFileName(i), 3)) = "dll" Then
                If RegServer(strPath & "\" & strFileName(i)) Then
                    List1.AddItem strPath & "\" & strFileName(i) & "  注册成功!"
                Else
                    List1.AddItem strPath & "\" & strFileName(i) & "  注册失败!"
                End If
            ElseIf LCase(Right(strPath & "\" & strFileName(i), 3)) = "tlb" Then
                If RegTypelib(strPath & "\" & strFileName(i)) Then
                    List1.AddItem strPath & "\" & strFileName(i) & "  注册成功!"
                Else
                    List1.AddItem strPath & "\" & strFileName(i) & "  注册失败!"
                End If
            End If
        Else
            If LCase(Right(strPath & "\" & strFileName(i), 3)) = "ocx" Or LCase(Right(strPath & "\" & strFileName(i), 3)) = "dll" Then
                If UnRegServer(strPath & "\" & strFileName(i)) Then
                    List1.AddItem strPath & "\" & strFileName(i) & "  反注册成功!"
                Else
                    List1.AddItem strPath & "\" & strFileName(i) & "  反注册失败!"
                End If
            ElseIf LCase(Right(strPath & "\" & strFileName(i), 3)) = "tlb" Then
                If UnregTypelib(strPath & "\" & strFileName(i)) Then
                    List1.AddItem strPath & "\" & strFileName(i) & "  反注册成功!"
                Else
                    List1.AddItem strPath & "\" & strFileName(i) & "  反注册失败!"
                End If
            End If
        End If
    Next i
    List1.AddItem "注册完毕"

End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -