Okay, tricky title. I've got a windows service which executes a process to update itself.
//Service
private static void Update()
{
Process p = new Process();
p.StartInfo.FileName = @"updateprocess.exe";
p.Start();
}
The update process checks if there's a new version available and some other prerequisites.
If there's a new version available I stop the service and call the Uninstall-function which looks like this
//Update.exe
private static void Uninstall()
{
Process p = new Process();
p.StartInfo.FileName = @"C:\WINDOWS\system32\msiexec.exe";
p.StartInfo.Arguments = @"/uninstall {6811FA84-3171-453C-9C22-E36B86DD86D7} /quiet";
p.Start();
p.WaitForExit();
}
I debugged this scenario. After p.Start(); the application stops. I checked the event log of my system which provided following information
Application: Update.exe
Frameworkversion: v4.0.30319
Exception: System.InvalidOperationException
Stack:
at System.Diagnostics.Process.EnsureState(State)
at System.Diagnostics.Process.EnsureState(State)
at System.Diagnostics.Process.GetProcessHandle(Int32, Boolean)
at System.Diagnostics.Process.WaitForExit(Int32)
at Update.Uninstall()
at Update.Main(System.String[])
Interesting fact: msiexec was executed - my application got uninstalled.
I should also mention I run everything as the system user. If I run it as my domain user, I have no problems: The uninstallation works like a charm, the installation is executed and successful and I can start the service.