Esempio n. 1
0
        /// <summary>
        /// The LsaOpenPolicy function opens a handle to the Policy object on a local or remote system. You must run the process "As Administrator" so that the
        /// call doesn't fail with ERROR_ACCESS_DENIED.
        /// </summary>
        /// <param name="DesiredAccess">
        /// An ACCESS_MASK that specifies the requested access rights. The function fails if the DACL of the target system does not allow the caller the
        /// requested access. To determine the access rights that you need, see the documentation for the LSA functions with which you want to use the policy handle.
        /// </param>
        /// <param name="SystemName">
        /// Name of the target system. The name can have the form "ComputerName" or "\\ComputerName". If this parameter is NULL, the function opens the Policy
        /// object on the local system.
        /// </param>
        /// <returns>A pointer to an LSA_HANDLE variable that receives a handle to the Policy object.</returns>
        public static SafeLsaPolicyHandle LsaOpenPolicy(LsaPolicyRights DesiredAccess, string SystemName = null)
        {
            var oa = LSA_OBJECT_ATTRIBUTES.Empty;

            LsaNtStatusToWinError(LsaOpenPolicy(SystemName, ref oa, DesiredAccess, out SafeLsaPolicyHandle handle)).ThrowIfFailed();
            return(handle);
        }
Esempio n. 2
0
        /// <summary>
        /// The LsaOpenPolicy function opens a handle to the Policy object on a local or remote system. You must run the process "As Administrator" so that the
        /// call doesn't fail with ERROR_ACCESS_DENIED.
        /// </summary>
        /// <param name="SystemName">
        /// Name of the target system. The name can have the form "ComputerName" or "\\ComputerName". If this parameter is NULL, the function opens the Policy
        /// object on the local system.
        /// </param>
        /// <param name="DesiredAccess">
        /// An ACCESS_MASK that specifies the requested access rights. The function fails if the DACL of the target system does not allow the caller the
        /// requested access. To determine the access rights that you need, see the documentation for the LSA functions with which you want to use the policy handle.
        /// </param>
        /// <returns>A pointer to an LSA_HANDLE variable that receives a handle to the Policy object.</returns>
        public static SafeLsaPolicyHandle LsaOpenPolicy(string SystemName, LsaPolicyRights DesiredAccess)
        {
            var oa = LSA_OBJECT_ATTRIBUTES.Empty;
            SafeLsaPolicyHandle handle;
            var ret = LsaNtStatusToWinError(LsaOpenPolicy(SystemName, ref oa, DesiredAccess, out handle));

            if (ret != 0)
            {
                throw new Win32Exception(ret);
            }
            return(handle);
        }
Esempio n. 3
0
 public static extern uint LsaOpenPolicy(
     [In, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LsaUnicodeStringMarshaler))] string SystemName,
     ref LSA_OBJECT_ATTRIBUTES ObjectAttributes,
     LsaPolicyRights DesiredAccess,
     out SafeLsaPolicyHandle PolicyHandle);
Esempio n. 4
0
 private static NTStatus OpenPolicy(string ServerName, LsaPolicyRights DesiredAccess, out SafeLSA_HANDLE PolicyHandle) =>
 //
 // Attempt to open the policy.
 //
 LsaOpenPolicy(ServerName, LSA_OBJECT_ATTRIBUTES.Empty, DesiredAccess, out PolicyHandle);