 |
|
 |
The code in AutoUpdate is working up to the line
System.Diagnostics.Process.Start(Application.ExecutablePath, Microsoft.VisualBasic.Command())
then I'm getting this error message guys,
"The process cannot access the file because it is being used by another process"
How can i solve this, ideas ???
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Got it, never mind Maybe to help others who might face same prob
Now, The zip file with the source code, has 2 projects, one for the AutoUpdate dll project, and another for the AutoUpdateTest project.
Now the AutoUpdate dll is simply referenced in the AutoUpdateTest project which means in essence we have one project, which is the AutoUpdateTest project which is the one we are trying to update. Now if you run that project, you will get an error
“The process cannot access the file because it is being used by another process “
Whats happening here is we were trying to update the same process that is currently running, this obviously doesn’t make sense or is not possible coz windows locks a running process !!!!!, My solution was simple, since we can’t modify a running process why not let this process do the job of downloading a replacing another projects .exe file, i.e. just create a separate project which will be the one we want to update, create say a third project there called ProjectToAutoUpdate project, compile it and copy the ProjectToAutoUpdate.exe to AutoUpdateTest Bin folder, set AutoUpdateTest as Main project so it runs first and checks updates etc, then downloads updates then delete the actual .exe we want updated(ProjectToAutoUpdate.exe), and then start this new ProjectToAutoUpdate.exe from AutoUpdateTest .
Man !!!
Well corret me if i'm wrong somewhere, but my solution works
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
I'm receiving the following error when adding the autoupdate.dll file to my project:
"Could not load file or assembly 'AutoUpdate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
Not sure what gives.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
NOw when I add the code as a module for AutoUpdate.vb it gives me this error:
Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog instead
Any ideas?
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
hi friends,
how can i save and retrieve word file into sql database using vb.net 2005.
thanx Naresh Rajput
|
| Sign In·View Thread·PermaLink | 1.33/5 (2 votes) |
|
|
|
 |
|
|
 |
|
 |
Hi there,
First of all, compliments for the usefull article. I was developing something similiar to this for a huge project long time before. The software I'm working on now is a software that contains a lot of logic builded inside class libraries (DLL files). Compiling the new version of the software will generate new references to the libraries by using keys on the .exe file side.
If the developer team distributes a new release of a single class library (dll file), we do not need to update the whole software package. We would like to update only the single class library file (dll file). By reading a central update file on a webserver we would like to download/update only the files needed to be updated and not the whole software package.
The problem I'm facing now are the references/codes compiled in the binary executable .exe file of the software. The new updated class library will not always be accepted, because the .exe file has in my opinion a reference key to each .dll file inculded in the project.
Is there a way to solve this problem? How can I update only the files that need to be updated (dll files) without having the issue with the reference keys. The class libraries should stay protected as they are. Am I missing something here? Any suggestions?
Regards,
Sead
|
| Sign In·View Thread·PermaLink | 2.25/5 (4 votes) |
|
|
|
 |
|
 |
this blog suggests it won't work for those of us using MSI installers, as the installer will simply revert the application files back automatically. true?
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
Is it not a little dangerous to remove the ability of updating the AutoUpdate program itself?
What happens when a patch/fix is required for the AutoUpdate program, how do you see this scenario being performed ?
|
| Sign In·View Thread·PermaLink | 1.75/5 (5 votes) |
|
|
|
 |
|
 |
