-
December 1st, 2010, 04:26 AM
#1
Restart running application (C#, VS2010, Dotnet 2.0)
Hi
I have a program that is going to autoupdate itself if there is a new version on a ftp. After the update its supposed to restart itself, here is also the problem.
I have read and tried lots of things but cant really get this to work, any ideas on how to do this would be much appreciated.
Code:
Code:
private void Form1_Load(object sender, EventArgs e)
{
// Check if we have internet access
if (IsConnected())
{
// Check FTP for a new version
if (checkIfWeNeedAUpdate())
{
// Download new version to same folder as startup and named newVikingKundTerminal.exe
if (downloadNewVersion())
{
// Set new modified datetime so we wont download new version again
updateModifiedDatetime(remoteFile);
// Restart program
restartApplication();
}
}
}
else
{
// No internet, run in offline mode
}
private void restartApplication()
{
try
{
if(File.Exists(Application.StartupPath + @"\oldVikingKundTerminal.exe"))
{
File.Delete(Application.StartupPath + @"\oldVikingKundTerminal.exe");
}
File.Move(Application.StartupPath + @"\VikingKundTerminal.exe", Application.StartupPath + @"\oldVikingKundTerminal.exe");
File.Move(Application.StartupPath + @"\newVikingKundTerminal.exe", Application.StartupPath + @"\VikingKundTerminal.exe");
this.Close();
Process.Start(Application.ExecutablePath);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Omstart av programmet", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Everything works until:
Code:
Process.Start(Application.ExecutablePath);
The error says its trying to start oldVikingKundTerminal.exe....
Suggestions/Ideas on how to accomplish this?
-
December 1st, 2010, 12:09 PM
#2
Re: Restart running application (C#, VS2010, Dotnet 2.0)
It looks like the currently running application knows it got renamed. Stepping through the code in a debugger can confirm this.
At any rate try
Code:
Process.Start( Application.StartupPath + @"\VikingKundTerminal.exe );
-
December 1st, 2010, 12:20 PM
#3
Re: Restart running application (C#, VS2010, Dotnet 2.0)
I had the same problem some time ago, and I used another exe to update the main application, actually they were updating each other, after the main app was updated I started it and it checked if the updater needs to be updated ;]
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
December 1st, 2010, 01:21 PM
#4
Re: Restart running application (C#, VS2010, Dotnet 2.0)
Originally Posted by memeloo
I had the same problem some time ago, and I used another exe to update the main application, actually they were updating each other, after the main app was updated I started it and it checked if the updater needs to be updated ;]
That's probably the best way.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|