I use something like the following to register KiXforms. If the object cannot be created the UDF attempts to use a local copy to register it.

Useful for deploying one-off tools to tech support staff - if they get an error they know that they just need to re-run the script with a privileged account.


$System=initKixForms()
If @ERROR
$=MessageBox("Sorry, you must install KiXForms to use this application. If you run the application as a power user it will automatically install KiXforms","Cannot start KiXForms",0,48)
Exit 0
EndIf


Function initKixForms(Optional $iMode) ; {{{
Dim $sDLL $sDLL="kixforms.dll"
Dim $sResource $sResource=@SCRIPTDIR
Dim $sTarget $sTarget=%SYSTEMROOT%+"\system32\"+$sDLL

$iMode=Val($iMode)

$initKixForms=CreateObject("Kixtart.System")
If @ERROR
Select
Case $iMode=1
Case "Default"
"Attempting KixForms install..."+@CRLF
COPY $sResource+"\"+$sDLL $sTarget
If @ERROR
"Can't copy file - requires elevated privilege"+@CRLF
Else
Shell 'regsvr32 /s "'+$sTarget+'"'
If @ERROR
"Can't register file - requires elevated privilege"+@CRLF
Else
$initKixForms=CreateObject("Kixtart.System")
EndIf
EndIf
EndSelect
EndIf

Exit @ERROR

EndFunction ; }}}
; vim600:ai sw=4 ts=4 fdc=4 fdm=marker



Edited by Richard H. (2007-10-31 09:15 AM)