Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing Application on Remote machine across network

Status
Not open for further replies.

DomAntPallot

Programmer
May 26, 2007
16
GB
Hello.

I need to be able to close an application on another machine to perform updates.

The machine is connected via a small network.

I know how to close applications on the same machine but I can not work out how to do it across the network.
 
If the "application" in question is coded by you, I have several suggestions. If not, (someone else wrote it) then I'm still thinking...
Which is it?

Roo
Delphi Rules!
 
And I'm guessing you want to programatically check if it's open and close it if it is?


Leslie

In an open world there's no need for windows and gates
 
Hi DomAntPallot,

I'd probably make a small server server program (in Delphi) and place it on the remote machine.

If you create a new application and drop a IdHTTPServer onto it (IdHTTPServer is in the Indy components tab), this application will act as a server. You can set it to a specified port, i.e. 6000 then send it commands. If you then set the CommandGet event for the server, you can close the application you want, as this will be code running locally on that machine.
If the machines name was test, issuing the command http:\\test:6000?action=close in a web browser would fire the CommandGet event.

Your commandGet event would look something like this:
Code:
procedure TfrmWebServer.IdHTTPServer1CommandGet(AThread: TIdPeerThread;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  sAction: String;
begin
   AResponseInfo.ContentType := 'text/html';

  if (ARequestInfo.Params.Values['action'] <> '') then
    begin
      sAction := ARequestInfo.Params.Values['action'];
      if (sAction = 'close') then 
        // fire the procedure to close the application
    end;
end;

This is handy as it will work through a web browser, so you can do it without using another program to communicate. You do have other options rather then using an IdHTTPServer, such as UDP (IdUDPServer) or TCP (IdTCPServer), howerver you will need to write a delphi program with the equivalent IdUDPClient or IdTCPClient to send requests to the program.

There may be a possibility that you can use WMI (Windows Management Instrumentation). I know that you can query what processes are running, but I am not 100% that you can close and application using WMI. I'll leave it up to you to research.

Hope this helps,
Adam
 
Well I have an application that is used here by several users. I've placed a shortcut on their desktops that calls a batch file. It checks various drive maps, then calls program UpdateChk.exe that I also wrote. UpdateChk compares the date of my application, lets call it "Program1.exe". It compares the date of the exe on a server shared folder with the "Program1.exe" in their C:\Program files\<folder name>\
If it (the server copy) is newer, it overwrites it with the new one, then launches it from C:. If not, it just launches the existing one. This guaranties that everyone has the latest version every time they open the application via the shortcut.

I know this doesn't answer "how to terminate across the network", but it works for me. In my case, I felt that terminating a database application while users may be in the middle of data entry or running a query might not be such a good idea.

You're welcome to my code for UpdateChk if you think that it will work for you...


Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top