【问题标题】:InstallUtil which framework version was used to install service?InstallUtil 使用哪个框架版本来安装服务?
【发布时间】:2014-05-29 15:03:21
【问题描述】:

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

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

【问题讨论】:

    标签: c# .net .net-4.5


    【解决方案1】:

    尝试使用 Windows 自己的 SC.EXE 代替 InstallUtil

    例如卸载服务:

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

    (第一个命令用于停止服务,如果它仍在运行)

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

    【讨论】:

    • 感谢您的建议,但 InstalUtil 的使用在整个应用程序中非常广泛
    【解决方案2】:

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

    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
    }
    

    【讨论】:

      猜你喜欢
      • 2012-05-04
      • 2010-09-07
      • 2013-01-11
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      • 1970-01-01
      • 2011-03-23
      • 1970-01-01
      相关资源
      最近更新 更多