Jump to content

Recommended Posts

Posted

I want to register DLL file from AutoIt script.

I know I can do it easily by using regsvr32.exe utility from DOS command which can be launched from AutoIt script.

Any help would be much appreciated.

Tan

Posted

  TanBandradi said:

I want to register DLL file from AutoIt script.

I know I can do it easily by using regsvr32.exe utility from DOS command which can be launched from AutoIt script.

Any help would be much appreciated.

Tan

I am not sure what help you need but just use the /s switch with Regsvr32.exe on the DLL file.

RunWait('Regsvr32 /s "' & $DLL & '"')

I am being naughty by using AutoIt3 tags in the AutoItX.dll forum. :)

:P

Posted

  Richard Robertson said:

DllCall wasn't in AutoItX was it?

:)

Uups, I think I posted a wrong topic to this forum, sorry... my mistake.

I thought this forum is related to activex or COM topic.

And I've created the AutoIt script for registering .dll or .ocx by myself.

Cheers,

Posted

  TanBandradi said:

:)

Uups, I think I posted a wrong topic to this forum, sorry... my mistake.

I thought this forum is related to activex or COM topic.

And I've created the AutoIt script for registering .dll or .ocx by myself.

Cheers,

Care to share?

Posted

  kemikelx said:

Care to share?

Oh, yes indeed.

Sorry for the late reply.

You need Auto3Lib UDF, I think it is available somewhere for download in this forum.

CODE
;

UDF requirements

#include <A3LWinAPI.au3>

Global Const $WAIT_ABANDONED = 128

Global Const $WAIT_OBJECT_0 = 0

Global Const $WAIT_TIMEOUT = 258

Global Const $WAIT_FAILED = -1

Global Const $STILL_ACTIVE = 259

; ****************************************************************************************************

;

; Function name : _API_GetProcAddress

; Description : retrieves the address of an exported function or variable from the specified dynamic-link library (DLL)

; Parameter(s) : $hModule - a handle to the DLL module that contains the function or variable (the LoadLibrary or GetModuleHandle function returns this handle)

; $lpProcName - the function or variable name, or the function's ordinal value

; Requirement(s) : (none)

; Return value(s) : If the function succeeds, the return value is the address of the exported function or variable. If the function fails, the return value is NULL.

