/// <summary> /// GetServiceSidPtr method implementation /// </summary> private static IntPtr GetServiceSidPtr(string service) { NativeMethods.LSA_UNICODE_STRING lSA_UNICODE_STRING = default(NativeMethods.LSA_UNICODE_STRING); lSA_UNICODE_STRING.SetTo(service); int cb = 0; IntPtr intPtr = IntPtr.Zero; IntPtr result; try { uint num = NativeMethods.RtlCreateServiceSid(ref lSA_UNICODE_STRING, IntPtr.Zero, ref cb); if (num == 3221225507u) { intPtr = Marshal.AllocHGlobal(cb); num = NativeMethods.RtlCreateServiceSid(ref lSA_UNICODE_STRING, intPtr, ref cb); } if (num != 0u) { throw new Win32Exception(Convert.ToInt32(num)); } result = intPtr; } finally { lSA_UNICODE_STRING.Dispose(); } return(result); }
internal static extern uint RtlCreateServiceSid(ref NativeMethods.LSA_UNICODE_STRING serviceName, IntPtr serviceSid, ref int serviceSidLength);