Пример #1
0
        public static bool ChangeServiceDescription(IntPtr Handle, string description)
        {
            try
            {
                SERVICE_DESCRIPTION sd = new SERVICE_DESCRIPTION();
                sd.Description = description;

                const int cbBufSize = 8 * 1024;

                IntPtr lpMemory = Marshal.AllocHGlobal((int)cbBufSize);
                Marshal.StructureToPtr(sd, lpMemory, false);

                bool result = NativeServiceFunctions.ChangeServiceConfig2(Handle, SC_SERVICE_CONFIG.SERVICE_CONFIG_DESCRIPTION, lpMemory);

                Marshal.FreeHGlobal(lpMemory);

                return result;
            }
            catch(Exception e)
            {
                Log.Error("ChangeServiceDescription() failed", e);
                return false;
            }
        }