dll文件的注册与删除
来源:互联网 发布:python 聚合搜索结果 编辑:程序博客网 时间:2024/05/19 02:06
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文件的注册与删除
- 如何注册删除dll文件,以及dll文件的介绍
- DLL ,OCX文件的注册与反注册
- 注册dll的bat文件
- 关于.dll文件的注册,如何注册.dll文件
- 建立注册DLL和反注册DLL文件的快捷方式
- 删除dll文件的方法
- 注册dll文件的方法集合
- DLL文件注册时遇到的麻烦
- 注册控件的方法----即注册.dll文件的方法
- 注册DLL文件
- 如何注册dll文件
- 注册*.dll文件
- 注册dll文件
- 如何注册DLL文件
- windows 注册DLL文件
- 注册DLL文件命令
- dll文件注册
- 2009年12月12日
- Delphi 2010 中的泛型(注:Delphi 2009也含有)
- 数据库字符字转换成数字
- 五子棋
- 并献给所有需要力量的朋友们,当你疲惫时,准备放弃时,看看这个吧
- dll文件的注册与删除
- 网络游戏制作技术(一)
- 把生活按比例变成48小时制!?
- Linux内核的等待队列(转载)
- C# 异步编程
- Ext Grid分页
- 商业周刊(Business Week)去年底发布的:“世界最有影响力的公司”-- 苹果、Google、华为。
- 我最喜欢的神语:Java,C,PHP,C++,Python,JavaScript,ActionScript.
- 网络游戏制作技术(二)—— 消息打包处理部分