Solved

Replace the current running exe

Posted on 2004-09-27
5
300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

759 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