InstallUtil使用哪个框架版本来安装服务?

时间:2014-05-29 15:03:21

标签: c# .net .net-4.5

场景:服务器上安装了较旧的2.0 Windows服务,但如果我尝试使用较新的4.5 InstallUtil进行卸载,则会收到错误。

我们使用使用InstallUtil服务的应用程序来卸载/安装Windows服务。有没有办法检查InstallUtil的哪个框架版本用于安装服务?因此,根据使用的版本,我可以将正确的InstallUtil路径传递给方法

2 个答案:

答案 0 :(得分:0)

而不是InstallUtil尝试使用Windows自带的SC.EXE

E.g。卸载服务:

NET stop "Your Service Name"
SC delete "Your Service Name" 

(用于在服务仍在运行时停止服务的第一个命令)

同样,您可以使用SC.EXE来创建和启动服务。这样您就不依赖于InstallUtil或其特定版本。

答案 1 :(得分:0)

我可以使用此代码获取我想要的详细信息:

const string dotNetFourPath = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\" + "servicename "; //servicename here
using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(dotNetFourPath))
{
    Console.WriteLine(registryKey.GetValue("EventMessageFile")); //returns EventMessageFile - Value Data
}