Link to home
Start Free TrialLog in
Avatar of Marcusw
Marcusw

asked on

close app

I have an app lets say APP1 that checks for an updated exe.  if APP1.exe has been updated it uses the shell command to run another app lets say APP2 that copys the file to the users machine and renames it. Then i want the app to shut down the APP1 and delete it. Then rename the updated exe then run the APP1 agian

the code i have is

APP1 Code
******************************************
Private Sub Form_Load()
Set FSys = CreateObject("Scripting.FileSystemObject")

Set SourceFile = FSys.getfile("C:\APP1.exe")
SourceFileDateModified = SourceFile.DateLastModified
MsgBox (SourceFileDateModified)

Set CurrentFile = FSys.getfile("\\Machineserver\Database\APP1.exe")
CurrentFileDateModified = CurrentFile.DateLastModified
MsgBox (CurrentFileDateModified)

If SourceFileDateModified <> CurrentFileDateModified Then
Shell "c:\APP2.exe", vbHide
Unload frmLogin
End If
End Sub
****************************************

APP2 code
****************************************
Private Sub Form_Load()
Dim FSys As New Scripting.FileSystemobject

FSys.copyfile "\\Machineserver\Database\APP1.exe", "c:\APP1.tmp", overwrite

'Code to close APP1

Kill "c:\APP1.exe"
Name "c:\APP1.tmp" As "c:\APP1.exe"
Shell "c:\APP1.exe", vbNormalFocus
Unload Form1
End Sub
*********************************************
ASKER CERTIFIED SOLUTION
Avatar of SilentRage
SilentRage

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SilentRage
SilentRage

oh yeah, almost forgot.  How do you find the window title and class you say?  There's a nifty program that comes with Visual Studio Professional called Spy++.  Take a peek at it.  With it you can find the class and title of any window.  Just open your app1, and make sure it stays open.  Then use Spy++ FindWindow feature to highlight the window of which you'd like to collect information about.  Then you may use my above code.
But your code still copies over the executable before closing down the app. You should first close the app, then copy your file, then start it back up again. aviods any file locking issues that may occur.
my first example included deleting the old app.  My last 2 code examples were just close app functions meant to replace the

'Code to close APP1

in his example.
Avatar of Marcusw

ASKER

Fantastic thanks, i still a newbie so all your code and suggestions are very useful