我們現在有一個系統很多人用﹐現有需要將其中部分內容用dll文件寫好﹐但如何能讓用戶在不可知的情況下自動注冊?

解决方案 »

  1.   

    Regsvr32使用/s选项可去除提示框
      

  2.   

    shell "regsvr32 /s a.dll"
      

  3.   

    因為你的系統有很多人用,所以你要把.dll文件打包,安裝到每一個用戶,這個文件會自動安裝到 windows\system32下面,這樣做就不用注冊
      

  4.   

    放在程序文件夹下,第一次运行,应该就能自动找到并注册该文件吧
    我用OCX,win2000下测试是可以的
      

  5.   

    Usage: regsvr32 [/u] [/s] [/n] [/i[:cmdline]] dllname
    /u Unregister server
    /s Silent; display no message boxes
    /i Call DllInstall passing it an optional [cmdline]; when used with /u calls dll uninstall
    /n do not call DllRegisterServer; this option must be used with /i
      

  6.   

    将DLL文件与应用程序放置在同一个目录下,就可以不需要注册运行否则,将文件放置在对应的目录下,注意,有些通用文件最好保持其原有位置。利用代码注册可使用SHELL命令
      

  7.   

    参考 X:\Program Files\Microsoft Visual Studio\VB98\Wizards\PDWizard\Setup1
    Declare Function DLLSelfRegister Lib "vb6stkit.dll" (ByVal lpDllName As String) As Integer
    Declare Function RegisterTLB Lib "vb6stkit.dll" (ByVal lpTLBName As String) As Integer
      

  8.   

    '**************************************
    'ActiveX Dll 注册/反注册API全局声明
    '**************************************
    Private Declare Function LoadLibraryRegister Lib "KERNEL32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
    Private Declare Function FreeLibraryRegister Lib "KERNEL32" Alias "FreeLibrary" (ByVal hLibModule As Long) As Long
    Private Declare Function CloseHandle Lib "KERNEL32" (ByVal hObject As Long) As Long
    Private Declare Function GetProcAddressRegister Lib "KERNEL32" Alias "GetProcAddress" (ByVal hModule As Long, ByVal lpProcName As String) As Long
    Private Declare Function CreateThreadForRegister Lib "KERNEL32" Alias "CreateThread" (lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lpparameter As Long, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
    Private Declare Function WaitForSingleObject Lib "KERNEL32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Private Declare Function GetExitCodeThread Lib "KERNEL32" (ByVal hThread As Long, lpExitCode As Long) As Long
    Private Declare Sub ExitThread Lib "KERNEL32" (ByVal dwExitCode As Long)'**************************************
    '模块名: ActiveX Dll 注册/反注册
    '描述:该代码演示怎样在程序中注册和反注册,在regsvr32上自己进行
    '输入Inputs:文件名
    '返回:7 个标志,具体看代码
    '**************************************Option Explicit
    Private Declare Function LoadLibraryRegister Lib "KERNEL32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
    Private Declare Function FreeLibraryRegister Lib "KERNEL32" Alias "FreeLibrary" (ByVal hLibModule As Long) As Long
    Private Declare Function CloseHandle Lib "KERNEL32" (ByVal hObject As Long) As Long
    Private Declare Function GetProcAddressRegister Lib "KERNEL32" Alias "GetProcAddress" (ByVal hModule As Long, ByVal lpProcName As String) As Long
    Private Declare Function CreateThreadForRegister Lib "KERNEL32" Alias "CreateThread" (lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lpparameter As Long, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
    Private Declare Function WaitForSingleObject Lib "KERNEL32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Private Declare Function GetExitCodeThread Lib "KERNEL32" (ByVal hThread As Long, lpExitCode As Long) As Long
    Private Declare Sub ExitThread Lib "KERNEL32" (ByVal dwExitCode As Long)
        Private Const STATUS_WAIT_0 = &H0
        Private Const WAIT_OBJECT_0 = ((STATUS_WAIT_0) + 0)
        Private Const NOERRORS As Long = 0
    Private Enum stRegisterStatus
        stFileCouldNotBeLoadedIntoMemorySpace = 1
        stNotAValidActiveXComponent = 2
        stActiveXComponentRegistrationFailed = 3
        stActiveXComponentRegistrationSuccessful = 4
        stActiveXComponentUnRegisterSuccessful = 5
        stActiveXComponentUnRegistrationFailed = 6
        stNoFileProvided = 7
    End Enum
    Public Function Register(ByVal p_sFileName As String) As Variant
        Dim lLib As Long
        Dim lProcAddress As Long
        Dim lThreadID As Long
        Dim lSuccess As Long
        Dim lExitCode As Long
        Dim lThreadHandle As Long
        Dim lRet As Long
        On Error GoTo ErrorHandler
        If lRet = NOERRORS Then
            If p_sFileName = "" Then
                lRet = stNoFileProvided
            End If
        End If
        If lRet = NOERRORS Then
            lLib = LoadLibraryRegister(p_sFileName)
            If lLib = 0 Then
                lRet = stFileCouldNotBeLoadedIntoMemorySpace
            End If
        End If
        If lRet = NOERRORS Then
            lProcAddress = GetProcAddressRegister(lLib, "DllRegisterServer")
            If lProcAddress = 0 Then
                lRet = stNotAValidActiveXComponent
            Else
                lThreadHandle = CreateThreadForRegister(0, 0, lProcAddress, 0, 0, lThreadID)
                If lThreadHandle <> 0 Then
                    lSuccess = (WaitForSingleObject(lThreadHandle, 10000) = WAIT_OBJECT_0)
                    If lSuccess = 0 Then
                        Call GetExitCodeThread(lThreadHandle, lExitCode)
                        Call ExitThread(lExitCode)
                        lRet = stActiveXComponentRegistrationFailed
                    Else
                        lRet = stActiveXComponentRegistrationSuccessful
                    End If
                End If
            End If
        End If
        ExitRoutine:
        Register = lRet
        If lThreadHandle <> 0 Then
            Call CloseHandle(lThreadHandle)
        End If
        If lLib <> 0 Then
            Call FreeLibraryRegister(lLib)
        End If
        Exit Function
        ErrorHandler:
        lRet = Err.Number
        GoTo ExitRoutine
    End Function
    Public Function UnRegister(ByVal p_sFileName As String) As Variant
        Dim lLib As Long
        Dim lProcAddress As Long
        Dim lThreadID As Long
        Dim lSuccess As Long
        Dim lExitCode As Long
        Dim lThreadHandle As Long
        Dim lRet As Long
        On Error GoTo ErrorHandler
        If lRet = NOERRORS Then
            If p_sFileName = "" Then
                lRet = stNoFileProvided
            End If
        End If
        If lRet = NOERRORS Then
            lLib = LoadLibraryRegister(p_sFileName)
            If lLib = 0 Then
                lRet = stFileCouldNotBeLoadedIntoMemorySpace
            End If
        End If
        If lRet = NOERRORS Then
            lProcAddress = GetProcAddressRegister(lLib, "DllUnregisterServer")
            If lProcAddress = 0 Then
                lRet = stNotAValidActiveXComponent
            Else
                lThreadHandle = CreateThreadForRegister(0, 0, lProcAddress, 0, 0, lThreadID)
                If lThreadHandle <> 0 Then
                    lSuccess = (WaitForSingleObject(lThreadHandle, 10000) = WAIT_OBJECT_0)
                    If lSuccess = 0 Then
                        Call GetExitCodeThread(lThreadHandle, lExitCode)
                        Call ExitThread(lExitCode)
                        lRet = stActiveXComponentUnRegistrationFailed
                    Else
                        lRet = stActiveXComponentUnRegisterSuccessful
                    End If
                End If
            End If
        End If
        ExitRoutine:
        UnRegister = lRet
        If lThreadHandle <> 0 Then
            Call CloseHandle(lThreadHandle)
        End If
        If lLib <> 0 Then
            Call FreeLibraryRegister(lLib)
        End If
        Exit Function
        ErrorHandler:
        lRet = Err.Number
        GoTo ExitRoutine
    End Function
      

  9.   

    这样做好像没什么意义,做个安装程序你所用的DLL都会自动注册了,就算要限制某些功能直接通过权限设置就可以了.