Implement the program automatic upgrade in VFP
From: http://huanqiu.51.net/vfp/26.htm
When developing and using a C / S working method, it is often encountered by the program upgrade. It is often used in manual copying, which is very cumbersome when the network has become increasingly huge. Can you automatically update local programs when you update like many network programs? After two days, the author refers to some information, and the automatic upgrade function of the program is implemented under VFP. Basic ideas are automatically updated from the specified FTP server through the upgrade program to update the program. Basic operating environment of the program: VFP7 WIN98 (Win2000), server: FTP server, the program is running normal. For VFP5, the program should be run, but there is no test. Implementing the method in other languages should be the same.
first step
The judgment program needs to be upgraded. The easiest way is to set a version constant in the program, compare the latest version number of the program set in the remote library when the program starts. If you are older than the version number in the far library, the upgrade program is executed. Since the running program is not overwritten, there is a separate upgrade program to be upgraded. Assume that the name of this program is update.exe, also compiled with VFP, then run this upgrade program in the main program:
Declare Integer SHELLEXECUTE IN Shell32.dll Integer, String, String, String, String, Integer
= Shellexecute (0, 0, 'update.exe', 0, 0, 1)
At the same time, use the Quit command to exit the main program.
Second step
Update using the upgrade program. The main upgrade procedures are as follows (in use, you need to modify the following procedure according to the actual situation. In order to make beautiful and actual use, you can create a form to implement the selection of the upgrade server, the username, and password input).
#Define internet_INValid_port_number 0
#Define internet_open_type_direct 1
#Define internet_open_type_proxy 3
#Define internet_default_ftp_port 21
#Define internet_flag_async 268435456 && & H10000000
#Define internet_flag_from_cache 16777216 && & H1000000
#Define internet_flag_offline 16777216
#Define internet_flag_cache_if_net_fail 65536 && & H10000
#Define internet_open_type_preconfig 0
#Define fTP_TRANSFER_TYPE_ASCII 1
#Define fTP_TRANSFER_TYPE_BINARY 2
#Define Internet_Service_FTP 1
#Define internet_service_gopher 2
#Define internet_service_http 3
#Define file_attribute_normal 128 && 0x00000080
Declare Integer Internetopen in Wininet;
String Sagent, Integer LaccesSstype, String Sproxyname ,;
String sproxybypass, string lflags
Declare Integer InternetCloseHandle In Wininet Integer IntegerTConnect in Wininet
Integer HinternetSession, String SSERVERNAME ,;
Integer Nserveport, String SUSERNAME ,;
String spassword, integer lservice ,;
Integer Lflags, Integer LCONText
Declare integer ftpgetfile in wininet;
Integer Hftpsession, String Lpszremotefile ,;
String lpsznewfile, integer ffailifexists ,;
Integer dwflagsandattributes ,;
Integer dwflags, integer dwcontext
SAGENT = "" var1 ""
Sproxyname = chr (0)
SproxyByPass = CHR (0)
LFLAGS = 0
Hopen = Internetopen (SAGENT, Internet_Open_TYPE_DIRECT, "
SproxyName, SproxyBypass, LFLAGS)
IF Hopen = 0
= MessageBox ("" Cannot find the entrance "", 16, "Warning" ")
Return
ENDIF
* Modify your own FTP server data here
strHost = "ftp.abc.com" "&& stores the FTP server address of the upgrade file
Struser = "" User "&& upgrade FTP username
StrPwd = "1111" && ftp user password
HFTPSession = InternetConnect (Hopen, Strhost ,;
Internet_INValid_port_number ,;
Struser, StrPwd ,;
Internet_Service_FTP, 0, 0)
IF hftpsession = 0
= InternetCloseHandle (Hopen)
= MessageBox ("" Can't find the specified server "", 16, "warning")
Return
ENDIF
* The following sets of FTP path and file name
Lpszremotefile = "/aaa.exe" "The path and file name on && ftp
LPSZNewFile = "" ./aaa.exe "&& download to local paths and file names, default in the same directory
FFailifexists = 0 && If this file already exists, it is overwritten directly, do not ask questions
DWCONText = 0
lnResult = ftpgetfile (HFTPSession, lpszremotefile, lpsznewfile ,;
FFailifexists, file_attribute_normal, ftp_transfer_type_ascii ,;
DWCONText) = InternetCloseHandle (HFTPSession)
= InternetCloseHandle (Hopen)
IF lnResult # 1
= MessageBox ("" upgrade failed! Please check if the username and password are correct. "", 16, "Warning")
Else
= MessageBox ("" Upgrade is successful! Please quit the upgrade program. "", 64, "Tips")
ThisForm.Release && upgrade successs automatically leaves your form
ENDIF
Return
third step
Use and call the same method as the upgrade program, run the main program to exit the upgrade program, complete the upgrade process of the program.