private IntPtr GetLsaPolicy(LSA_AccessPolicy access) { IntPtr LsaPolicyHandle; uint ntsResult = LsaOpenPolicy(ref this.localsystem, ref this.objectAttributes, (uint)access, out LsaPolicyHandle); uint winErrorCode = LsaNtStatusToWinError(ntsResult); if (winErrorCode != 0) { throw new Exception("LsaOpenPolicy failed: " + winErrorCode); } return(LsaPolicyHandle); }
public LSAPolicy(LSA_AccessPolicy access) { //initialize an empty unicode-string string systemName = null; //these attributes are not used, but LsaOpenPolicy wants them to exist // (MSDN: "the structure members are not used, initalize them to NULL or zero") var objectAttributes = new LSA_OBJECT_ATTRIBUTES(); // objectAttributes.Length = 0; // objectAttributes.RootDirectory = IntPtr.Zero; // objectAttributes.Attributes = 0; // objectAttributes.SecurityDescriptor = IntPtr.Zero; // objectAttributes.SecurityQualityOfService = IntPtr.Zero; // //get a policy handle var resultPolicy = LsaOpenPolicy(ref systemName, ref objectAttributes, (int)access, out _policy); var winErrorCode = LsaNtStatusToWinError(resultPolicy); if (winErrorCode != 0) { throw new Win32Exception(winErrorCode, "OpenPolicy failed: " + winErrorCode); } }