Per la registrazione/deregistrazione ci sono già riuscito...
I nostri programmi, ora come ora, se non trovano le loro librerie (cioè quelle da noi prodotte) tentano di registrarle automaticamente (e ci riescono). L'utente nemmeno se ne accorge...
Ecco qua il modulo con la funzione RegUnReg:
codice:
Option Explicit
Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" _
(ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _
(ByVal lpLibFileName As String) As Long
Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, _
ByVal lpProcName As String) As Long
Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, _
ByVal dwStackSize As Long, ByVal lpStartAddress As Long, _
ByVal lParameter As Long, ByVal dwCreationFlags As Long, _
lpThreadID As Long) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, _
lpExitCode As Long) As Long
Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode As Long)
Public Enum REGUNREG_RETURNS
RU_REG_OK = 0
RU_UNREG_OK = 1
RU_ERRORE_CARICAMENTO = 2
RU_COMANDO_NON_TROVATO = 3
RU_TIME_OUT = 4
RU_NO_ENTRY_POINT = 5
End Enum
Public Function RegUnReg(ByVal sFile As String, _
Optional sHandle As String = "") As REGUNREG_RETURNS
Dim lLib As Long
Dim lpDLLEntryPoint As Long
Dim lpThreadID As Long
Dim lpExitCode As Long
Dim mThread
Dim mResult
Dim unReg As Boolean
lLib = LoadLibrary(sFile)
If lLib = 0 Then
' //File non esiste o non e' una DLL valida
RegUnReg = RU_ERRORE_CARICAMENTO
Exit Function
End If
If sHandle = "" Then
lpDLLEntryPoint = GetProcAddress(lLib, "DllRegisterServer")
unReg = False
ElseIf sHandle = "U" Or sHandle = "u" Then '//Unregister Server
lpDLLEntryPoint = GetProcAddress(lLib, "DllUnregisterServer")
unReg = True
Else
RegUnReg = RU_COMANDO_NON_TROVATO
'MsgBox "Comando non trovato", vbCritical, "Register Server"
Exit Function
End If
If lpDLLEntryPoint = vbNull Or lpDLLEntryPoint = 0 Then
GoTo Exit1
End If
mThread = CreateThread(ByVal 0, 0, ByVal lpDLLEntryPoint, _
ByVal 0, 0, lpThreadID)
If mThread = 0 Then
GoTo Exit1
End If
mResult = WaitForSingleObject(mThread, 10000)
If mResult <> 0 Then
GoTo Exit2
End If
CloseHandle mThread
FreeLibrary lLib
If unReg = True Then
RegUnReg = RU_UNREG_OK
Else
RegUnReg = RU_REG_OK
End If
Exit Function
Exit1:
'MsgBox "Registrazione fallita EntryPoint mancante" & sFile & ".", _
vbCritical, "Registrazione Fallita!"
RegUnReg = RU_NO_ENTRY_POINT
FreeLibrary lLib
Exit Function
Exit2:
'MsgBox "Registrazione fallita per time-out da " & sFile & ".", _
vbCritical, "Registrazione fallita!"
RegUnReg = RU_TIME_OUT
FreeLibrary lLib
lpExitCode = GetExitCodeThread(mThread, lpExitCode)
ExitThread lpExitCode
End Function
Il codice credo di averlo trovato su visual-basic.it o it-lang-vb.net
e l'ho modificato leggermente.
Se non ti funzia le modifiche da fare credo siano poche...
Have fun!
Ah, ora cerco sto Fusion