Get the version information of an installed service?

I want to check programmatically that the latest version of my Windows Service is installed. I have:

var ctl = ServiceController.GetServices().Where(s => s.ServiceName == "MyService").FirstOrDefault();
if (ctl != null) {
  // now what?
}

I don't see anything on the ServiceController interface that will tell me the version number. How do I do it?


I am afraid there is no way other than getting the executable path from the registry as ServiceController does not provide that information.

Here is a sample I had created before:

private static string GetExecutablePathForService(string serviceName, RegistryView registryView, bool throwErrorIfNonExisting)
    {
        string registryPath = @"SYSTEM\CurrentControlSet\Services\" + serviceName;
        RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView).OpenSubKey(registryPath);
        if(key==null)
        {
            if (throwErrorIfNonExisting)
                throw new ArgumentException("Non-existent service: " + serviceName, "serviceName");
            else
                return null;
        }
        string value = key.GetValue("ImagePath").ToString();
        key.Close();
        if(value.StartsWith("\""))
        {
            value = Regex.Match(value, "\"([^\"]+)\"").Groups[1].Value;
        }

        return Environment.ExpandEnvironmentVariables(value);
    }

After getting the exe path, just use FileVersionInfo.GetVersionInfo(exePath) class to get the version.

How to check the version of an assembly (dll)?, How do I tell what version of IIS is installed? Select windows +R key and type inetmgr and press OK. It will open the IIS manager window. In the same way go to Help ->About Internet Information Services and you will get the version installed on your computer. Alternatively select windows +R and type %SystemRoot%\system32\inetsrv\InetMgr.exe.


If you own the service, you can put version information into the DisplayName, e.g. DisplayName="MyService 2017.06.28.1517". This allows you to find an existing installation of your service and parse the version information:

var ctl = ServiceController
    .GetServices()
    .FirstOrDefault(s => s.ServiceName == "MyService");
if (ctl != null) {
    // get version substring, you might have your own style.
    string substr = s.DisplayName.SubString("MyService".Length);
    Version installedVersion = new Version(substr);
    // do stuff, e.g. check if installed version is newer than current assembly.
}

This may be useful if you want to avoid the registry. The problem is, that service entries can go to different parts of the registry depending on the installation routine.

How can I tell what version of IIS is installed?, How do I know which version of Windows 10 I have installed? Right-click My Computer, found on the Windows desktop or in the Start menu. Select Properties in the popup menu. In the System Properties window, under the General tab, the version of Windows is displayed, as well as the currently-installed Windows Service Pack.


If you are talking about getting the current version of your service automatically from the assembly properties then you can set up a property such as below in your ServiceBase class.

public static string ServiceVersion { get; private set; }

Then in your OnStart method add the following...

ServiceVersion = typeof(Program).Assembly.GetName().Version.ToString();

Full Example

using System.Diagnostics;
using System.ServiceProcess;

public partial class VaultServerUtilities : ServiceBase
{

    public static string ServiceVersion { get; private set; }

    public VaultServerUtilities()
    {
        InitializeComponent();

        VSUEventLog = new EventLog();
        if (!EventLog.SourceExists("Vault Server Utilities"))
        {
            EventLog.CreateEventSource("Vault Server Utilities", "Service Log");
        }

        VSUEventLog.Source = "Vault Server Utilities";
        VSUEventLog.Log = "Service Log";

    }


    protected override void OnStart(string[] args)
    {

        ServiceVersion = typeof(Program).Assembly.GetName().Version.ToString();
        VSUEventLog.WriteEntry(string.Format("Vault Server Utilities v{0} has started successfully.", ServiceVersion));

    }

    protected override void OnStop()
    {
        VSUEventLog.WriteEntry(string.Format("Vault Server Utilities v{0} has be shutdown.", ServiceVersion));
    }
}

In the example above my event log displays the current version of my service...

See which version of Windows 10 you have, on your PC: Select the Start button and then select Settings . In Settings, select System > About. Find OS Version and Service Pack number from CMD As you can see above, ver command shows only OS version but not the service pack number. We can find service pack number as well with Systeminfo command. Systeminfo dumps lot of other information too, which we can filter out using findstr command.


How do I get file version information from the command line?, You can use PowerShell to obtain the version information for a file. PS> (Get-​Command C:\Path\To\Thing.dll).FileVersionInfo.FileVersion 3.1. Select System when the Windows Settings screen opens. Choose About from the left pane at the bottom. The Windows 10 major update you have installed is shown on the Version line. A faster way to find the Windows 10 version number is by typing the winver command at the command prompt or in the Run dialog box.


How to check your Windows version using a shortcut or CMD, Microsoft provides details about the Windows version installed on your You need this information if you want to check whether your operating system programs, user-defined programs, service applications and processes. 1- Using the command "winver". 1- Connect to your Windows server remotely (Remote Desktop) 2- Open a Microsoft MS-DOS command prompt shell window "cmd". 3- Type the following command. winver. 4- Press the "Enter" bouton to execute the command. The infomation about your Windows version and Edition will be displayed.


5 Ways To Check Installed Version of IIS in Windows, Internet Information Service (IIS) is a web server from Microsoft used to host anything on the web . It will host your websites, application on the  Surface Pro 3 - surface version information service i recently got a firmware update on my surface pro 3 and now there is an exclamation point at ( !/other/ surface version information service I have tried uninstall device and reinstall but it still says no driver installed or no driver needed any suggestions