Solved

Replace the current running exe

Posted on 2004-09-27
5
298 Views
Last Modified: 2011-10-03
Hi all,

(note this is related to another question which i will post the url to once i submit the question)
I'm writing a application that will eventually have little 'agents' that are running on about 70 computers on a WAN.

Basically, I have a central application that via tcp/ip sends xml commands to these agents, which in turn do 'stuff' based on the xml commands and return a result.

Because the only way i have access to these agents is via a ssh tunnel and vnc, i decided that i really dont want to log onto by opening the tunnel and a vnc session 70 times whenever i need to upgrade the exe. Instead, I have a system where dll's are dynamically loaded based on a config file. the idea being i can just send a xml command (and some binary data) to add new dlls and update the config file so the agent knows how to respond to new xml commands (or to fix any problems in existing dlls).

PROBLEM: In the event that i need to replace the agent exe itself, i need to also do this remotely. How do i replace an exe that is running at the time? I guess the short answer is that I cant, so what is an alternative to upgrade the exe remotely.

NOTE: i cannot use 2 ports, so I cannot have a second applicaiton running always listening on a second port to receive an upgrade to the first exe.

Thanks in advance for your help.
0
Comment
Question by:gimmeadrink
  • 3
5 Comments
 
LVL 2

Author Comment

by:gimmeadrink
ID: 12159901
0
 
LVL 1

Accepted Solution

by:
VBtorment earned 125 total points
ID: 12162568
Send the updated exe and switcher.exe to the client (agent.upd)
Send a command on the first port, when it says 'update' the start the second app (switcher.exe) and unload agent.exe

In the Switcher app have a timer running (about 5 seconds or if takes longer for agent.exe to unload...)

when the timer shoots remove agent.exe and rename agent.upd too agent.exe and start agent.exe (the new one)
unload switcher

Code for switcher:

you need:
Basic form with a timer (you can use the timer to countdown for restart)
a Label

Option Explicit
Private iCount%

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1


Private Sub Form_Load()
    iCount% = 5
    Timer1.Interval = 1000
    Timer1.Enabled = True
    Label1.Caption = "5 seconds for restart of agent"
End Sub

Private Sub Timer1_Timer()
    iCount% = iCount% - 1
    Label1.Caption = iCount% & " seconds for restart of agent"
    If iCount% = 0 Then
        ShellExecute Me.hwnd, vbNullString, App.Path & "\agent.exe", vbNullString, "C:\", SW_SHOWNORMAL
        Unload Me
    End If
End Sub
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12164414
Or, if you don't want a second executable, you could use the existing connection to send the agent a script to run.  It would perform the same steps that VBtorment described.  
0
 
LVL 2

Author Comment

by:gimmeadrink
ID: 12164667
VBtorment: I like the idea.... ill give it a go today and get back to ya.

Thanks
0
 
LVL 2

Author Comment

by:gimmeadrink
ID: 12168727
yep, works nicely, thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question