Hello!
My contribution as a command line parametrizable C# implementation:
It is then launched within command set (copy is to prevent installation blocking as it updates the UpdaterStarter.exe as well).
copy bin\UpdaterStarter.exe .
UpdaterStarter.exe acupdate.exe "/silentall -nofreqcheck"
<and finally here (re)start the updated application>
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.IO;
namespace UpdaterStarter
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args) {
if(args.Length != 2) {
MessageBox.Show("Usage: UpdaterStarter <updater full path> <updater start args>");
return;
}
string updaterExe = args[0];
if(!File.Exists(updaterExe)) {
MessageBox.Show("Updater does not exist: " + updaterExe);
return;
}
updaterExe = Path.GetFullPath(updaterExe);
string updaterParams = args[1].Replace("\"", "");
Process updaterProc = Process.Start(updaterExe, updaterParams);
updaterProc.WaitForExit();
int exitCode = updaterProc.ExitCode;
if(exitCode == 0) {
string mutexName = updaterExe.Replace('\\', '_').Replace(".exe", ".mtx");
waitForMutex(mutexName);
}
}
private static void waitForMutex(string mutexName) {
Mutex mutex = null;
while(mutex == null) {
try {
mutex = Mutex.OpenExisting(mutexName, MutexRights.Synchronize);
} catch(WaitHandleCannotBeOpenedException) {
Thread.Sleep(500);
}
}
try {
mutex.WaitOne();
} catch(AbandonedMutexException) {
}
}
}
}
Enjoy!
Br,
Kalle