1. Create a project - click File -> New -> Project -> Class Library 1.1. Name it whatever you want (as long as its name is AutoUpdate ) 1.2. Rename Class1.cs to AutoUpdate.cs (accepting to rename all references) 1.2. Double click AutoUpdate.cs and paste (replace whatever is in there) the following
using System; using System.Collections.Generic; using System.IO; using System.Net; using System.Diagnostics; using System.Windows.Forms;
public class AutoUpdate { private const string ToDeleteExtension = ".ToDelete"; private const string UpdateFileName = "Update.txt"; private const string ErrorMessageCheck = "There was a problem checking the update config file."; private const string ErrorMessageUpdate = "There was a problem runing the Auto Update."; private const string ErrorMessageDelete = "There was a problem deleting files.";
#region "CleanUp"
public static bool CleanUp() { try { string file;
DirectoryInfo dir = new DirectoryInfo(Application.StartupPath); FileInfo[] infos = dir.GetFiles("*" + ToDeleteExtension, SearchOption.AllDirectories); foreach (FileInfo info in infos) { file = info.FullName; File.SetAttributes(file, FileAttributes.Normal); File.Delete(file); } return true; } catch (Exception ex) { MessageBox.Show(ErrorMessageDelete + "\r" + ex.Message); return false; } }
#endregion
#region "UpdateFiles"
public static bool UpdateFiles(string remotePath, bool DoUpdate) { if (remotePath == string.Empty) return false;
if (DoUpdate) { CleanUp(); }
System.Collections.Generic.List<AutoUpdateRollback> rollBackList = new System.Collections.Generic.List<AutoUpdateRollback>();
string remoteUri = remotePath; WebClient myWebClient = new WebClient();
bool retValue = false; try { string contents = myWebClient.DownloadString(remoteUri + UpdateFileName); contents = contents.Replace("\n", ""); string[] fileList = contents.Split(Convert.ToChar("\r"));
contents = string.Empty; foreach (string file in fileList) { string fileAux; if ((file.IndexOf("\'") + 1 != 0)) fileAux = file.Substring(0, ((file.IndexOf("\'") + 1) - 1)); else fileAux = file; if (fileAux.Trim() != string.Empty) { if (!string.IsNullOrEmpty(contents)) contents = contents + (char) (Keys.Return); contents = contents + fileAux.Trim(); } }
fileList = contents.Split((char) (Keys.Return)); string[] info; string infoFilePath; String infoParam; List<string> fileNameList = new List<string>(); Version Version1, Version2; FileVersionInfo fv; bool IsToDelete; bool IsToUpgrade; foreach (string file in fileList) { info = file.Split(Convert.ToChar(";")); infoFilePath = info[0].Trim(); infoParam = info[1].Trim(); while (infoFilePath[0] == '.' || infoFilePath[0] == '\\') { infoFilePath = infoFilePath.Substring(1, infoFilePath.Length-1); }
if (fileNameList.Contains(infoFilePath.ToLowerInvariant())) { continue; }
fileNameList.Add(infoFilePath.ToLowerInvariant()); IsToDelete = false; IsToUpgrade = false; string fileName = Application.StartupPath + @"\" + infoFilePath; string tempFileName = Application.StartupPath + @"\" + infoFilePath + DateTime.Now.TimeOfDay.TotalMilliseconds; bool FileExists = File.Exists(fileName); if ((infoParam == "delete")) { IsToDelete = FileExists; if (DoUpdate) if (IsToDelete) rollBackList.Add(new AutoUpdateRollback(fileName, tempFileName + ToDeleteExtension, "Delete")); } else if ((infoParam == "?")) { IsToUpgrade = !FileExists; } else if (infoParam != string.Empty && (infoParam[0] == '=' && FileExists)) { fv = FileVersionInfo.GetVersionInfo(fileName); Version1 = new Version(infoParam.Substring(1, infoParam.Length - 1)); Version2 = new Version(fv.FileVersion); IsToUpgrade = Version1 != Version2; IsToDelete = IsToUpgrade; if (DoUpdate) if (IsToUpgrade) rollBackList.Add( new AutoUpdateRollback(fileName, tempFileName + ToDeleteExtension, "Upgrade")); } else if (FileExists) { fv = FileVersionInfo.GetVersionInfo(fileName); if (infoParam != string.Empty) { Version1 = new Version(infoParam); Version2 = new Version(fv.FileVersion); IsToUpgrade = Version1 > Version2; IsToDelete = IsToUpgrade; if (DoUpdate) if (IsToUpgrade) rollBackList.Add( new AutoUpdateRollback(fileName, tempFileName + ToDeleteExtension, "Upgrade")); } } else { IsToUpgrade = true; }
if (DoUpdate) { if (IsToUpgrade) myWebClient.DownloadFile(remoteUri + infoFilePath, tempFileName); if (IsToDelete) File.Move(fileName, tempFileName + ToDeleteExtension); if (IsToUpgrade) File.Move(tempFileName, fileName); }
if (IsToUpgrade || IsToDelete) retValue = true; }
} catch (Exception ex) { MessageBox.Show("There was an error. Trying to roll back"); if (DoUpdate) { foreach (AutoUpdateRollback rollBack in rollBackList) { if (rollBack.Operation == "Delete" || rollBack.Operation == "Upgrade") { if (File.Exists(rollBack.Renamed)) File.Move(rollBack.Renamed, rollBack.Original); } } MessageBox.Show(ErrorMessageUpdate + "\r" + ex.Message + "\r" + "Remote URI: " + remoteUri); } else MessageBox.Show(ErrorMessageCheck + "\r" + ex.Message + "\r" + "Remote URI: " + remoteUri);
retValue = false; } finally { myWebClient.Dispose(); rollBackList.Clear(); }
return retValue; }
#endregion }
public class AutoUpdateRollback { #region Properties
private string _renamed, _original, _operation;
public string Operation { get { return _operation; } set { _operation = value; } }
public string Original { get { return _original; } set { _original = value; } }
public string Renamed { get { return _renamed; } set { _renamed = value; } }
#endregion
#region Constructor
public AutoUpdateRollback(string Original, string Renamed, string Operation) { _original = Original; _renamed = Renamed; _operation = Operation; }
#endregion } 2. Add a new project of type Windows Application named "AutoUpdateTest" 2.1. Add a reference to the AutoUpdate project 2.2. Rename Form1.cs to Startup.cs 2.3. Click View Code and paste (replace whatever is in there) the following
using System; using System.Diagnostics; using System.Windows.Forms;
namespace AutoUpdateTest { public partial class Startup : Form { public Startup() { InitializeComponent(); }
private void Startup_Load(object sender, EventArgs e) { Show();
string RemotePath = "http://localhost/AutoUpdateTest/"; label1.Text = RemotePath; Form helper = new Updated.ShowVersionForm(); helper.Show(); MessageBox.Show("Checking if update is needed..."); if (AutoUpdate.UpdateFiles(RemotePath, false)) { MessageBox.Show("Update is needed."); if (AutoUpdate.UpdateFiles(RemotePath, true)) { MessageBox.Show("Auto Update succedeed!"); Dispose(); Process.Start(Application.ExecutablePath); Application.Exit(); } } else { MessageBox.Show("No update is available."); AutoUpdate.CleanUp(); } }
private void button1_Click(object sender, EventArgs e) { Close(); } } } 3. On IIS create a virtual directory named "AutoUpdateTest" 3.1. Put your sample files in there. 3.2. Put there an Update.txt like this one
\Updated2.exe ; 'Get Updated2.exe if it doesn't exist (ignore "\") .\Updated3.exe ; ? 'Get Updated3.exe if it doesn't exist (ignore ".\") .\Updated3.exe ; delete 'This line is ignored as it's the second instance of the same file path ..\Updated4.exe ; =1.0.0.3 'If actual Updated4.exe isn't this version, get it (ignore "..\") Updated5.exe ; delete 'Delete Updated5.exe Updated.exe ; 1.0.0.3 'If actual Updated.exe version is smaller than 1.0.0.3, get it 'Update2.exe ; delete 'ignore this line 'the lines below just test the same features on sub-directories TST\TSTUpdated.dll ; 1.0.0.1 TST\SubSub\SUBUpdated.dll ; 1.0.0.1 \TST\SubSub\Slash.dll ; 1.0.0.1 .\TST\SubSub\DotSlash.dll ; 1.0.0.1 .\TST\SubSub\Trash.dll ; delete 4. Build and execute AutoUpdateTest.exe
NB - If you have questions, just reply to this message. I'll receive a notification and will answer.
modified on Friday, February 8, 2008 6:54 PM
|
| Sign In·View Thread·PermaLink | 4.14/5 (6 votes) |
|
|
|
 |
|
|
 |
|
 |
yes,it can update while single folder,but how can i update with sub folder? any advise?
God helps those who help themselves
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
yeah,i got how to update subfolder, i had made a mistaken when i updated! thank you!
God helps those who help themselves
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
what is the content of the form/GUI?
I need your help regarding this:
I need an automatic updater for created applications (Tool_A, Tool_B) in the client's PC. I will create a tool that will reside in the memory of the client's PC and server's PC. Whenever I created an update and put in the server, the tool in the server PC will contact the tool in the client's PC and display an option if the user wants to upgrade to a new version of Tool_A/Tool_B.
I hope ypu can give me some advise. 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I suggest you try the code. Refering your use case - starting the update process per server request, this is a completely different scenario. Auto update isn't suited for that scenario - as its name says, auto update means "I update myself".
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Does it accept absolute paths? I need a way to update the GAC, any thoughts or methods that you think may work for this application?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
plz check it. i send yesterday a ticket to the Code Project team, but nothing happens, yet.
The old version works fine, but when i dont need the autoupdater.exe now, i will be change the updateSystem of my program!
regrads
modified on Friday, December 07, 2007 2:20:21 AM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
okay i use the C# code from dbembibre, build an DLL and use this in my VB.Net project.
THX dbembibre for the C# Code!!
EDIT: there is only a little bug in the C# code. When the Update.txt has NO Comment ('Comment) the return of "isUpdatable" is always false!
so i change all
string Aux = string.Empty;
to
string Aux = F;
modified on Monday, December 10, 2007 3:36:31 AM
|
| Sign In·View Thread·PermaLink | 4.00/5 (1 vote) |
|
|
|
 |
|
 |
Thanks Eduardo,
This is a simple library, but perfectly adequate for a small project and really kicked me along in getting my function going.
Regards, Paul
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |