1

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.

FRules
  • 739
  • 1
  • 10
  • 20
  • What is your question? I thought it will be something like "why I get error", but you answered it at the end. – Renatas M. Jan 14 '15 at 13:31
  • I want to execute it as system user. Order of the update process is this: "Check Version" -> "Stop Service" -> "Uninstall service" -> "Install service" -> "Start service" but my problem is in "Uninstall service" that after the p.Start() function the program crashes. – FRules Jan 14 '15 at 13:47
  • Not sure what the InvalidOperationException is about but you might want to see [Programatically installing MSI packages](http://stackoverflow.com/questions/5764868/programatically-installing-msi-packages) for other more robust methods of performing Windows Installer Operations. – Justin Jan 14 '15 at 14:26
  • After rethinking this I found out what the problem is. I deliver those files in a single setup. When I call the uninstall function, the msiexec removes the process itself so thats why it won't install it. – FRules Jan 15 '15 at 07:37

0 Answers0