以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- VB6管理员模式注册COM DLL和控件,反注册,VB.NET也可参考 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=186657) |
-- 作者:软件开发订做 -- 发布时间:2023/5/17 21:23:00 -- VB6管理员模式注册COM DLL和控件,反注册,VB.NET也可参考 VB6管理员模式注册COM DLL和控件,反注册,VB.NET也可参考 有的电脑管理员权限比较高,就自已写个REGSVR32一样的软件来自动注册,或使用VBS,BAT提权后注册。 最好的方法还是使用免注册加载Activex对象的方法。 64位VBA免注册调用32位COM DLL的问题 https://club.excelhome.net/thread-1662929-1-1.html RegComDll App.Path & "\\32_MFCActiveXControl1.ocx" \'reg x64 com dll RegComDll App.Path & "\\64_MFCActiveXControl1.ocx", False ’反注册DLL RegComDll App.Path & "\\32_MFCActiveXControl1.ocx", , True 代码: Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long Private Declare Function GetCurrentProcess Lib "kernel32" () As Long Private Declare Function IsWow64Process Lib "kernel32" (ByVal hProc As Long, bWow64Process As Boolean) As Long Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _ ByVal hWnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long Const SW_SHOWNORMAL = 1 Public Function Is64bit() As Boolean Dim handle As Long, bolFunc As Boolean bolFunc = False handle = GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process") If handle > 0 Then IsWow64Process GetCurrentProcess(), bolFunc End If Is64bit = bolFunc End Function Function RegComDll(DllFile As String, Optional For32Bit As Boolean = True, Optional UnRegComDLL As Boolean) ShellExecute 0, "runas", "C:\\Windows\\" & IIf(Is64bit And For32Bit, "SysWOW64", "system32") & "\\regsvr32.exe", Chr(34) & DllFile & Chr(34) & IIf(UnRegComDLL, " /U", ""), vbNullString, SW_SHOWNORMAL End Function Function RegsvrComDll(DllFile As String, Optional For32BitDll As Boolean = True, Optional UnRegComDLL As Boolean) Dim Path1 As String Path1 = "system32" If Is64bit And For32BitDll Then Path1 = "SysWOW64" ShellExecute 0, "runas", "C:\\Windows\\" & Path1 & "\\regsvr32.exe", Chr(34) & DllFile & Chr(34) & IIf(UnRegComDLL, " /U", ""), vbNullString, SW_SHOWNORMAL End Function |