Example #1
0
        static void UpdateServiceDescriptionWithVersion(string serviceName, string machineName, string path)
        {
            const string sv       = "Service Version: ";
            string       filepath =
                Alphaleonis.Win32.Filesystem.Path.GetFullPath("\\\\" + machineName + "\\" + path.Replace(':', '$'));
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(filepath);

            ServiceUtilWin32Helper svcUtil = new ServiceUtilWin32Helper(machineName);
            string desc = svcUtil.GetServiceDescription(serviceName);

            if (!string.IsNullOrWhiteSpace(desc))
            {
                int pos = desc.IndexOf(sv);
                if (pos >= 0)
                {
                    desc = desc.Remove(pos, desc.Length - pos);
                }
                if (desc.Length > 0 && desc[desc.Length - 1] != ' ')
                {
                    desc += " ";
                }
            }

            desc = string.Format("{0}{1}{2}", desc, sv, fvi.FileVersion);
            svcUtil.SetServiceDescription(serviceName, desc);
        }
Example #2
0
 public static void UpdateServiceDescription(string serviceName, string machineName, string description)
 {
     if (!String.IsNullOrWhiteSpace(description))
     {
         ServiceUtilWin32Helper svcUtil = new ServiceUtilWin32Helper(machineName);
         string desc = svcUtil.GetServiceDescription(serviceName);
         svcUtil.SetServiceDescription(serviceName, description);
     }
 }