; To get extended error information, call _API_GetLastError() (required #include <A3LWinAPI.au3>)

; Author(s) : Tan Bandradi © 2007

;

Func _API_GetProcAddress($hModule, $lpProcName)

Local $aResult

$aResult = DllCall("kernel32.dll", "long", "GetProcAddress", "long", $hModule, "str", $lpProcName)

Return $aResult[0]

EndFunc

; ****************************************************************************************************

;

; Function name : _API_CreateThread

; Description : creates a thread to execute within the virtual address space of the calling process

; Parameter(s) : $pThreadAttributes - a pointer to a SECURITY_ATTRIBUTES structure (refer to http://msdn2.microsoft.com/en-us/library/aa379560.aspx)

; that determines whether the returned handle can be inherited by child processes. If lpThreadAttributes is NULL, the handle cannot be inherited

; $dwStackSize - the initial size of the stack, in bytes. The system rounds this value to the nearest page. If this parameter is zero,

; the new thread uses the default size for the executable.

; $pStartAddress - a pointer to the application-defined function to be executed by the thread and represents the starting address of the thread

; $pParameter - a pointer to a variable to be passed to the thread

; $dwCreationFlags - the flags that control the creation of the thread. If this value is zero, the thread runs immediately after creation

; $pThreadID - a pointer to a variable that receives the thread identifier. If this parameter is NULL, the thread identifier is not returned

; Requirement(s) : (none)

; Return value(s) : If the function succeeds, the return value is a handle to the new thread. If the function fails, the return value is NULL.

; To get extended error information, call _API_GetLastError() (required #include <A3LWinAPI.au3>)

; Author(s) : Tan Bandradi © 2007

;

Func _API_CreateThread($pThreadAttributes, $dwStackSize, $pStartAddress, $pParameter, $dwCreationFlags, $pThreadID)

Local $aResult

$aResult = DllCall("kernel32.dll", "long", "CreateThread", "long", $pThreadAttributes, "long", $dwStackSize, "long", $pStartAddress, "long", $pParameter, _

"long", $dwCreationFlags, "long", $pThreadID)

Return $aResult[0]

EndFunc

; ****************************************************************************************************

;

; Function name : _API_WaitForSingleObject

; Description : waits until the specified object is in the signaled state or the time-out interval elapses

; Parameter(s) : $hHandle - a handle to the object. If this handle is closed while the wait is still pending, the function's behavior is undefined.

; $dwMilliseconds - the time-out interval, in milliseconds. The function returns if the interval elapses, even if the object's state is nonsignaled.

; If $dwMilliseconds is zero, the function tests the object's state and returns immediately.

; Requirement(s) : (none)

; Return value(s) : If the function succeeds, the return value indicates the event that caused the function to return.

; It can be one of the following values:

; $WAIT_ABANDONED - the specified object is a mutex object that was not released by the thread that owned

; the mutex object before the owning thread terminated. Ownership of the mutex object is granted to the calling thread,

; and the mutex is set to nonsignaled.

; $WAIT_OBJECT_0 - the state of the specified object is signaled

; $WAIT_TIMEOUT - the time-out interval elapsed, and the object's state is nonsignaled

; If the function fails, the return value is $WAIT_FAILED

; To get extended error information, call _API_GetLastError() (required #include <A3LWinAPI.au3>)

; Author(s) : Tan Bandradi © 2007

;

Func _API_WaitForSingleObject($hHandle, $dwMilliseconds)

Local $aResult

$aResult = DllCall("kernel32.dll", "long", "WaitForSingleObject", "long", $hHandle, "long", $dwMilliseconds)

Return $aResult[0]

EndFunc

; ****************************************************************************************************

;

; Function name : _API_GetExitCodeThread

; Description : retrieves the termination status of the specified thread

; Parameter(s) : $hThread - a handle to the thread

; $pExitCode - a pointer to a variable to receive the thread termination status. If the specified thread has not terminated and the function succeeds,

; the termination status returned is $STILL_ACTIVE

; Requirement(s) : (none)

; Return value(s) : If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.

; To get extended error information, call _API_GetLastError() (required #include <A3LWinAPI.au3>)

; Author(s) : Tan Bandradi © 2007

;

Func _API_GetExitCodeThread($hThread, $pExitCode)

Local $aResult

$aResult = DllCall("kernel32.dll", "long", "GetExitCodeThread", "long", $hThread, "long", $pExitCode)

Return $aResult[0]

EndFunc

; ****************************************************************************************************

;

; Function name : _API_ExitThread

; Description : ends the calling thread

; Parameter(s) : $dwExitCode - the exit code for the thread

; Requirement(s) : (none)

; Return value(s) : (none)

; Author(s) : Tan Bandradi © 2007

;

Func _API_ExitThread($dwExitCode)

Local $aResult

$aResult = DllCall("kernel32.dll", "", "ExitThread", "long", $dwExitCode)

EndFunc

; ****************************************************************************************************

;

; Function name : _DLLRegisterServer

; Description : register / unregister dynamic link library file (.dll) or activex control (.ocx)

; Parameter(s) : $dll - the name of .dll or .ocx file

; $register - 'True' to register server (default), 'False' to unregister

; Requirement(s) : <A3LWinAPI.au3>

; Return value(s) : 'True' if successfull

; Author(s) : Tan Bandradi © 2007

;

Func _DLLRegisterServer($dll, $register = True)

Dim $hLib

Dim $pAddress

Dim $pThread, $pThreadId

Dim $waitstate

Dim $pExitCode

$hLib = _API_LoadLibraryEx($dll)

If $hLib = 0 Then Return(False)

If $register Then

$pAddress = _API_GetProcAddress($hLib, "DllRegisterServer")

Else

$pAddress = _API_GetProcAddress($hLib, "DllUnregisterServer")

EndIf

If $pAddress = "" Then

_API_FreeLibrary($hLib)

Return(False)

EndIf

$pThread = _API_CreateThread(0, 0, $pAddress, 0, 0, $pThreadId)

If $pThread = 0 Then

_API_FreeLibrary($hLib)

Return(False)

EndIf

$waitstate = _API_WaitForSingleObject($pThread, 10000)

If $waitstate <> 0 Then

$pExitCode = _API_GetExitCodeThread($pThread, $pExitCode)

_API_ExitThread($pExitCode)

Return(False)

EndIf

_API_CloseHandle($pThread)

_API_FreeLibrary($hLib)

Return(True)

EndFunc

Suggestion and correction are welcome!

Tan

Posted

Why copy paste makes the tabbing disappeared in the code box? Oh, well...

So, what you need is the function _DLLRegisterServer().

For example:

If _DLLRegisterServer("C:\Program Files\AutoIt3\AutoItX\AutoItX3.dll", True) Then
[indent]
ConsoleWrite("AutoItX is successfully registered.")
[/indent]
Else
[indent]
ConsoleWrite("AutoItX is failed to be registered.")
[/indent]

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...