usesShellapi;functionExecandwait (ConstExecutefile, paramstring:string): boolean;varSeinfo:tshellexecuteinfo; Exitcode:dword;beginFillchar (Seinfo, SizeOf (seinfo),0); Seinfo.cbsize:=SizeOf (Tshellexecuteinfo); withSeinfo Do beginfmask:=see_mask_nocloseprocess; Wnd:=Application.handle; Lpfile:=PChar (Executefile); Lpparameters:=PChar (paramstring); Nshow:=Sw_hide; End; ifShellExecuteEx (@SEInfo) Then begin Repeatapplication.processmessages; GetExitCodeProcess (seinfo.hprocess, ExitCode); until(ExitCode <> still_active)orapplication.terminated; Result:=True; End Elseresult:=False;End; procedureRegisterOCX;typeTregfunc=function: HResult;stdcall;varAregfunc:tregfunc; Ahandle:thandle; Ocxpath:string;begin TryOcxpath:='E:\SVN\Matrix Control \jydmax.ocx';//Extractfilepath (application.exename) + ' flash.ocx ';Ahandle: =LoadLibrary (PChar (Ocxpath)); ifAhandle <>0 Then beginAregfunc:= GetProcAddress (Ahandle,'DllRegisterServer'); ifAssigned (Aregfunc) Then beginexecandwait ('regsvr32','/ S'+Ocxpath); End; FreeLibrary (Ahandle); End; exceptShowMessage (Format ('Unable to register%s', [Ocxpath])); End;End; {1.} typeTdllregisterserver=function: HResult;stdcall; functionRegisterOCX (FileName:string): Boolean;varOcxhand:thandle; Regfunc:tdllregisterserver;beginOcxhand:=LoadLibrary (PChar (FileName)); Regfunc:= GetProcAddress (Ocxhand,'DllRegisterServer'); if@RegFunc <>Nil ThenResult:= Regfunc =S_OKElseResult:=False; FreeLibrary (Ocxhand);End; functionUnregisterocx (FileName:string): Boolean;varOcxhand:thandle; Regfunc:tdllregisterserver;beginOcxhand:=LoadLibrary (PChar (FileName)); Regfunc:= GetProcAddress (Ocxhand,'DllUnregisterServer'); if@RegFunc <>Nil ThenResult:= Regfunc =S_OKElseResult:=False; FreeLibrary (Ocxhand);End; {**********} {2.} functionRegisterServer (ConstAdllfilename:string; aregister:boolean): Boolean;typeTregproc=function: HResult; stdcall;ConstCregfuncnamearr:Array[Boolean] ofPChar = ('DllUnregisterServer','DllRegisterServer');varVlibhandle:thandle; Vregproc:tregproc;beginResult:=False; Vlibhandle:=LoadLibrary (PChar (adllfilename)); ifVlibhandle =0 ThenExit; @vRegProc:=GetProcAddress (Vlibhandle, Cregfuncnamearr[aregister]); if@vRegProc <>Nil ThenResult:= Vregproc =S_OK; FreeLibrary (vlibhandle);End;
Http://www.cnblogs.com/toosuo/p/3226193.html
Delphi Registration/Anti-registration OCX