regsvr32 dllname.dll
regsvr32/u dllname.dll


up


Function RegisterDll(strDllFileName As String, strProgID As String, strClsID As String, Optional bVerify As Boolean = True) As Long
' 函数说明
'     注册 ActiveX DLL。
'     注册校验:如果 strProgID 不为空,则注册后检查 strProgID 对应的 CLSID 是否与 strCLSID 相等,
'     如不相等,则认为未注册成功。
'
' 参数说明
'     strDllFileName    :(in) DLL 文件名,包括路径
'     strProgID         :(in) ProgID,如 "AutoYuanjuanProject.AutoYuejuan"
'     strCLSID          :(in) CLSID,如 "37048527-7337-43A8-A041-18DDA083F9F3"
'     bVerify           :(in) 是否校验注册成功,默认为是
'
' 返回值
'     0 = 正常
'     1 = 程序运行错误
'
' 算法或程序流程
'     1. regsvr32 /s /u .dll
'     2. regsvr32 /s .dll
'     3. CLSIDFromProgID
'     4. StringFromCLSID
'     5. CLSID 的 String 与 strCLSID 比较,如果相同,说明注册成功
   Dim strSystemPath       As String
   Dim strRegsvr32         As String
   Dim strCmdLine          As String
   Dim lnProcess           As Long
   Dim lnProcessID         As Long
   Dim lnExitCode          As Long
   Dim sgStartTimer        As Single
   Dim tClsID              As tp_GUID
   Dim pOLESTR             As Long
   Dim strNewClsID         As String
   Dim lnReturn            As Long
   Dim ln1                 As Long
   
   On Error GoTo err_RegisterDll
   
   ' 取得系统路径
   strSystemPath = String(MAX_PATH, Chr(0))
   lnReturn = GetSystemDirectory(strSystemPath, MAX_PATH)
   If lnReturn > 0 Then
      strSystemPath = Left(strSystemPath, lnReturn)
   Else
      ' 取得系统路径失败
      RegisterDll = 1
      Exit Function
   End If
   If Right(strSystemPath, 1) <> "/" Then strSystemPath = strSystemPath & "/"
   
   ' 计算 regsvr32.exe 的文件名
   strRegsvr32 = strSystemPath & "regsvr32.exe"
   
   ' 注册 DLL
   'strCmdLine = strRegsvr32 & " /s " & strDllFileName
   strCmdLine = strRegsvr32 & " /s """ & strDllFileName & """"
   lnProcessID = Shell(strCmdLine, vbNormalFocus)
   If lnProcessID = 0 Then
      ' 运行失败
      RegisterDll = 1
      Exit Function
   End If
   
   lnProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, lnProcessID)
   If lnProcess <> 0 Then
      sgStartTimer = Timer
      Do
          Call GetExitCodeProcess(lnProcess, lnExitCode)
          DoEvents
          DoEvents
          DoEvents
      Loop While (lnExitCode = STATUS_PENDING) And (Timer - sgStartTimer < 5)    ' 5 秒超时
      CloseHandle lnProcess
      If lnExitCode = STATUS_PENDING Then
         ' regsvr32 运行超时
         RegisterDll = 1
         Exit Function
      End If
   End If
      
   ' 校验注册结果
   If Not bVerify Then
      RegisterDll = 0
      Exit Function
   Else
      ' 计算 CLSIDFromProgID
      If strProgID = "" Then
         ' 不进行 ProgID 与 CLSID 的校验
         RegisterDll = 0
         Exit Function
      End If
      lnReturn = CLSIDFromProgID(StrPtr(strProgID), tClsID)
      If lnReturn <> 0 Then
         ' 运行失败
         RegisterDll = 1
         Exit Function
      End If
      
      ' 计算 StringFromCLSID
      strNewClsID = String(160, Chr(0))
      lnReturn = StringFromCLSID(tClsID, pOLESTR)
      If lnReturn <> 0 Then
         ' 运行失败
         RegisterDll = 1
         Exit Function
      End If
      If GetComString(pOLESTR, 100, strNewClsID) <> 0 Then
         ' 运行失败
         CoTaskMemFree pOLESTR
         RegisterDll = 1
         Exit Function
      End If
      CoTaskMemFree pOLESTR
      
      ' CLSID 的 String 与 strCLSID 比较,如果相同,说明注册成功
      If strNewClsID = strClsID Then
         RegisterDll = 0
         Exit Function
      Else
         RegisterDll = 1
         Exit Function
      End If
   End If
   
err_RegisterDll:
      
   RegisterDll = 1
   
'debug
'MsgBox "err_RegisterDll"
'Err.Clear
'On Error GoTo err_RegisterDll
'Resume Next
End Function
Function UnRegisterDll(strDllFileName As String) As Long
' 函数说明
'     注销 ActiveX DLL
'
' 参数说明
'     strDllFileName    :(in) DLL 文件名,包括路径
'
' 返回值
'     0 = 正常
'     1 = 程序运行错误
'
' 算法或程序流程
'     1 regsvr32 /s /u .dll
   Dim strSystemPath       As String
   Dim strRegsvr32         As String
   Dim strCmdLine          As String
   Dim lnReturn            As Long
   Dim lnProcessID         As Long
   
   On Error GoTo err_UnRegisterDll
   
   ' 取得系统路径
   strSystemPath = String(MAX_PATH, Chr(0))
   lnReturn = GetSystemDirectory(strSystemPath, MAX_PATH)
   If lnReturn > 0 Then
      strSystemPath = Left(strSystemPath, lnReturn)
   Else
      ' 取得系统路径失败
      UnRegisterDll = 1
      Exit Function
   End If
   If Right(strSystemPath, 1) <> "/" Then strSystemPath = strSystemPath & "/"
   
   ' 计算 regsvr32.exe 的文件名
   strRegsvr32 = strSystemPath & "regsvr32.exe"
   
   ' 注销 DLL
   strCmdLine = strRegsvr32 & " /s /u " & strDllFileName
   lnProcessID = Shell(strCmdLine, vbNormalFocus)
   If lnProcessID = 0 Then
      ' 运行失败
      UnRegisterDll = 1
      Exit Function
   End If
      
   UnRegisterDll = 0
   Exit Function
   
err_UnRegisterDll:
   UnRegisterDll = 1
   
End Function

dll文件的注册与删除相关推荐

  1. Setup Factory打包时实现第三方DLL文件的注册

    Setup Factory中的如下界面: 红色矩形中的仅仅是用来测试该文件是否是能注册的组件或ocx控件,在安装包安装过程中并不会注册该组件,如需注册,必须按下面步骤进行: 1: 先将需要注册的组件所 ...

  2. .OCX、.dll文件注册命令Regsvr32的使用

    1.打开文件,打开需要注册的OCX文件或dll文件, 2.然后根据需要进行OCX文件或DLL文件的注册和反注册 DLL.OCX注册方法--文件Regsvr32用法及情况介绍 使用过activex的人都 ...

  3. 关于在Windows10上删除.dll文件的方法

    DLL文件是库文件,是我们软件运行时的必备文件,但是在有的时候我们删除了安装的软件,相对应的软件的DLL文件有可能没有删除,这里就分享一下删除DLL文件的方法. 1.按win+r键,会出现如下的界面: ...

  4. 注册修复动态链接库DLL文件

    所有DLL 文件一般都在system32 目录下,如果能把system32 目录下所有DLL 文件都注册一下,那么不就可以解决大多数由DLL 文件引起的问题了吗?怎么才能3秒钟找到DLL文件的&quo ...

  5. 解决无法删除的dll文件

    很多时候我们删不了一些文件其实就是因为里面有一些dll在运行,那么怎么定位这些dll的服务并且关闭这些服务呢?下面我们就一起来解决这个问题. 在运行里输入cmd进入命令提示符.        然后输入 ...

  6. DLL文件无法删除怎么解决

    dll文件你听说过吗?那怎样把那些删不掉的东西删掉呢?请看.... 老听网友说某某文件删不掉啊.之类的.而且有很多都是dll文件.删除的时候总是提示,"正在使用"或者是" ...

  7. regsvr32.exe进程注册dll文件

    regsvr32.exe用于注册Windows操作系统的动态链接库(dll)和ActiveX控件.这个程序对你系统的正常运行是非常重要的.   dll文件即动态链接库,是一个不可执行的二进制程序文件, ...

  8. 如何注册全部DLL文件以及DLL简要说明

    将您下载的 "*. DLL" 文件复制到 "C:\Windows\system32\" 系统目录下然后按 "Win键+R" 或单击 &quo ...

  9. 重新注册系统所有dll文件

    当开机dll文件报错时没有什么好的解决方案的时候,就重新注册system32下的dll文件就好了. 如何一下把所有的dll文件重新注册一遍呢?其实很简单! (1)开始-运行:输入cmd,按" ...

最新文章

  1. Noip2012同余方程
  2. python安装虚拟环境没有activate_Python venv虚拟环境:Activate命令的作用
  3. MFC模态窗口与非模态窗口
  4. css列表格式属性,css list-style-type属性笔记
  5. kusto使用_Python查找具有数据重复问题的Kusto表
  6. 阿里云 Aliplayer高级功能介绍(九):自动播放体验
  7. nio2 java_java nio2
  8. Mybatis 控制台打出Sql-Log的设置
  9. 图标透明,产生的EXE图标不透明
  10. 偏微分方程数值解法pdf_数值模拟偏微分方程的三种方法:FDM、FEM及FVM
  11. 浅谈新一代PGIS技术在智慧消防中的创新应用
  12. 下载excel打开后弹出警告提示,文件类型和文件内容不符问题处理
  13. 教你用电脑键盘打出“囍”字
  14. 教你计算个人所得税(企业员工)
  15. React实现(Web端)网易云音乐项目(四),错过了真的可惜呀
  16. PMP学习笔记:采购合同类型
  17. Linux下DES安全通信编程
  18. git多个commitId 合并成一个
  19. MacOS 开发 — 读取文件/视频 信息
  20. 微软 Windows 网络邻居

热门文章

  1. 操作系统基本功能(操作系统)
  2. 深度学习,NLP和表征(译:小巫)
  3. Python3,20行代码,通过微信电脑版爬取朋友圈数据,老板再也抓不到我上班看手机了!!!
  4. 【Windows】多显示器拔出HDMI接口线后应用界面丢失问题
  5. 我们是如何改进YOLOv3进行红外小目标检测的?
  6. 如何用css3制作一个旋转的立方体
  7. 09. 软件测试工程师的核心竞争力是什么
  8. Casbin 账号密码泄漏漏洞
  9. 杰瑞学Perl之多值比较问题
  10. Java获取Prometheus监控指标数据