Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

Updating System

Hello experts!

I have a Product based on a few Delphi applications (.EXE). This Product runs on several PCs in several cities in my country. We started out with a few locations, so I could update the applications with little effort. But now the project is growing fast, so I need to build an update system for the applications (like anti-virus application).

What’s the best way to do that?

This is what I have in mind so far:

All PCs are already connected to a main MySQL server. And one of the applications already works with FTP.  I could store the latest version of each application on MySQL, and I could build a program that would check the version of each application, download the new .EXEs when necessary, and install them. To install them, I would just have to stop the running application and copy the new EXE over the old one. I just don’t know how can I close a running application! How to I do that?

Or is there a better way to do that?

Oh, and this has to be completely standalone, the PCs don’t have any human operator. The process must be automatic.

Thanks a lot.
0
rogerbrito
Asked:
rogerbrito
1 Solution
 
DragonSlayerCommented:
A "simple" way would be to execute a batch file. Because if a process is running, the executable image cannot be deleted. Therefore, if you download (via FTP) the update and call it, say myprog.bak and the original programme is myprog.exe, you can have a batch file as follows:

@echo off
:DoDelete
del myprog.exe
if exist myprog.exe goto DoDelete
ren myprog.bak myprog.exe
myprog.exe

You would then execute the batch file and terminate self (either by closing the main form or Application.Terminate).


DragonSlayer.
0
 
TheRealLokiSenior DeveloperCommented:
if the running application has a form, you can do a FindWindow, and send a WM_Close message to it
e.g.

ahandle := FindWindow('Notepad', 'Untitiled - Notepad'); // class name, window name e.g. FindWindow('TForm1', 'Form1')

if aHandle <> 0 then
  sendmessage(aHandle,wm_Close,0,0);
or
  sendmessage(aHandle,wm_Destroy,0,0);
or
  sendmessage(aHandle,wm_CancelMode,0,0); // to close a dialog first, then call the wm_close

If it is a service, you can just do
Net Stop [servicename]
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now