给你的程序添加自动升级功能竟如此简单
只需要在你的程序最前面添加一句"=程序自动升级()",你的程序就拥有了自动升级的功能,当然幕后你需要及时把升级的程序上传到服务器,供下载更新使用代码非常粗糙,请建言献策完善它
PROCEDURE 程序自动升级
Declare Long InternetGetConnectedStateEx In "wininet.dll" Long @, String@, Long, Long
DECLARE INTEGER URLDownloadToFile IN urlmon.dll INTEGER pCaller, STRING szURL,STRING szFileName, INTEGER dwReserved,INTEGER lpfnCB
Declare Integer WinExec in kernel32 string, integer
LOCAL inifile,cRemoteFileini,cRemoteFileexe,selfname,lcCMD,Install,nname,cLocalFile,cRemoteFile,nResult,aa,sjmcm,nResult
mmver="0.00" &&版本号,可以隐式存在,但必须有且递增
inifile="softini.ini" &&这个文件名称请保证唯一且固定(临时文件夹下),用于存放升级文件信息
cRemoteFileini = "http://****/update.ini" &&文件升级信息下载地址,包含升级文件特征信息。内容(版本号(4))
cRemoteFileexe = "http://****/******.exe" &&升级文件下载地址,目前只是升级主程序
selfname=_GetAllProcessID()
IF file(addbs(sys(2023))+inifile)
lcCMD = 'taskkill /f /im '+JUSTFNAME(FILETOSTR(addbs(sys(2023))+inifile))
oWsh = CreateObject("wscript.shell")
oWsh.Run(lcCMD, 0, .T.)
ERASE (filetostr(addbs(sys(2023))+inifile))
STRTOFILE(FILETOSTR(selfname),filetostr(addbs(sys(2023))+inifile))
STRTOFILE(selfname,addbs(sys(2023))+inifile+"_")
MESSAGEBOX("升级完成,马上重启软件",64+4096,"温馨提示",5000)
lcCMD=filetostr(addbs(sys(2023))+inifile)
ERASE (addbs(sys(2023))+inifile)
winexec(lccmd,5)
quit
endif
IF file(addbs(sys(2023))+inifile+"_")
lcCMD = 'taskkill /f /im '+JUSTFNAME(FILETOSTR(addbs(sys(2023))+inifile+"_"))
oWsh = CreateObject("wscript.shell")
oWsh.Run(lcCMD, 0, .T.)
ERASE (filetostr(addbs(sys(2023))+inifile+"_"))
ERASE (addbs(sys(2023))+inifile+"_")
endif
Install = 0
nName = SPACE(513)
If InternetGetConnectedStateEx(@Install, @nName, 512, 0) > 0 &&网络已连接
cLocalFile = ADDBS(SYS(2023))+SYS(3)+TRANSFORM(GetCurrentProcessId())+".ini" &&本地文件名
cRemoteFile = cRemoteFileini
nResult = URLDownloadToFile(0, cRemoteFile, cLocalFile, 0,0)
IF nResult = 0
aa=fiLEtostr(cLocalFile)
ERASE (cLocalFile)
IF aa>mmver
MESSAGEBOX("软件有新版本,为了数据安全请及时升级"+CHR(13)+CHR(10)+"现在准备升级...",64+4096,"温馨提示")
sjmcm= ADDBS(SYS(2023))+SYS(3)+TRANSFORM(GetCurrentProcessId())+".exe" &&本地文件名
cRemoteFile = cRemoteFileexe
nResult = URLDownloadToFile(0, cRemoteFile, sjmcm, 0,0)
IF nResult = 0
ERASE (addbs(sys(2023))+inifile)
STRTOFILE(selfname,addbs(sys(2023))+inifile)
winexec(sjmcm,0)
else
MESSAGEBOX("文件下载失败",64,"温馨提示")
endif
quit
endif
ENDIF
ENDIF
RETURN
FUNCTION _GetAllProcessID ()
local CurrentProcessid,lcTitle,th32ProcessID,dwsize,szexefile
DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject
DECLARE Long GetModuleFileNameEx IN PsApi Long hProcess, Long hModule, String @ lpExename, Long dwSize
DECLARE Long OpenProcess IN WIN32API Long dwDesiredAccess, Long bInheritHandle, Long dwProcessId
Declare Integer GetCurrentProcessId In kernel32.Dll
CurrentProcessid=GetCurrentProcessid()
lcTitle = bintoc(296,"4rs") + REPLI(CHR(0),292)
th32ProcessID = OpenProcess( 0x10 + 0x400, 0, CurrentProcessid)
dwSize = 260
szExeFile = REPLICATE( CHR(0), dwSize )
IF ( th32ProcessID>0 )
dwSize = GetModuleFileNameEx( th32ProcessID, 0, @szExeFile, dwSize )
CloseHandle( th32ProcessID )
endif
szExeFile = STREXTRACT(szExeFile,"",CHR(0))
RETURN szexefile








