软件自动升级,未测试
***********************************************************
*-功能介绍:软件自动升级
*-调用方式:
*-upstr = 'RUN /N AutoUpdate.EXE "'+SYS(16,0)+'" '+ALLTRIM(STR(_VFP.ProcessId))+' "'+'新程序文件名"
*-&upstr
*-恋鱼猫
*-XINGHE SOFT 2005.11.16
***********************************************************
PARAMETERS MainProName,cProcID,TmpProName
IF PARAMETERS()<>3
RETURN .F.
ENDIF
ProcID = VAL(cProcID)
Declare ExitProcess IN kernel32 INTEGER uExitCode
IF FILE(MainProName) AND FILE(TmpProName)
Declare integer TerminateProcess in kernel32 integer hProcess , integer uExitCode
Declare integer OpenProcess in kernel32 integer dwDesiredAccess, integer binheritHandle, integer dwProcessId
Declare SHORT SetFileAttributes IN kernel32 STRING lpFileName,INTEGER dwFileAttributes
hproc = OpenProcess(2035711, 0, ProcId)
= TerminateProcess(hproc, 0) &&杀掉原程序
setfileattributes((MainProName), 0) &&去掉属性(防止只读禁写)
isIn = .T.
ON ERROR isIN = .T.
DO WHILE isIN &&用循环确保一定删除了原程序
DELETE FILE (MainProName)
IF !FILE(MainProName)
iSin = .F.
ENDIF
ENDDO
ON ERROR
RENAME (TmpProName) TO (MainProName) &&改名
MESSAGEBOX('升级成功,系统将自动运行新程序!',64,'信息',2000)
cDOS = 'RUN /N '+MainProName
&cDos
ELSE
MESSAGEBOX('升级失败,请手工将安装目录内的XHPRO.TMP更名为XHPRO.EXE!',48,'提示')
ENDIF
ExitProcess(14) &&退出升级程序
把上面这个编译成EXE,调用方法:
upstr = 'RUN /N AutoUpdate.EXE "'+SYS(16,0)+'" '+ALLTRIM(STR(_VFP.ProcessId))+' "'+'新程序文件名"
&upstr
*********修必远***********留言××××××××
*最终也是一个程序调用另一个程序
*下面是vfp的更新程序(仅是个例子,需要更改路径及程序名):
local lccomp,xx,oldexedate,oldexesize
set talk off
set safe off
lccomp=set("compatible")
set compatible on
xx=curdir()+"salesnew.exe"
oldexedate=fdate('&xx')
oldexesize=fsize('&xx')
if oldexedate<>fdate('\\ntserver\sales-setup\salesnew.exe') or oldexesize<>fsize('\\ntserver\sales-setup\salesnew.exe')
if messagebox(" 注意:软件已经修改!请选择是否更新?"+;
chr(13)+chr(13)+"是:自动从服务器更新软件; 否:不更新。"+;
chr(13)+chr(13)+"(菜单权限的设定请与资讯科或营业部联系)",4+32+256,"更新提示")=6
wait windows "正在复制文件,请稍侯......" nowait at 20,50
copy file \\ntserver\sales-setup\salesnew.exe to (xx)
wait clear
endif
endif
set compatible &lccomp
!/N1 &xx