Results 1 to 20 of 20

Thread: [RESOLVED] [2005] Download new .EXE and switch to new version

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Resolved [RESOLVED] [2005] Download new .EXE and switch to new version

    We've got this pocket PC app - but this is a general .Net question...

    This app will detect that a new version of the .EXE is available - and actually download it through the SQL CLIENT connection from the network server database. We are already storing images in the network server database - so I'm pretty sure I can store a .EXE as well.

    I was thinking that I would "write" the new .EXE to the same folder as the current .EXE - but with a different name.

    Now the question - how do I chain out to a .BAT file, for instance - that will rename the old .EXE and also rename the new app to take it's place?? I'm pretty sure that the rename operation cannot occur while the app is running (I've seen this fact on regular workstation installs of .EXE's - they are locked while they are running).

    So I need to get into a .BAT file (or a little "rename .exe") and have the app itself close - so the rename operations can occur.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2005] Download new .EXE and switch to new version

    What I do is create a second app (called appUpdater) When the application starts I call a check to see if a newer version is stored on a known location (based on date/time of the files). If the running apps date/time is the same or greater then the version stored in the update dir then app continues to load. If the update location has a newer version of the app then the app calls appUpdater and exits. The appUpdater copies the new file (doing an overwrite) then calls the actuall app to start again and exits itself.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005] Download new .EXE and switch to new version

    Here's how we did this (although it was for a desktop app, not a mobile, but I think the principle is the same.)
    We have an AppLauncher application that gets run first, basically a bootstrapper. It checks for a new version, installs it, then essentially shells out to the actual app itself. This ensures the app isn't in use when we try to overwrite it. The applauncher should never need to be updated since all it is is a shell.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [2005] Download new .EXE and switch to new version

    ok - ok...

    Now the million dollar question - what is the .Net code for doing this shell or app call type stuff??

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2005] Download new .EXE and switch to new version

    Process.Start(Filenamewithpath) MSDN
    Please mark you thread resolved using the Thread Tools as shown

  6. #6

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [2005] Download new .EXE and switch to new version

    Quote Originally Posted by danasegarane
    Process.Start(Filenamewithpath)
    And I can exit the app itself immediately...

    ...does the Process.Start start the new app immediately?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2005] Download new .EXE and switch to new version

    Here is what I use to check:

    vb.net Code:
    1. Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
    2.             'We Need to generate the Config File if not present
    3.             'Config will hold the database type, Database Location, Database Name and the UpdateDirectory
    4.             Try
    5.                 If Not FileIO.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\Config.ini") Then
    6.                     frmConfig.ShowDialog()
    7.                 End If
    8.                 If Not FileIO.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\Config.ini") Then
    9.                     MessageBox.Show("You must configure your database and update path to use this application.", "Database Configuration Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    10.                     e.Cancel = True
    11.                 End If
    12.                 'OK we have a Config file now we test newer stuff
    13.                 'f1 stuff is the Report DLL
    14.                 'f2 struff is the application
    15.                 'f3 struff is the config file
    16.                 Dim objIniFile As clsIniFile
    17.                 objIniFile = New clsIniFile(My.Application.Info.DirectoryPath & "\Config.ini")
    18.                 Dim strTName As String = objIniFile.GetString("Configuration", "UpdatePath", "")
    19.                 Dim strUpdatePath As String = strTName & "\"
    20.                 Dim strLocalPath As String = My.Application.Info.DirectoryPath & "\"
    21.                 Dim f1Update As Date = IO.File.GetLastWriteTime(strUpdatePath & "RSMReports.dll")
    22.                 Dim f2Update As Date = IO.File.GetLastWriteTime(strUpdatePath & "RSM.exe")
    23.                 Dim f3Update As Date = IO.File.GetLastWriteTime(strUpdatePath & "config.ini")
    24.                 Dim f1Local As Date = IO.File.GetLastWriteTime(strLocalPath & "RSMReports.dll")
    25.                 Dim f2Local As Date = IO.File.GetLastWriteTime(strLocalPath & "RSM.exe")
    26.                 Dim f3Local As Date = IO.File.GetLastWriteTime(strLocalPath & "config.ini")
    27.  
    28.                 If f1Local < f1Update Then
    29.                     IO.File.Copy(strUpdatePath & "RSMReports.dll", strLocalPath & "RSMReports.dll", True)
    30.                 End If
    31.                 If f3Local < f3Update Then
    32.                     IO.File.Copy(strUpdatePath & "config.ini", strLocalPath & "config.ini", True)
    33.                 End If
    34.                 If f2Local < f2Update Then
    35.                     Process.Start(strLocalPath & "RSMUpdater.exe")
    36.                     e.Cancel = True
    37.                 End If
    38.             Catch ex As Exception
    39.             End Try
    40.         End Sub
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  8. #8
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2005] Download new .EXE and switch to new version

    Yes it will start the application Immediately
    Please mark you thread resolved using the Thread Tools as shown

  9. #9

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [2005] Download new .EXE and switch to new version

    Here's the rub...

    I really have to get the .EXE from the database - as PPC's don't talk to the network very well...

    So the main app itself is the one that does the authentication and gets the SQL Client connection to the network database server.

    So being that the "discovery" of the new .exe is done by the .exe itself - I'll have that do the download.

    And I guess I'll fool with the Process.Start and startup a .BAT file - I can have the .BAT file be created by the old app .exe itself prior to doing the Process.Start.

    I just have to work in a pause of some kind to insure that the old app .exe is closed...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  10. #10
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Download new .EXE and switch to new version

    I don’t think there is need to write a separate application for update. If you are using .Net Setup than all you need is to add a Class library project and add to it an installer class. In the installer class you add BeforeInstall and AfterInstall events. In the BeforInstall event you write code that will detect if the app is running (you can use Process class for this), if it does than simply call the main form close method of the process. In the AfterInstall event you put the code that will lunch the app. Finally, in the Setup project of the app, under custom actions you add the primary output of the class library under Install folder.

  11. #11

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [2005] Download new .EXE and switch to new version

    @VBDT - that seems interesting - I'll look into it...

    Do you think it will work with the PPC and the fact that the new .EXE is in a database?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005] Download new .EXE and switch to new version

    VBDT - Ok.... I get it.... but how does the install get launched then? :blink: OOoooohh.... I get it. I think... the app looks to see if there's a new install available, and if so, launches it, which will then close the main app... install, then re-launch the app... if I read that right. I'm not sure I get how the app gets shut down in the first place.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [2005] Download new .EXE and switch to new version

    Are we talking about the actual INSTALL running again?

    I don't need that - just a copy in of a new .EXE...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  14. #14
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005] Download new .EXE and switch to new version

    szlamany - I think in your case... what you are looking to do will have to do... since it's the main app that gets the login info, which is needed to grab the exe from the database, copy it to new name then shell to something that renames it and launches it.

    It's simple to do, and not all that complicated.

    There's one other option, but it's a little more involved. For something this simple, I don't know if it would be worth the effort.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  15. #15
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Download new .EXE and switch to new version

    I think it should work. I think it doesn’t matter where the setup is unless it can be run from that location. At list you can copy the setup to the computer and run it.

  16. #16
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Download new .EXE and switch to new version

    Quote Originally Posted by techgnome
    VBDT - Ok.... I get it.... but how does the install get launched then? :blink: OOoooohh.... I get it. I think... the app looks to see if there's a new install available, and if so, launches it, which will then close the main app... install, then re-launch the app... if I read that right. I'm not sure I get how the app gets shut down in the first place.

    -tg
    Yes that is correct. The application checks to see if there is a new version, if there is than it lunches the setup. The setup its turn shuts down the app if it is running and installs the new app. After all it lunches the app.

  17. #17
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005] Download new .EXE and switch to new version

    I still don't get how the installer shuts down the app...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  18. #18
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Download new .EXE and switch to new version

    This code goes in to the installer class as I explained in my previous post.
    vb Code:
    1. Imports System.ComponentModel
    2. Imports System.Configuration.Install
    3.  
    4. Public Class Installer1
    5.  
    6.     Public Sub New()
    7.         MyBase.New()
    8.  
    9.         'This call is required by the Component Designer.
    10.         InitializeComponent()
    11.  
    12.         'Add initialization code after the call to InitializeComponent
    13.  
    14.     End Sub
    15.  
    16.     Private Sub Installer1_AfterInstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles Me.AfterInstall
    17.         Dim p As New Process
    18.         p.StartInfo.FileName = "C:\Program Files\Default Company Name\Setup2\DeviceApplication1.exe"
    19.         p.Start()
    20.     End Sub
    21.  
    22.     Private Sub Installer1_BeforeInstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles Me.BeforeInstall
    23.         For Each p As Process In Process.GetProcesses
    24.             If p.MainWindowTitle = "Form1" Then
    25.                 p.CloseMainWindow()
    26.             End If
    27.         Next
    28.     End Sub
    29. End Class

  19. #19
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005] Download new .EXE and switch to new version

    Looping through the processes... I figured... and you';d need to knwo the caption... if there is one... seems like there should be a more elegant way going about doing this../...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  20. #20

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [2005] Download new .EXE and switch to new version

    Ok - I dropped the idea for a .BAT file and I'm instead using a little update program written in .net.

    This is still in prototype - but it's working and should easliy be moved into production from here.

    I'm actually storing the UPDATE program in the database as well - it gets downloaded first then the application gets downloaded and then we Process.Start to the UPDATE program to finish the job.

    Code:
    Imports System.IO
    
    Module APCUpd
    
        Sub Main(ByVal args As String())
    
            Dim s1 As String = args(0).Replace("~", " ")
    
            MsgBox(s1)
    
            File.Move(Path.Combine(s1, "APC1.txt"), Path.Combine(s1, "APC2.txt"))
    
        End Sub
    
    End Module
    This is actually stored in a database on a network server and "dropped" onto a pocket PC with this code

    Code:
    Dim ExeData As Byte() = DirectCast(LDrc.ExecuteScalar, Byte())
    
    Dim fs As New FileStream(Path.Combine(strBaseFolder, "APCUpd.exe"), FileMode.CreateNew)
    Using bw As BinaryWriter = New BinaryWriter(fs)
        bw.Write(ExeData)
        bw.Close()
    End Using
    And then it's run with this:

    Code:
    Process.Start(Path.Combine(strBaseFolder, "APCUpd.exe"), strBaseFolder.Replace(" ", "~"))
    The reason for the tilde replace is that spaces were causing multiple "arguments" to be passed into the SUB MAIN()

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width