Beispiel #1
0
 private static NtResult <SafeStructureInOutBuffer <QUERY_SERVICE_CONFIG> > QueryConfig(SafeServiceHandle service, bool throw_on_error)
 {
     using (var buf = new SafeStructureInOutBuffer <QUERY_SERVICE_CONFIG>(8192, false)) {
         return(Win32NativeMethods.QueryServiceConfig(service, buf, buf.Length,
                                                      out int required).CreateWin32Result(throw_on_error, () => buf.Detach()));
     }
 }
        private static string GetServiceDisplayName(SafeServiceHandle service)
        {
            using (var buf = new SafeStructureInOutBuffer <QUERY_SERVICE_CONFIG>(8192, false))
            {
                if (!Win32NativeMethods.QueryServiceConfig(service, buf, buf.Length, out int required))
                {
                    return(string.Empty);
                }

                var result = buf.Result;
                if (result.lpDisplayName == IntPtr.Zero)
                {
                    return(string.Empty);
                }

                return(Marshal.PtrToStringUni(result.lpDisplayName));
            }
        }