1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009 |
- $PBExportHeader$uo_reghelper.sru
- forward
- global type uo_reghelper from nonvisualobject
- end type
- type filetime from structure within uo_reghelper
- end type
- type systemtime from structure within uo_reghelper
- end type
- end forward
- type filetime from structure
- long dwlowdatetime
- long dwhighdatetime
- end type
- type systemtime from structure
- integer wyear
- integer wmonth
- integer wdayofweek
- integer wday
- integer whour
- integer wminute
- integer wsecond
- integer wmilliseconds
- end type
- shared variables
- boolean sv_option_iftryreg = true // 控制是否注册
- end variables
- global type uo_reghelper from nonvisualobject
- end type
- global uo_reghelper uo_reghelper
- type prototypes
- Function long GetFullPathName (String lpFileName ,Long nBufferLength,ref string lpBuffer,ref long lpFilePart) library "kernel32" ALIAS FOR "GetFullPathNameA;Ansi"
- Function long CreateDirectory (string lpNewDirectory ,ref SECURITY_ATTRIBUTES lpSecurityAttributes ) library "kernel32" Alias for "CreateDirectoryA;Ansi"
- Function long GetFileTime (Long hFile ,ref filetime lpCreationTime ,ref filetime lpLastAccessTime ,ref filetime lpLastWriteTime ) library "kernel32" Alias for "GetFileTime;Ansi"
- Function long lopen (string lpPathName , long iReadWrite ) library "kernel32" Alias for "_lopen;Ansi"
- Function long lclose (long hFile) library "kernel32" Alias for "_lclose"
- Function long FileTimeToSystemTime (ref FILETIME lpFileTime ,ref SYSTEMTIME lpSystemTime ) library "kernel32" Alias for "FileTimeToSystemTime;Ansi"
- Function long CopyFile (String lpExistingFileName , String lpNewFileName , long bFailIfExists ) library "kernel32" Alias for "CopyFileA;Ansi"
- Subroutine Sleep(ulong dwMilliseconds) LIBRARY "kernel32.dll"
- Function long GetWindowsDirectory (ref string lpBuffer,long nSize) Library "kernel32" Alias for "GetWindowsDirectoryA;Ansi"
- Function long GetSystemDirectory (ref string lpBuffer,long nSize) Library "kernel32" Alias for "GetSystemDirectoryA;Ansi"
- Function long SetFileAttributes (String lpFileName , long dwFileAttributes ) Library "kernel32" Alias for "SetFileAttributesA;Ansi"
- end prototypes
- type variables
- public boolean ins_win32 = false
- end variables
- forward prototypes
- private function integer f_filetoblob (string arg_filepathname, ref blob arg_blobdata, ref string arg_msg)
- private function integer f_blobtofile (string arg_filepathname, blob arg_blobdata, ref string arg_msg)
- private function string f_clsid (string arg_progid)
- private function string f_codebase (string arg_progid)
- private function integer f_ifexist (string arg_regkey)
- private subroutine f_test ()
- private subroutine f_test1 ()
- private function integer reg32dll (string arg_filepath, ref string arg_msg)
- private function integer regdll (string arg_filepath, ref string arg_msg)
- public function integer unregdll (string arg_filepath, ref string arg_msg)
- public function integer connecttonewobject (string arg_progid, string arg_filepath, ref oleobject arg_ole, ref string arg_msg)
- public function datetime pf_getfilecreatetime (string arg_filefullpathname)
- public function integer tryreg (string arg_progid, string arg_filepath, ref string arg_msg, boolean arg_if_delete)
- public function integer tryreg (string arg_progid, string arg_filepath, ref string arg_msg)
- private function integer unreg32dll (string arg_filepath, ref string arg_msg)
- public function string pf_getfullpathname (string arg_filename)
- public function boolean pf_isadmin ()
- public subroutine set_sv_option_iftryreg (boolean arg_value)
- end prototypes
- private function integer f_filetoblob (string arg_filepathname, ref blob arg_blobdata, ref string arg_msg);//读入数据
- long flen,loops,ls_i,bytes_read,new_pos,rslt=1,li_FileNum
- blob b_dtdata_p,tot_b
- flen = FileLength(arg_filepathname)
- li_FileNum = FileOpen(arg_filepathname, StreamMode!, Read!, LockRead!)
- if li_FileNum=-1 then
- rslt=0
- arg_msg='打开文件'+arg_filepathname+'操作失败!'
- fileclose(li_FileNum)
- goto ext
- end if
- IF flen > 32765 THEN
- IF Mod(flen, 32765) = 0 THEN
- loops = flen/32765
- ELSE
- loops = (flen/32765) + 1
- END IF
- ELSE
- loops = 1
- END IF
- new_pos = 1
- FOR ls_i = 1 to loops
- bytes_read = FileRead(li_FileNum, b_dtdata_p)
- if bytes_read=0 then
- rslt=0
- arg_msg='读取文件'+arg_filepathname+'操作失败!'
- fileclose(li_FileNum)
- goto ext
- end if
- tot_b = tot_b + b_dtdata_p
- NEXT
- fileclose(li_FileNum)
- arg_blobdata=tot_b
- ext:
- return rslt
- end function
- private function integer f_blobtofile (string arg_filepathname, blob arg_blobdata, ref string arg_msg);//blob转文件
- long rslt=1,fend,fend_t
- blob b_dtdata, b_dtdata_p
- long li_FileNum,ls_i,ls_jh
- string tmpfilepathname
- tmpfilepathname=arg_filepathname
- b_dtdata=arg_blobdata
- fend=len(b_dtdata)
- if fend<=32765 then
- fend_t=1
- else
- fend_t=fend/32765
- if mod(fend,32765)<>0 then
- fend_t=fend_t+1
- end if
- end if
- li_FileNum = FileOpen( tmpfilepathname,StreamMode!, Write!, LockWrite!)
- if li_FileNum<=0 then
- arg_msg="打开文件"+tmpfilepathname+"失败"
- rslt=0
- fileclose(li_FileNum)
- goto ext
- end if
- for ls_i = 1 to fend_t
- b_dtdata_p=blobmid(b_dtdata,1+(ls_i - 1 )*32765,32765)
- ls_jh=FileWrite(li_FileNum, b_dtdata_p)
- if ls_jh<=0 then
- arg_msg="写文件"+tmpfilepathname+"失败"
- rslt=0
- fileclose(li_FileNum)
- goto ext
- end if
- next
- fileclose(li_FileNum)
- ext:
- return rslt
- end function
- private function string f_clsid (string arg_progid);String ls_key
- ls_key = "HKEY_CLASSES_ROOT\" + arg_progid + "\CLSID"
- String ls_clsid
- IF RegistryGet(ls_key, "", RegString!, ls_clsid) <> 1 THEN
- SetNull(ls_clsid)
- END IF
- RETURN ls_clsid
- end function
- private function string f_codebase (string arg_progid);String ls_clsid
- ls_clsid = f_clsid(arg_progid)
- String ls_codebase
- IF IsNull(ls_clsid) THEN
- SetNull(ls_codebase)
- GOTO ext
- END IF
- String ls_key
- ls_key = "HKEY_CLASSES_ROOT\CLSID\" + ls_clsid + "\InprocServer32"
- String ls_name
- IF ins_win32 THEN
- ls_name = ""
- ELSE
- ls_name = "CodeBase"
- END IF
- IF RegistryGet(ls_key, ls_name, RegString!, ls_codebase) <> 1 THEN
- SetNull(ls_codebase)
- GOTO ext
- END IF
- IF Pos(ls_codebase, 'file:///') > 0 THEN
- ls_codebase = Mid(ls_codebase, 9)
- END IF
- Long ll_pos
- ll_pos = Pos(ls_codebase, '/')
- DO WHILE ll_pos > 0
- ls_codebase = Replace(ls_codebase, ll_pos, 1, '\')
- ll_pos = Pos(ls_codebase, '/')
- LOOP
- ext:
- RETURN ls_codebase
- end function
- private function integer f_ifexist (string arg_regkey);String ls_value[]
- IF RegistryValues(arg_regkey, ls_value) = 1 THEN
- RETURN 1
- ELSE
- RETURN 0
- END IF
- end function
- private subroutine f_test ();String ls_path
- ls_path = "D:\workspace\__________test\MyTest\PBCOMTest\bin\Release\PBCOMTest.dll"
- String ls_netversion
- ls_netversion = "4.0"
- String ls_regkey
- ls_regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework"
- String ls_valuename
- ls_valuename = "InstallRoot"
- String ls_frameworkpath
- IF RegistryGet(ls_regkey, ls_valuename, RegString!, ls_frameworkpath) <> 1 THEN
- MessageBox("", "没有安装.net Framework " + ls_netversion)
- GOTO ext
- END IF
- String ls_exec
- IF ls_netversion < "2.0" THEN
- ls_exec = ls_frameworkpath + "v1.1.4322\"
- ELSEIF ls_netversion < "4.0" THEN
- ls_exec = ls_frameworkpath + "v2.0.50727\"
- ELSE
- ls_exec = ls_frameworkpath + "v4.0.30319\"
- END IF
- ls_exec = ls_exec + "RegAsm.exe"
- IF Not FileExists(ls_exec) THEN
- MessageBox("", ls_exec + "不存在")
- GOTO ext
- END IF
- string ls_logfile
- ls_logfile= "tmp_reg.txt"
- ls_exec = "~"" + ls_exec + "~" ~"" + ls_path + "~" /codebase > ~"" + ls_logfile + "~" 2>&1"
- String ls_tmpfile
- ls_tmpfile = "tmp_reg.cmd"
- if fileexists(ls_tmpfile) then
- filedelete(ls_tmpfile)
- end if
- String arg_msg
- IF f_blobtofile(ls_tmpfile, Blob(ls_exec,EncodingANSI!), arg_msg) <> 1 THEN
- MessageBox("", arg_msg)
- GOTO ext
- END IF
- IF Run(ls_tmpfile) <> 1 THEN
- MessageBox("", "注册失败")
- GOTO ext
- END IF
- sleep(1)
- filedelete(ls_tmpfile)
- Blob lb_msg
- IF f_filetoblob(ls_logfile, lb_msg, arg_msg) <> 1 THEN
- MessageBox("", arg_msg)
- GOTO ext
- END IF
- filedelete(ls_logfile)
- arg_msg = string(lb_msg, EncodingANSI!)
- MessageBox('', arg_msg)
- ext:
- end subroutine
- private subroutine f_test1 ();oleobject obj
- obj = Create oleobject
- IF obj.ConnectToNewObject("PBCOMTest.Class3") <> 0 THEN
- MessageBox('', '未连接')
- GOTO ext
- END IF
- String ls_msg
- ls_msg = obj.HelloWorld("123")
- MessageBox('', ls_msg)
- ext:
- obj.DisconnectObject()
- Destroy obj
- end subroutine
- private function integer reg32dll (string arg_filepath, ref string arg_msg);Int rslt = 1
- IF Not FileExists(arg_filepath) THEN
- rslt = 0
- arg_msg = arg_filepath + '不存在'
- GOTO ext
- END IF
- String ls_exec = ""
- ls_exec = "C:\WINDOWS\system32\regsvr32.exe"
- IF Not FileExists(ls_exec) THEN
- rslt = 0
- arg_msg = ls_exec + "不存在"
- GOTO ext
- END IF
- String ls_logfile
- ls_logfile = "tmp_reg.txt"
- String ls_logfile1
- ls_logfile1 = "tmp_tmp.log"
- ls_exec = "~"" + ls_exec + "~" /s ~"" + arg_filepath + "~" > ~"" + ls_logfile1 + "~" 2>&1~r~nrename ~"" + ls_logfile1 + "~" ~"" + ls_logfile + "~""
- String ls_tmpfile
- ls_tmpfile = "tmp_reg.cmd"
- IF FileExists(ls_tmpfile) THEN
- FileDelete(ls_tmpfile)
- END IF
- IF FileExists(ls_logfile) THEN
- FileDelete(ls_logfile)
- END IF
- IF f_blobtofile(ls_tmpfile, Blob(ls_exec,EncodingANSI!), arg_msg) <> 1 THEN
- rslt = 0
- GOTO ext
- END IF
- IF Run(ls_tmpfile) <> 1 THEN
- rslt = 0
- arg_msg = "执行脚本失败," + ls_tmpfile
- GOTO ext
- END IF
- DO WHILE Not FileExists(ls_logfile)
- sleep(1)
- LOOP
- FileDelete(ls_tmpfile)
- Blob lb_msg
- IF f_filetoblob(ls_logfile, lb_msg, arg_msg) <> 1 THEN
- rslt = 0
- GOTO ext
- END IF
- FileDelete(ls_logfile)
- String ls_msg
- ls_msg = String(lb_msg, EncodingANSI!)
- arg_msg = ls_msg
- ext:
- RETURN rslt
- end function
- private function integer regdll (string arg_filepath, ref string arg_msg);//====================================================================
- // 事件: uo_reghelper.regdll()
- //--------------------------------------------------------------------
- // 描述: 注册.net的DLL
- //--------------------------------------------------------------------
- // 参数:
- // value string arg_filepath
- // reference string arg_msg
- //--------------------------------------------------------------------
- // 返回: integer
- //--------------------------------------------------------------------
- // 作者: lwl 日期: 2013年03月23日
- //--------------------------------------------------------------------
- // LONGJOE
- //--------------------------------------------------------------------
- // 修改历史:
- //
- //====================================================================
- IF ins_win32 THEN
- RETURN reg32dll(arg_filepath, arg_msg)
- END IF
- Int rslt = 1
- datastore lds_dllmap
- lds_dllmap = Create datastore
- lds_dllmap.DataObject = 'ds_dllmap'
- IF Not FileExists(arg_filepath) THEN
- rslt = 0
- arg_msg = arg_filepath + '不存在'
- GOTO ext
- END IF
- String ls_regkey
- ls_regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework"
- String ls_valuename
- ls_valuename = "InstallRoot"
- String ls_frameworkpath
- IF RegistryGet(ls_regkey, ls_valuename, RegString!, ls_frameworkpath) <> 1 THEN
- rslt = 0
- arg_msg = "没有安装.net Framework"
- GOTO ext
- END IF
- String ls_exec = ""
- //IF DirectoryExists(ls_frameworkpath + "v4.0.30319\") THEN
- // ls_exec = ls_frameworkpath + "v4.0.30319\"
- //ELSEIF DirectoryExists(ls_frameworkpath + "v2.0.50727\") THEN
- // ls_exec = ls_frameworkpath + "v2.0.50727\"
- //ELSEIF DirectoryExists(ls_frameworkpath + "v1.1.4322\") THEN
- // ls_exec = ls_frameworkpath + "v1.1.4322\"
- //END IF
- String ls_dllname // 获取dll文件名
- IF LastPos(arg_filepath, '\') > 0 THEN
- ls_dllname = Mid(arg_filepath, LastPos(arg_filepath, '\') + 1)
- ELSE
- ls_dllname = arg_filepath
- END IF
- Long ll_row
- String ls_dotnetver = ''
- ll_row = lds_dllmap.Find('dllname="' + ls_dllname + '"', 1, lds_dllmap.RowCount())
- If (ll_row > 0) THEN
- ls_dotnetver = Trim(lds_dllmap.Object.dotnetver[ll_row])
- END IF
- CHOOSE CASE ls_dotnetver
- CASE '4.0'
- IF DirectoryExists(ls_frameworkpath + "v4.0.30319\") THEN
- ls_exec = ls_frameworkpath + "v4.0.30319\"
- ELSE
- rslt = 0
- END IF
- CASE '2.0'
- IF DirectoryExists(ls_frameworkpath + "v2.0.50727\") THEN
- ls_exec = ls_frameworkpath + "v2.0.50727\"
- ELSE
- rslt = 0
- END IF
- CASE '1.1'
- IF DirectoryExists(ls_frameworkpath + "v1.1.4322\") THEN
- ls_exec = ls_frameworkpath + "v1.1.4322\"
- ELSE
- rslt = 0
- END IF
- CASE ELSE
- IF DirectoryExists(ls_frameworkpath + "v4.0.30319\") THEN
- ls_exec = ls_frameworkpath + "v4.0.30319\"
- ELSEIF DirectoryExists(ls_frameworkpath + "v2.0.50727\") THEN
- ls_exec = ls_frameworkpath + "v2.0.50727\"
- ELSEIF DirectoryExists(ls_frameworkpath + "v1.1.4322\") THEN
- ls_exec = ls_frameworkpath + "v1.1.4322\"
- ELSE
- rslt = 0
- END IF
- END CHOOSE
- If (rslt = 0) And (ls_dotnetver <> '') THEN
- arg_msg = '本机没有安装.Net Framework ' + ls_dotnetver + '环境,请联系实施人员协助处理'
- GOTO ext
- ELSEIF rslt = 0 THEN
- arg_msg = '本机没有安装.Net Framework环境,请联系实施人员协助处理'
- GOTO ext
- END IF
- ls_exec = ls_exec + "RegAsm.exe"
- IF Not FileExists(ls_exec) THEN
- rslt = 0
- arg_msg = ls_exec + "不存在"
- GOTO ext
- END IF
- String ls_logfile
- ls_logfile = "tmp_reg.txt"
- String ls_logfile1
- ls_logfile1 = "tmp_tmp.log"
- ls_exec = "~"" + ls_exec + "~" /tlb:~""+Mid(arg_filepath, 1, Len(arg_filepath) - 4)+".tlb~" ~"" + arg_filepath + "~" /codebase > ~"" + ls_logfile1 + "~" 2>&1~r~nrename ~"" + ls_logfile1 + "~" ~"" + ls_logfile + "~""
- String ls_tmpfile
- ls_tmpfile = "tmp_reg.cmd"
- IF FileExists(ls_tmpfile) THEN
- FileDelete(ls_tmpfile)
- END IF
- IF FileExists(ls_logfile) THEN
- FileDelete(ls_logfile)
- END IF
- IF f_blobtofile(ls_tmpfile, Blob(ls_exec,EncodingANSI!), arg_msg) <> 1 THEN
- rslt = 0
- GOTO ext
- END IF
- IF Run(ls_tmpfile) <> 1 THEN
- rslt = 0
- arg_msg = "执行脚本失败," + ls_tmpfile
- GOTO ext
- END IF
- DO WHILE Not FileExists(ls_logfile)
- sleep(1)
- LOOP
- FileDelete(ls_tmpfile)
- Blob lb_msg
- IF f_filetoblob(ls_logfile, lb_msg, arg_msg) <> 1 THEN
- rslt = 0
- GOTO ext
- END IF
- FileDelete(ls_logfile)
- String ls_msg
- ls_msg = String(lb_msg, EncodingANSI!)
- arg_msg = Lower(ls_msg)
- IF Pos(arg_msg, 'error ra0000') > 0 And (Pos(arg_msg, '管理员') > 0 Or Pos(arg_msg, 'admin') > 0) THEN
- rslt = 0
- arg_msg = '注册"' + arg_filepath + '"失败,请以管理员身份运行本程序。详细信息:~r~n~r~n' + arg_msg
- ELSEIF Pos(arg_msg, 'success') <= 0 And Pos(arg_msg, '成功') <= 0 THEN
- rslt = 0
- END IF
- ext:
- Destroy lds_dllmap
- RETURN rslt
- end function
- public function integer unregdll (string arg_filepath, ref string arg_msg);//====================================================================
- // 事件: uo_reghelper.regdll()
- //--------------------------------------------------------------------
- // 描述: 注册.net的DLL
- //--------------------------------------------------------------------
- // 参数:
- // value string arg_filepath
- // reference string arg_msg
- //--------------------------------------------------------------------
- // 返回: integer
- //--------------------------------------------------------------------
- // 作者: lwl 日期: 2013年03月23日
- //--------------------------------------------------------------------
- // LONGJOE
- //--------------------------------------------------------------------
- // 修改历史:
- //
- //====================================================================
- if ins_win32 then
- return unreg32dll(arg_filepath, arg_msg)
- end if
- Int rslt = 1
- IF Not FileExists(arg_filepath) THEN
- rslt = 0
- arg_msg = arg_filepath + '不存在'
- GOTO ext
- END IF
- String ls_regkey
- ls_regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework"
- String ls_valuename
- ls_valuename = "InstallRoot"
- String ls_frameworkpath
- IF RegistryGet(ls_regkey, ls_valuename, RegString!, ls_frameworkpath) <> 1 THEN
- rslt = 0
- arg_msg = "没有安装.net Framework"
- GOTO ext
- END IF
- String ls_exec = "",ls_exec1
- IF DirectoryExists(ls_frameworkpath + "v4.0.30319\") THEN
- ls_exec = ls_frameworkpath + "v4.0.30319\"
- ELSEIF DirectoryExists(ls_frameworkpath + "v2.0.50727\") THEN
- ls_exec = ls_frameworkpath + "v2.0.50727\"
- ELSEIF DirectoryExists(ls_frameworkpath + "v1.1.4322\") THEN
- ls_exec = ls_frameworkpath + "v1.1.4322\"
- END IF
- ls_exec = ls_exec + "RegAsm.exe"
- IF Not FileExists(ls_exec) THEN
- rslt = 0
- arg_msg = ls_exec + "不存在"
- GOTO ext
- END IF
- String ls_logfile
- ls_logfile = "tmp_reg.txt"
- String ls_logfile1
- ls_logfile1 = "tmp_tmp.log"
- ls_exec = "~"" + ls_exec + "~" ~"" + arg_filepath + "~" /unregister > ~"" + ls_logfile1 + "~" 2>&1~r~nrename ~"" + ls_logfile1 + "~" ~"" + ls_logfile + "~""
- //ls_exec = "~"" + ls_exec + "~"" + " " + arg_filepath + + " /unregister" + "~"" + "/codebase >" + "~"" + ls_logfile1 + "~" 2>&1~r~nrename ~"" + ls_logfile1 + "~" ~"" + ls_logfile + "~""
- String ls_tmpfile
- ls_tmpfile = "tmp_reg.cmd"
- IF FileExists(ls_tmpfile) THEN
- FileDelete(ls_tmpfile)
- END IF
- IF FileExists(ls_logfile) THEN
- FileDelete(ls_logfile)
- END IF
- IF f_blobtofile(ls_tmpfile, Blob(ls_exec,EncodingANSI!), arg_msg) <> 1 THEN
- rslt = 0
- GOTO ext
- END IF
- IF Run(ls_tmpfile) <> 1 THEN
- rslt = 0
- arg_msg = "执行脚本失败," + ls_tmpfile
- GOTO ext
- END IF
- DO WHILE Not FileExists(ls_logfile)
- sleep(1)
- LOOP
- FileDelete(ls_tmpfile)
- Blob lb_msg
- IF f_filetoblob(ls_logfile, lb_msg, arg_msg) <> 1 THEN
- rslt = 0
- GOTO ext
- END IF
- FileDelete(ls_logfile)
- String ls_msg
- ls_msg = String(lb_msg, EncodingANSI!)
- arg_msg = ls_msg
- IF Pos(arg_msg, 'success') <= 0 And Pos(arg_msg, '成功') <= 0 THEN
- rslt = 0
- END IF
- ext:
- RETURN rslt
- end function
- public function integer connecttonewobject (string arg_progid, string arg_filepath, ref oleobject arg_ole, ref string arg_msg);//====================================================================
- // 事件: uo_reghelper.connecttonewobject()
- //--------------------------------------------------------------------
- // 描述:
- //--------------------------------------------------------------------
- // 参数:
- // value string arg_progid 类名
- // value string arg_filepath DLL路径
- // reference oleobject arg_ole 要连接的oleobject
- // reference string arg_msg 返回失败信息
- //--------------------------------------------------------------------
- // 返回: integer
- //--------------------------------------------------------------------
- // 作者: lwl 日期: 2013年03月23日
- //--------------------------------------------------------------------
- // LONGJOE
- //--------------------------------------------------------------------
- // 修改历史:
- //
- //====================================================================
- Int rslt = 1
- IF sv_option_iftryreg AND pf_isadmin() THEN
- IF tryreg(arg_progid, arg_filepath, Ref arg_msg, False) <> 1 THEN
- rslt = 0
- GOTO ext
- END IF
- END IF
- IF arg_ole.ConnectToNewObject(arg_progid) <> 0 THEN
- rslt = 0
- arg_msg = '连接ole对象失败,' + arg_progid + ',' + arg_filepath
- GOTO ext
- END IF
- ext:
- RETURN rslt
- end function
- public function datetime pf_getfilecreatetime (string arg_filefullpathname);//pf_getfilecreatetime
- long rslt
- datetime createtime,errdatetime
- date ls_date
- time ls_time
- systemtime ls_systemtime
- filetime lpCreationTime ,lpLastAccessTime ,lpLastWriteTime
- long li_FileNum
- //
- li_FileNum = lOpen(arg_filefullpathname,0)
- rslt = GetFileTime (li_FileNum ,lpCreationTime ,lpLastAccessTime ,lpLastWriteTime )
- li_FileNum=lclose(li_FileNum)
- if rslt=0 then return errdatetime
- //rslt=FileTimeToSystemTime(lpCreationTime,ls_systemtime)//
- rslt=FileTimeToSystemTime(lpLastWriteTime,ls_systemtime)
- if rslt=0 then return errdatetime
-
- ls_date=date(string(ls_systemtime.wYear)+'.'+&
- string(ls_systemtime.wmonth)+'.'+&
- string(ls_systemtime.wDay))
- ls_time=time(string(ls_systemtime.wHour)+':'+&
- string(ls_systemtime.wMinute )+':'+&
- string(ls_systemtime.wSecond ))
- createtime =datetime(ls_date,ls_time)
- return createtime
- end function
- public function integer tryreg (string arg_progid, string arg_filepath, ref string arg_msg, boolean arg_if_delete);
- Int rslt = 1
- Long ll_pos
- String ls_path
- ls_path = arg_filepath
- ll_pos = Pos(ls_path, '\')
- IF ll_pos = 0 THEN
-
- IF sys_cur_path = '' THEN
- ls_path = pf_getfullpathname(arg_filepath)
- ELSE
- ls_path = sys_cur_path + arg_filepath
- END IF
-
- IF Not FileExists(ls_path) THEN
- ls_path = "C:\Windows\SysWOW64\" + arg_filepath
- IF Not FileExists(ls_path) THEN
- ls_path = "C:\Windows\System32\" + arg_filepath
- END IF
- END IF
- END IF
- IF Not FileExists(ls_path) THEN
- rslt = 0
- arg_msg = '文件不存在,' + ls_path
- GOTO ext
- END IF
- String ls_codebase
- ls_codebase = f_codebase(arg_progid)
- IF IsNull(ls_codebase) THEN
- GOTO reg
- END IF
- DateTime ld_org_date, ld_cur_date
- IF Lower(ls_codebase) <> Lower(ls_path) THEN
- IF Lower(ls_codebase) <> "" THEN
- IF FileExists(ls_codebase) THEN
- // DONE: 如果原来的较新 GOTO con
- ld_org_date = pf_getfilecreatetime(ls_codebase)
- ld_cur_date = pf_getfilecreatetime(ls_path)
- IF ld_cur_date <= ld_org_date THEN
- GOTO con
- END IF
- unregdll(ls_codebase, arg_msg)
- END IF
- END IF
- GOTO reg
- END IF
- GOTO con
- reg:
- String ls_msg
- IF regdll(ls_path, arg_msg) <> 1 THEN
- rslt = 0
- GOTO ext
- END IF
- ls_codebase = f_codebase(arg_progid)
- IF IsNull(ls_codebase) THEN
- rslt = 0
- arg_msg = ls_path + '文件中不存在对象:' + arg_progid + ',请联系软件供应商获取最新文件版本!'
- IF arg_if_delete THEN
- unregdll(ls_path, ls_msg)
- FileDelete(ls_path)
- arg_msg += '旧文件已被删除'
- END IF
- GOTO ext
- END IF
- IF Lower(ls_codebase) <> Lower(ls_path) THEN
- rslt = 0
- arg_msg = ls_path + '文件注册失败'
- GOTO ext
- END IF
- con:
- ext:
- RETURN rslt
- end function
- public function integer tryreg (string arg_progid, string arg_filepath, ref string arg_msg);return tryreg(arg_progid, arg_filepath, ref arg_msg, false)
- end function
- private function integer unreg32dll (string arg_filepath, ref string arg_msg);Int rslt = 1
- IF Not FileExists(arg_filepath) THEN
- rslt = 0
- arg_msg = arg_filepath + '不存在'
- GOTO ext
- END IF
- String ls_exec = ""
- ls_exec = "C:\WINDOWS\system32\regsvr32.exe"
- IF Not FileExists(ls_exec) THEN
- rslt = 0
- arg_msg = ls_exec + "不存在"
- GOTO ext
- END IF
- String ls_logfile
- ls_logfile = "tmp_reg.txt"
- String ls_logfile1
- ls_logfile1 = "tmp_tmp.log"
- ls_exec = "~"" + ls_exec + "~" /s /u ~"" + arg_filepath + "~" > ~"" + ls_logfile1 + "~" 2>&1~r~nrename ~"" + ls_logfile1 + "~" ~"" + ls_logfile + "~""
- String ls_tmpfile
- ls_tmpfile = "tmp_reg.cmd"
- IF FileExists(ls_tmpfile) THEN
- FileDelete(ls_tmpfile)
- END IF
- IF FileExists(ls_logfile) THEN
- FileDelete(ls_logfile)
- END IF
- IF f_blobtofile(ls_tmpfile, Blob(ls_exec,EncodingANSI!), arg_msg) <> 1 THEN
- rslt = 0
- GOTO ext
- END IF
- IF Run(ls_tmpfile) <> 1 THEN
- rslt = 0
- arg_msg = "执行脚本失败," + ls_tmpfile
- GOTO ext
- END IF
- DO WHILE Not FileExists(ls_logfile)
- sleep(1)
- LOOP
- FileDelete(ls_tmpfile)
- Blob lb_msg
- IF f_filetoblob(ls_logfile, lb_msg, arg_msg) <> 1 THEN
- rslt = 0
- GOTO ext
- END IF
- FileDelete(ls_logfile)
- String ls_msg
- ls_msg = String(lb_msg, EncodingANSI!)
- arg_msg = ls_msg
- ext:
- RETURN rslt
- end function
- public function string pf_getfullpathname (string arg_filename);//f_init_syscurpath(arg_msg)
- Long rslt = 1
- String lpBuffer
- lpBuffer = Fill('',200)
- Long lpfilepart,li_FileNum
- rslt = GetFullPathName(arg_filename,196,lpBuffer,lpfilepart)
- IF rslt = 0 THEN
- return arg_filename
- ELSE
- sys_cur_path = Left(lpBuffer,Len(lpBuffer)-Len(arg_filename))
- return lpBuffer
- END IF
- end function
- public function boolean pf_isadmin ();// DONE: 检查是否有注册表权限
- String ls_key
- ls_key = 'HKEY_LOCAL_MACHINE\SOFTWARE\LongJoe'
- String ls_name
- ls_name = 'testadmin'
- IF RegistrySet(ls_key, ls_name, RegString!, publ_operator) = 1 THEN
- RETURN True
- ELSE
- RETURN False
- END IF
- end function
- public subroutine set_sv_option_iftryreg (boolean arg_value);sv_option_iftryreg = arg_value
- end subroutine
- on uo_reghelper.create
- call super::create
- TriggerEvent( this, "constructor" )
- end on
- on uo_reghelper.destroy
- TriggerEvent( this, "destructor" )
- call super::destroy
- end on
|