uo_reghelper.sru 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. $PBExportHeader$uo_reghelper.sru
  2. forward
  3. global type uo_reghelper from nonvisualobject
  4. end type
  5. type filetime from structure within uo_reghelper
  6. end type
  7. type systemtime from structure within uo_reghelper
  8. end type
  9. end forward
  10. type filetime from structure
  11. long dwlowdatetime
  12. long dwhighdatetime
  13. end type
  14. type systemtime from structure
  15. integer wyear
  16. integer wmonth
  17. integer wdayofweek
  18. integer wday
  19. integer whour
  20. integer wminute
  21. integer wsecond
  22. integer wmilliseconds
  23. end type
  24. global type uo_reghelper from nonvisualobject
  25. end type
  26. global uo_reghelper uo_reghelper
  27. type prototypes
  28. Function long GetFullPathName (String lpFileName ,Long nBufferLength,ref string lpBuffer,ref long lpFilePart) library "kernel32" ALIAS FOR "GetFullPathNameA;Ansi"
  29. Function long CreateDirectory (string lpNewDirectory ,ref SECURITY_ATTRIBUTES lpSecurityAttributes ) library "kernel32" Alias for "CreateDirectoryA;Ansi"
  30. Function long GetFileTime (Long hFile ,ref filetime lpCreationTime ,ref filetime lpLastAccessTime ,ref filetime lpLastWriteTime ) library "kernel32" Alias for "GetFileTime;Ansi"
  31. Function long lopen (string lpPathName , long iReadWrite ) library "kernel32" Alias for "_lopen;Ansi"
  32. Function long lclose (long hFile) library "kernel32" Alias for "_lclose"
  33. Function long FileTimeToSystemTime (ref FILETIME lpFileTime ,ref SYSTEMTIME lpSystemTime ) library "kernel32" Alias for "FileTimeToSystemTime;Ansi"
  34. Function long CopyFile (String lpExistingFileName , String lpNewFileName , long bFailIfExists ) library "kernel32" Alias for "CopyFileA;Ansi"
  35. Subroutine Sleep(ulong dwMilliseconds) LIBRARY "kernel32.dll"
  36. Function long GetWindowsDirectory (ref string lpBuffer,long nSize) Library "kernel32" Alias for "GetWindowsDirectoryA;Ansi"
  37. Function long GetSystemDirectory (ref string lpBuffer,long nSize) Library "kernel32" Alias for "GetSystemDirectoryA;Ansi"
  38. Function long SetFileAttributes (String lpFileName , long dwFileAttributes ) Library "kernel32" Alias for "SetFileAttributesA;Ansi"
  39. end prototypes
  40. type variables
  41. public boolean ins_win32 = false
  42. end variables
  43. forward prototypes
  44. private function integer f_filetoblob (string arg_filepathname, ref blob arg_blobdata, ref string arg_msg)
  45. private function integer f_blobtofile (string arg_filepathname, blob arg_blobdata, ref string arg_msg)
  46. private function string f_clsid (string arg_progid)
  47. private function string f_codebase (string arg_progid)
  48. private function integer f_ifexist (string arg_regkey)
  49. private subroutine f_test ()
  50. private subroutine f_test1 ()
  51. private function integer reg32dll (string arg_filepath, ref string arg_msg)
  52. private function integer regdll (string arg_filepath, ref string arg_msg)
  53. public function integer unregdll (string arg_filepath, ref string arg_msg)
  54. public function integer connecttonewobject (string arg_progid, string arg_filepath, ref oleobject arg_ole, ref string arg_msg)
  55. public function datetime pf_getfilecreatetime (string arg_filefullpathname)
  56. public function integer tryreg (string arg_progid, string arg_filepath, ref string arg_msg, boolean arg_if_delete)
  57. public function integer tryreg (string arg_progid, string arg_filepath, ref string arg_msg)
  58. private function integer unreg32dll (string arg_filepath, ref string arg_msg)
  59. public function string pf_getfullpathname (string arg_filename)
  60. end prototypes
  61. private function integer f_filetoblob (string arg_filepathname, ref blob arg_blobdata, ref string arg_msg);//读入数据
  62. long flen,loops,ls_i,bytes_read,new_pos,rslt=1,li_FileNum
  63. blob b_dtdata_p,tot_b
  64. flen = FileLength(arg_filepathname)
  65. li_FileNum = FileOpen(arg_filepathname, StreamMode!, Read!, LockRead!)
  66. if li_FileNum=-1 then
  67. rslt=0
  68. arg_msg='打开文件'+arg_filepathname+'操作失败!'
  69. fileclose(li_FileNum)
  70. goto ext
  71. end if
  72. IF flen > 32765 THEN
  73. IF Mod(flen, 32765) = 0 THEN
  74. loops = flen/32765
  75. ELSE
  76. loops = (flen/32765) + 1
  77. END IF
  78. ELSE
  79. loops = 1
  80. END IF
  81. new_pos = 1
  82. FOR ls_i = 1 to loops
  83. bytes_read = FileRead(li_FileNum, b_dtdata_p)
  84. if bytes_read=0 then
  85. rslt=0
  86. arg_msg='读取文件'+arg_filepathname+'操作失败!'
  87. fileclose(li_FileNum)
  88. goto ext
  89. end if
  90. tot_b = tot_b + b_dtdata_p
  91. NEXT
  92. fileclose(li_FileNum)
  93. arg_blobdata=tot_b
  94. ext:
  95. return rslt
  96. end function
  97. private function integer f_blobtofile (string arg_filepathname, blob arg_blobdata, ref string arg_msg);//blob转文件
  98. long rslt=1,fend,fend_t
  99. blob b_dtdata, b_dtdata_p
  100. long li_FileNum,ls_i,ls_jh
  101. string tmpfilepathname
  102. tmpfilepathname=arg_filepathname
  103. b_dtdata=arg_blobdata
  104. fend=len(b_dtdata)
  105. if fend<=32765 then
  106. fend_t=1
  107. else
  108. fend_t=fend/32765
  109. if mod(fend,32765)<>0 then
  110. fend_t=fend_t+1
  111. end if
  112. end if
  113. li_FileNum = FileOpen( tmpfilepathname,StreamMode!, Write!, LockWrite!)
  114. if li_FileNum<=0 then
  115. arg_msg="打开文件"+tmpfilepathname+"失败"
  116. rslt=0
  117. fileclose(li_FileNum)
  118. goto ext
  119. end if
  120. for ls_i = 1 to fend_t
  121. b_dtdata_p=blobmid(b_dtdata,1+(ls_i - 1 )*32765,32765)
  122. ls_jh=FileWrite(li_FileNum, b_dtdata_p)
  123. if ls_jh<=0 then
  124. arg_msg="写文件"+tmpfilepathname+"失败"
  125. rslt=0
  126. fileclose(li_FileNum)
  127. goto ext
  128. end if
  129. next
  130. fileclose(li_FileNum)
  131. ext:
  132. return rslt
  133. end function
  134. private function string f_clsid (string arg_progid);String ls_key
  135. ls_key = "HKEY_CLASSES_ROOT\" + arg_progid + "\CLSID"
  136. String ls_clsid
  137. IF RegistryGet(ls_key, "", RegString!, ls_clsid) <> 1 THEN
  138. SetNull(ls_clsid)
  139. END IF
  140. RETURN ls_clsid
  141. end function
  142. private function string f_codebase (string arg_progid);String ls_clsid
  143. ls_clsid = f_clsid(arg_progid)
  144. String ls_codebase
  145. IF IsNull(ls_clsid) THEN
  146. SetNull(ls_codebase)
  147. GOTO ext
  148. END IF
  149. String ls_key
  150. ls_key = "HKEY_CLASSES_ROOT\CLSID\" + ls_clsid + "\InprocServer32"
  151. String ls_name
  152. IF ins_win32 THEN
  153. ls_name = ""
  154. ELSE
  155. ls_name = "CodeBase"
  156. END IF
  157. IF RegistryGet(ls_key, ls_name, RegString!, ls_codebase) <> 1 THEN
  158. SetNull(ls_codebase)
  159. GOTO ext
  160. END IF
  161. IF Pos(ls_codebase, 'file:///') > 0 THEN
  162. ls_codebase = Mid(ls_codebase, 9)
  163. END IF
  164. Long ll_pos
  165. ll_pos = Pos(ls_codebase, '/')
  166. DO WHILE ll_pos > 0
  167. ls_codebase = Replace(ls_codebase, ll_pos, 1, '\')
  168. ll_pos = Pos(ls_codebase, '/')
  169. LOOP
  170. ext:
  171. RETURN ls_codebase
  172. end function
  173. private function integer f_ifexist (string arg_regkey);String ls_value[]
  174. IF RegistryValues(arg_regkey, ls_value) = 1 THEN
  175. RETURN 1
  176. ELSE
  177. RETURN 0
  178. END IF
  179. end function
  180. private subroutine f_test ();String ls_path
  181. ls_path = "D:\workspace\__________test\MyTest\PBCOMTest\bin\Release\PBCOMTest.dll"
  182. String ls_netversion
  183. ls_netversion = "4.0"
  184. String ls_regkey
  185. ls_regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework"
  186. String ls_valuename
  187. ls_valuename = "InstallRoot"
  188. String ls_frameworkpath
  189. IF RegistryGet(ls_regkey, ls_valuename, RegString!, ls_frameworkpath) <> 1 THEN
  190. MessageBox("", "没有安装.net Framework " + ls_netversion)
  191. GOTO ext
  192. END IF
  193. String ls_exec
  194. IF ls_netversion < "2.0" THEN
  195. ls_exec = ls_frameworkpath + "v1.1.4322\"
  196. ELSEIF ls_netversion < "4.0" THEN
  197. ls_exec = ls_frameworkpath + "v2.0.50727\"
  198. ELSE
  199. ls_exec = ls_frameworkpath + "v4.0.30319\"
  200. END IF
  201. ls_exec = ls_exec + "RegAsm.exe"
  202. IF Not FileExists(ls_exec) THEN
  203. MessageBox("", ls_exec + "不存在")
  204. GOTO ext
  205. END IF
  206. string ls_logfile
  207. ls_logfile= "tmp_reg.txt"
  208. ls_exec = "~"" + ls_exec + "~" ~"" + ls_path + "~" /codebase > ~"" + ls_logfile + "~" 2>&1"
  209. String ls_tmpfile
  210. ls_tmpfile = "tmp_reg.cmd"
  211. if fileexists(ls_tmpfile) then
  212. filedelete(ls_tmpfile)
  213. end if
  214. String arg_msg
  215. IF f_blobtofile(ls_tmpfile, Blob(ls_exec,EncodingANSI!), arg_msg) <> 1 THEN
  216. MessageBox("", arg_msg)
  217. GOTO ext
  218. END IF
  219. IF Run(ls_tmpfile) <> 1 THEN
  220. MessageBox("", "注册失败")
  221. GOTO ext
  222. END IF
  223. sleep(1)
  224. filedelete(ls_tmpfile)
  225. Blob lb_msg
  226. IF f_filetoblob(ls_logfile, lb_msg, arg_msg) <> 1 THEN
  227. MessageBox("", arg_msg)
  228. GOTO ext
  229. END IF
  230. filedelete(ls_logfile)
  231. arg_msg = string(lb_msg, EncodingANSI!)
  232. MessageBox('', arg_msg)
  233. ext:
  234. end subroutine
  235. private subroutine f_test1 ();oleobject obj
  236. obj = Create oleobject
  237. IF obj.ConnectToNewObject("PBCOMTest.Class3") <> 0 THEN
  238. MessageBox('', '未连接')
  239. GOTO ext
  240. END IF
  241. String ls_msg
  242. ls_msg = obj.HelloWorld("123")
  243. MessageBox('', ls_msg)
  244. ext:
  245. obj.DisconnectObject()
  246. Destroy obj
  247. end subroutine
  248. private function integer reg32dll (string arg_filepath, ref string arg_msg);Int rslt = 1
  249. IF Not FileExists(arg_filepath) THEN
  250. rslt = 0
  251. arg_msg = arg_filepath + '不存在'
  252. GOTO ext
  253. END IF
  254. String ls_exec = ""
  255. ls_exec = "C:\WINDOWS\system32\regsvr32.exe"
  256. IF Not FileExists(ls_exec) THEN
  257. rslt = 0
  258. arg_msg = ls_exec + "不存在"
  259. GOTO ext
  260. END IF
  261. String ls_logfile
  262. ls_logfile = "tmp_reg.txt"
  263. String ls_logfile1
  264. ls_logfile1 = "tmp_tmp.log"
  265. ls_exec = "~"" + ls_exec + "~" /s ~"" + arg_filepath + "~" > ~"" + ls_logfile1 + "~" 2>&1~r~nrename ~"" + ls_logfile1 + "~" ~"" + ls_logfile + "~""
  266. String ls_tmpfile
  267. ls_tmpfile = "tmp_reg.cmd"
  268. IF FileExists(ls_tmpfile) THEN
  269. FileDelete(ls_tmpfile)
  270. END IF
  271. IF FileExists(ls_logfile) THEN
  272. FileDelete(ls_logfile)
  273. END IF
  274. IF f_blobtofile(ls_tmpfile, Blob(ls_exec,EncodingANSI!), arg_msg) <> 1 THEN
  275. rslt = 0
  276. GOTO ext
  277. END IF
  278. IF Run(ls_tmpfile) <> 1 THEN
  279. rslt = 0
  280. arg_msg = "执行脚本失败," + ls_tmpfile
  281. GOTO ext
  282. END IF
  283. DO WHILE Not FileExists(ls_logfile)
  284. sleep(1)
  285. LOOP
  286. FileDelete(ls_tmpfile)
  287. Blob lb_msg
  288. IF f_filetoblob(ls_logfile, lb_msg, arg_msg) <> 1 THEN
  289. rslt = 0
  290. GOTO ext
  291. END IF
  292. FileDelete(ls_logfile)
  293. String ls_msg
  294. ls_msg = String(lb_msg, EncodingANSI!)
  295. arg_msg = ls_msg
  296. ext:
  297. RETURN rslt
  298. end function
  299. private function integer regdll (string arg_filepath, ref string arg_msg);//====================================================================
  300. // 事件: uo_reghelper.regdll()
  301. //--------------------------------------------------------------------
  302. // 描述: 注册.net的DLL
  303. //--------------------------------------------------------------------
  304. // 参数:
  305. // value string arg_filepath
  306. // reference string arg_msg
  307. //--------------------------------------------------------------------
  308. // 返回: integer
  309. //--------------------------------------------------------------------
  310. // 作者: lwl 日期: 2013年03月23日
  311. //--------------------------------------------------------------------
  312. // LONGJOE
  313. //--------------------------------------------------------------------
  314. // 修改历史:
  315. //
  316. //====================================================================
  317. if ins_win32 then
  318. return reg32dll(arg_filepath, arg_msg)
  319. end if
  320. Int rslt = 1
  321. IF Not FileExists(arg_filepath) THEN
  322. rslt = 0
  323. arg_msg = arg_filepath + '不存在'
  324. GOTO ext
  325. END IF
  326. String ls_regkey
  327. ls_regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework"
  328. String ls_valuename
  329. ls_valuename = "InstallRoot"
  330. String ls_frameworkpath
  331. IF RegistryGet(ls_regkey, ls_valuename, RegString!, ls_frameworkpath) <> 1 THEN
  332. rslt = 0
  333. arg_msg = "没有安装.net Framework"
  334. GOTO ext
  335. END IF
  336. String ls_exec = ""
  337. //IF DirectoryExists(ls_frameworkpath + "v4.0.30319\") THEN
  338. // ls_exec = ls_frameworkpath + "v4.0.30319\"
  339. //ELSEIF DirectoryExists(ls_frameworkpath + "v2.0.50727\") THEN
  340. // ls_exec = ls_frameworkpath + "v2.0.50727\"
  341. //ELSEIF DirectoryExists(ls_frameworkpath + "v1.1.4322\") THEN
  342. // ls_exec = ls_frameworkpath + "v1.1.4322\"
  343. //END IF
  344. string ls_dllname // 获取dll文件名
  345. if LastPos(arg_filepath, '\') > 0 then
  346. ls_dllname = Mid(arg_filepath, LastPos(arg_filepath, '\') + 1)
  347. else
  348. ls_dllname = arg_filepath
  349. end if
  350. long ll_row
  351. string ls_dotnetver
  352. datastore lds_dllmap
  353. lds_dllmap = create datastore
  354. lds_dllmap.DataObject = 'ds_dllmap'
  355. ll_row = lds_dllmap.Find('dllname="' + ls_dllname + '"', 1, lds_dllmap.RowCount())
  356. if (ll_row > 0) then
  357. ls_dotnetver = Trim(lds_dllmap.Object.dotnetver[ll_row])
  358. choose case ls_dotnetver
  359. case '4.0'
  360. IF DirectoryExists(ls_frameworkpath + "v4.0.30319\") THEN
  361. ls_exec = ls_frameworkpath + "v4.0.30319\"
  362. ELSE
  363. rslt = 0
  364. END IF
  365. case '2.0'
  366. IF DirectoryExists(ls_frameworkpath + "v2.0.50727\") THEN
  367. ls_exec = ls_frameworkpath + "v2.0.50727\"
  368. ELSE
  369. rslt = 0
  370. END IF
  371. case '1.1'
  372. IF DirectoryExists(ls_frameworkpath + "v1.1.4322\") THEN
  373. ls_exec = ls_frameworkpath + "v1.1.4322\"
  374. ELSE
  375. rslt = 0
  376. END IF
  377. case else
  378. rslt = 0
  379. end choose
  380. else
  381. IF DirectoryExists(ls_frameworkpath + "v4.0.30319\") THEN
  382. ls_exec = ls_frameworkpath + "v4.0.30319\"
  383. ELSEIF DirectoryExists(ls_frameworkpath + "v2.0.50727\") THEN
  384. ls_exec = ls_frameworkpath + "v2.0.50727\"
  385. ELSEIF DirectoryExists(ls_frameworkpath + "v1.1.4322\") THEN
  386. ls_exec = ls_frameworkpath + "v1.1.4322\"
  387. ELSE
  388. rslt = 0
  389. END IF
  390. end if
  391. if (rslt = 0) then
  392. arg_msg = '本机没有安装.Net Framework ' + ls_dotnetver + '环境,请联系实施人员协助处理'
  393. goto ext
  394. end if
  395. ls_exec = ls_exec + "RegAsm.exe"
  396. IF Not FileExists(ls_exec) THEN
  397. rslt = 0
  398. arg_msg = ls_exec + "不存在"
  399. GOTO ext
  400. END IF
  401. String ls_logfile
  402. ls_logfile = "tmp_reg.txt"
  403. String ls_logfile1
  404. ls_logfile1 = "tmp_tmp.log"
  405. 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 + "~""
  406. String ls_tmpfile
  407. ls_tmpfile = "tmp_reg.cmd"
  408. IF FileExists(ls_tmpfile) THEN
  409. FileDelete(ls_tmpfile)
  410. END IF
  411. IF FileExists(ls_logfile) THEN
  412. FileDelete(ls_logfile)
  413. END IF
  414. IF f_blobtofile(ls_tmpfile, Blob(ls_exec,EncodingANSI!), arg_msg) <> 1 THEN
  415. rslt = 0
  416. GOTO ext
  417. END IF
  418. IF Run(ls_tmpfile) <> 1 THEN
  419. rslt = 0
  420. arg_msg = "执行脚本失败," + ls_tmpfile
  421. GOTO ext
  422. END IF
  423. DO WHILE Not FileExists(ls_logfile)
  424. sleep(1)
  425. LOOP
  426. FileDelete(ls_tmpfile)
  427. Blob lb_msg
  428. IF f_filetoblob(ls_logfile, lb_msg, arg_msg) <> 1 THEN
  429. rslt = 0
  430. GOTO ext
  431. END IF
  432. FileDelete(ls_logfile)
  433. String ls_msg
  434. ls_msg = String(lb_msg, EncodingANSI!)
  435. arg_msg = Lower(ls_msg)
  436. IF Pos(arg_msg, 'error ra0000') > 0 And (Pos(arg_msg, '管理员') > 0 or Pos(arg_msg, 'admin') > 0) THEN
  437. rslt = 0
  438. arg_msg = '注册"' + arg_filepath + '"失败,请以管理员身份运行本程序。详细信息:~r~n~r~n' + arg_msg
  439. ELSEIF Pos(arg_msg, 'success') <= 0 And Pos(arg_msg, '成功') <= 0 THEN
  440. rslt = 0
  441. END IF
  442. ext:
  443. destroy lds_dllmap
  444. RETURN rslt
  445. end function
  446. public function integer unregdll (string arg_filepath, ref string arg_msg);//====================================================================
  447. // 事件: uo_reghelper.regdll()
  448. //--------------------------------------------------------------------
  449. // 描述: 注册.net的DLL
  450. //--------------------------------------------------------------------
  451. // 参数:
  452. // value string arg_filepath
  453. // reference string arg_msg
  454. //--------------------------------------------------------------------
  455. // 返回: integer
  456. //--------------------------------------------------------------------
  457. // 作者: lwl 日期: 2013年03月23日
  458. //--------------------------------------------------------------------
  459. // LONGJOE
  460. //--------------------------------------------------------------------
  461. // 修改历史:
  462. //
  463. //====================================================================
  464. if ins_win32 then
  465. return unreg32dll(arg_filepath, arg_msg)
  466. end if
  467. Int rslt = 1
  468. IF Not FileExists(arg_filepath) THEN
  469. rslt = 0
  470. arg_msg = arg_filepath + '不存在'
  471. GOTO ext
  472. END IF
  473. String ls_regkey
  474. ls_regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework"
  475. String ls_valuename
  476. ls_valuename = "InstallRoot"
  477. String ls_frameworkpath
  478. IF RegistryGet(ls_regkey, ls_valuename, RegString!, ls_frameworkpath) <> 1 THEN
  479. rslt = 0
  480. arg_msg = "没有安装.net Framework"
  481. GOTO ext
  482. END IF
  483. String ls_exec = "",ls_exec1
  484. IF DirectoryExists(ls_frameworkpath + "v4.0.30319\") THEN
  485. ls_exec = ls_frameworkpath + "v4.0.30319\"
  486. ELSEIF DirectoryExists(ls_frameworkpath + "v2.0.50727\") THEN
  487. ls_exec = ls_frameworkpath + "v2.0.50727\"
  488. ELSEIF DirectoryExists(ls_frameworkpath + "v1.1.4322\") THEN
  489. ls_exec = ls_frameworkpath + "v1.1.4322\"
  490. END IF
  491. ls_exec = ls_exec + "RegAsm.exe"
  492. IF Not FileExists(ls_exec) THEN
  493. rslt = 0
  494. arg_msg = ls_exec + "不存在"
  495. GOTO ext
  496. END IF
  497. String ls_logfile
  498. ls_logfile = "tmp_reg.txt"
  499. String ls_logfile1
  500. ls_logfile1 = "tmp_tmp.log"
  501. ls_exec = "~"" + ls_exec + "~" ~"" + arg_filepath + "~" /unregister > ~"" + ls_logfile1 + "~" 2>&1~r~nrename ~"" + ls_logfile1 + "~" ~"" + ls_logfile + "~""
  502. //ls_exec = "~"" + ls_exec + "~"" + " " + arg_filepath + + " /unregister" + "~"" + "/codebase >" + "~"" + ls_logfile1 + "~" 2>&1~r~nrename ~"" + ls_logfile1 + "~" ~"" + ls_logfile + "~""
  503. String ls_tmpfile
  504. ls_tmpfile = "tmp_reg.cmd"
  505. IF FileExists(ls_tmpfile) THEN
  506. FileDelete(ls_tmpfile)
  507. END IF
  508. IF FileExists(ls_logfile) THEN
  509. FileDelete(ls_logfile)
  510. END IF
  511. IF f_blobtofile(ls_tmpfile, Blob(ls_exec,EncodingANSI!), arg_msg) <> 1 THEN
  512. rslt = 0
  513. GOTO ext
  514. END IF
  515. IF Run(ls_tmpfile) <> 1 THEN
  516. rslt = 0
  517. arg_msg = "执行脚本失败," + ls_tmpfile
  518. GOTO ext
  519. END IF
  520. DO WHILE Not FileExists(ls_logfile)
  521. sleep(1)
  522. LOOP
  523. FileDelete(ls_tmpfile)
  524. Blob lb_msg
  525. IF f_filetoblob(ls_logfile, lb_msg, arg_msg) <> 1 THEN
  526. rslt = 0
  527. GOTO ext
  528. END IF
  529. FileDelete(ls_logfile)
  530. String ls_msg
  531. ls_msg = String(lb_msg, EncodingANSI!)
  532. arg_msg = ls_msg
  533. IF Pos(arg_msg, 'success') <= 0 And Pos(arg_msg, '成功') <= 0 THEN
  534. rslt = 0
  535. END IF
  536. ext:
  537. RETURN rslt
  538. end function
  539. public function integer connecttonewobject (string arg_progid, string arg_filepath, ref oleobject arg_ole, ref string arg_msg);//====================================================================
  540. // 事件: uo_reghelper.connecttonewobject()
  541. //--------------------------------------------------------------------
  542. // 描述:
  543. //--------------------------------------------------------------------
  544. // 参数:
  545. // value string arg_progid 类名
  546. // value string arg_filepath DLL路径
  547. // reference oleobject arg_ole 要连接的oleobject
  548. // reference string arg_msg 返回失败信息
  549. //--------------------------------------------------------------------
  550. // 返回: integer
  551. //--------------------------------------------------------------------
  552. // 作者: lwl 日期: 2013年03月23日
  553. //--------------------------------------------------------------------
  554. // LONGJOE
  555. //--------------------------------------------------------------------
  556. // 修改历史:
  557. //
  558. //====================================================================
  559. Int rslt = 1
  560. //IF tryreg(arg_progid, arg_filepath, Ref arg_msg, False) <> 1 THEN
  561. // rslt = 0
  562. // GOTO ext
  563. //END IF
  564. IF arg_ole.ConnectToNewObject(arg_progid) <> 0 THEN
  565. rslt = 0
  566. arg_msg = '连接ole对象失败,' + arg_progid + ',' + arg_filepath
  567. GOTO ext
  568. END IF
  569. ext:
  570. RETURN rslt
  571. end function
  572. public function datetime pf_getfilecreatetime (string arg_filefullpathname);//pf_getfilecreatetime
  573. long rslt
  574. datetime createtime,errdatetime
  575. date ls_date
  576. time ls_time
  577. systemtime ls_systemtime
  578. filetime lpCreationTime ,lpLastAccessTime ,lpLastWriteTime
  579. long li_FileNum
  580. //
  581. li_FileNum = lOpen(arg_filefullpathname,0)
  582. rslt = GetFileTime (li_FileNum ,lpCreationTime ,lpLastAccessTime ,lpLastWriteTime )
  583. li_FileNum=lclose(li_FileNum)
  584. if rslt=0 then return errdatetime
  585. //rslt=FileTimeToSystemTime(lpCreationTime,ls_systemtime)//
  586. rslt=FileTimeToSystemTime(lpLastWriteTime,ls_systemtime)
  587. if rslt=0 then return errdatetime
  588. ls_date=date(string(ls_systemtime.wYear)+'.'+&
  589. string(ls_systemtime.wmonth)+'.'+&
  590. string(ls_systemtime.wDay))
  591. ls_time=time(string(ls_systemtime.wHour)+':'+&
  592. string(ls_systemtime.wMinute )+':'+&
  593. string(ls_systemtime.wSecond ))
  594. createtime =datetime(ls_date,ls_time)
  595. return createtime
  596. end function
  597. public function integer tryreg (string arg_progid, string arg_filepath, ref string arg_msg, boolean arg_if_delete);
  598. Int rslt = 1
  599. Long ll_pos
  600. String ls_path
  601. ls_path = arg_filepath
  602. ll_pos = Pos(ls_path, '\')
  603. IF ll_pos = 0 THEN
  604. IF sys_cur_path = '' THEN
  605. ls_path = pf_getfullpathname(arg_filepath)
  606. ELSE
  607. ls_path = sys_cur_path + arg_filepath
  608. END IF
  609. IF Not FileExists(ls_path) THEN
  610. ls_path = "C:\Windows\SysWOW64\" + arg_filepath
  611. IF Not FileExists(ls_path) THEN
  612. ls_path = "C:\Windows\System32\" + arg_filepath
  613. END IF
  614. END IF
  615. END IF
  616. IF Not FileExists(ls_path) THEN
  617. rslt = 0
  618. arg_msg = '文件不存在,' + ls_path
  619. GOTO ext
  620. END IF
  621. String ls_codebase
  622. ls_codebase = f_codebase(arg_progid)
  623. IF IsNull(ls_codebase) THEN
  624. GOTO reg
  625. END IF
  626. DateTime ld_org_date, ld_cur_date
  627. IF Lower(ls_codebase) <> Lower(ls_path) THEN
  628. IF Lower(ls_codebase) <> "" THEN
  629. IF FileExists(ls_codebase) THEN
  630. // DONE: 如果原来的较新 GOTO con
  631. ld_org_date = pf_getfilecreatetime(ls_codebase)
  632. ld_cur_date = pf_getfilecreatetime(ls_path)
  633. IF ld_cur_date <= ld_org_date THEN
  634. GOTO con
  635. END IF
  636. unregdll(ls_codebase, arg_msg)
  637. END IF
  638. END IF
  639. GOTO reg
  640. END IF
  641. GOTO con
  642. reg:
  643. String ls_msg
  644. IF regdll(ls_path, arg_msg) <> 1 THEN
  645. rslt = 0
  646. GOTO ext
  647. END IF
  648. ls_codebase = f_codebase(arg_progid)
  649. IF IsNull(ls_codebase) THEN
  650. rslt = 0
  651. arg_msg = ls_path + '文件中不存在对象:' + arg_progid + ',请联系软件供应商获取最新文件版本!'
  652. IF arg_if_delete THEN
  653. unregdll(ls_path, ls_msg)
  654. FileDelete(ls_path)
  655. arg_msg += '旧文件已被删除'
  656. END IF
  657. GOTO ext
  658. END IF
  659. IF Lower(ls_codebase) <> Lower(ls_path) THEN
  660. rslt = 0
  661. arg_msg = ls_path + '文件注册失败'
  662. GOTO ext
  663. END IF
  664. con:
  665. ext:
  666. RETURN rslt
  667. end function
  668. public function integer tryreg (string arg_progid, string arg_filepath, ref string arg_msg);return tryreg(arg_progid, arg_filepath, ref arg_msg, false)
  669. end function
  670. private function integer unreg32dll (string arg_filepath, ref string arg_msg);Int rslt = 1
  671. IF Not FileExists(arg_filepath) THEN
  672. rslt = 0
  673. arg_msg = arg_filepath + '不存在'
  674. GOTO ext
  675. END IF
  676. String ls_exec = ""
  677. ls_exec = "C:\WINDOWS\system32\regsvr32.exe"
  678. IF Not FileExists(ls_exec) THEN
  679. rslt = 0
  680. arg_msg = ls_exec + "不存在"
  681. GOTO ext
  682. END IF
  683. String ls_logfile
  684. ls_logfile = "tmp_reg.txt"
  685. String ls_logfile1
  686. ls_logfile1 = "tmp_tmp.log"
  687. ls_exec = "~"" + ls_exec + "~" /s /u ~"" + arg_filepath + "~" > ~"" + ls_logfile1 + "~" 2>&1~r~nrename ~"" + ls_logfile1 + "~" ~"" + ls_logfile + "~""
  688. String ls_tmpfile
  689. ls_tmpfile = "tmp_reg.cmd"
  690. IF FileExists(ls_tmpfile) THEN
  691. FileDelete(ls_tmpfile)
  692. END IF
  693. IF FileExists(ls_logfile) THEN
  694. FileDelete(ls_logfile)
  695. END IF
  696. IF f_blobtofile(ls_tmpfile, Blob(ls_exec,EncodingANSI!), arg_msg) <> 1 THEN
  697. rslt = 0
  698. GOTO ext
  699. END IF
  700. IF Run(ls_tmpfile) <> 1 THEN
  701. rslt = 0
  702. arg_msg = "执行脚本失败," + ls_tmpfile
  703. GOTO ext
  704. END IF
  705. DO WHILE Not FileExists(ls_logfile)
  706. sleep(1)
  707. LOOP
  708. FileDelete(ls_tmpfile)
  709. Blob lb_msg
  710. IF f_filetoblob(ls_logfile, lb_msg, arg_msg) <> 1 THEN
  711. rslt = 0
  712. GOTO ext
  713. END IF
  714. FileDelete(ls_logfile)
  715. String ls_msg
  716. ls_msg = String(lb_msg, EncodingANSI!)
  717. arg_msg = ls_msg
  718. ext:
  719. RETURN rslt
  720. end function
  721. public function string pf_getfullpathname (string arg_filename);//f_init_syscurpath(arg_msg)
  722. Long rslt = 1
  723. String lpBuffer
  724. lpBuffer = Fill('',200)
  725. Long lpfilepart,li_FileNum
  726. rslt = GetFullPathName(arg_filename,196,lpBuffer,lpfilepart)
  727. IF rslt = 0 THEN
  728. return arg_filename
  729. ELSE
  730. sys_cur_path = Left(lpBuffer,Len(lpBuffer)-Len(arg_filename))
  731. return lpBuffer
  732. END IF
  733. end function
  734. on uo_reghelper.create
  735. call super::create
  736. TriggerEvent( this, "constructor" )
  737. end on
  738. on uo_reghelper.destroy
  739. TriggerEvent( this, "destructor" )
  740. call super::destroy
  741. end on