Solved

Replace the current running exe

Posted on 2004-09-27
5
295 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now