Solved

Replace the current running exe

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

707 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

15 Experts available now in Live!

Get 1:1 Help Now