Solved

Replace the current running exe

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
Suggested Courses
Course of the Month10 days, 5 hours left to enroll

623 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