Kill windows service forcefully in WIX

点点圈 提交于 2019-11-28 14:43:05

I shouldn't answer this since it has been ages since I have dealt with stuff like this, but what the heck, let's try.

  1. CloseApplication Element: Maybe I would just try WiX's CloseApplication Element first. I doubt it will work for a service, but this is the most convenient approach I can think of off the top of my head.
  2. Sysinternals PsKill: Mark Russinovich's PsKill would be worth a try. I think his tools are redistributable so you can include them in your setup, and they are always good. You have to invoke it from an elevated, deferred mode custom action - which is alway more involved than using a built-in WiX construct.
  3. Taskkill: There is also the built-in Taskkill - which I have never used. Suggested use with the sc tool.

I want to emphasize that I haven't actually tested these tools for killing services, and I don't have time to do so right now. There could be issues with the sequencing whereby StopServices could be scheduled before the CloseApplication custom action from WiX is scheduled to run. Please check the InstallExecuteSequence using Orca (towards bottom) after compilation to see whether this is the case.

I have found a solution for this after digging for sometime .

I am creating new C# custom action project and i am sequencing my action before InstallInitialize.

In my C# custom action method, i am reading the existing installed file version by using FileVersionInfo.GetVersionInfo(filePath);

Then i am checking with desired version which i want to check and if condition matches i am killing my service process using

 foreach (Process proc in Process.GetProcessesByName("ProcessName"))
 {
      proc.Kill();
      session.Log("Service Killed");
 }

in order to achieve this, Wix toolset v3.11.1 has to installed beforehand

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!