ホーム › Security.Authentication.Identity › LsaRemoveAccountRights
LsaRemoveAccountRights
関数指定アカウントからユーザー権利を削除する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
NTSTATUS LsaRemoveAccountRights(
LSA_HANDLE PolicyHandle,
PSID AccountSid,
BOOLEAN AllRights,
LSA_UNICODE_STRING* UserRights, // optional
DWORD CountOfRights
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| PolicyHandle | LSA_HANDLE | in | LsaOpenPolicyで取得したLSAポリシーハンドル。アカウント変更権が必要となる。 |
| AccountSid | PSID | in | 権利を削除する対象アカウントのSID。有効なPSIDを指定する。 |
| AllRights | BOOLEAN | in | TRUEならアカウントの全権利を削除しオブジェクトを破棄する。FALSEならUserRights指定分のみ削除する。 |
| UserRights | LSA_UNICODE_STRING* | inoptional | 削除する権利または特権名を保持するLSA_UNICODE_STRING配列へのポインタ。AllRightsがTRUEの場合は無視される。 |
| CountOfRights | DWORD | in | UserRights配列に含まれる権利の数を指定する。AllRightsがTRUEなら0でよい。 |
戻り値の型: NTSTATUS
各言語での呼び出し定義
// ADVAPI32.dll
#include <windows.h>
NTSTATUS LsaRemoveAccountRights(
LSA_HANDLE PolicyHandle,
PSID AccountSid,
BOOLEAN AllRights,
LSA_UNICODE_STRING* UserRights, // optional
DWORD CountOfRights
);[DllImport("ADVAPI32.dll", ExactSpelling = true)]
static extern int LsaRemoveAccountRights(
IntPtr PolicyHandle, // LSA_HANDLE
IntPtr AccountSid, // PSID
[MarshalAs(UnmanagedType.U1)] bool AllRights, // BOOLEAN
IntPtr UserRights, // LSA_UNICODE_STRING* optional
uint CountOfRights // DWORD
);<DllImport("ADVAPI32.dll", ExactSpelling:=True)>
Public Shared Function LsaRemoveAccountRights(
PolicyHandle As IntPtr, ' LSA_HANDLE
AccountSid As IntPtr, ' PSID
<MarshalAs(UnmanagedType.U1)> AllRights As Boolean, ' BOOLEAN
UserRights As IntPtr, ' LSA_UNICODE_STRING* optional
CountOfRights As UInteger ' DWORD
) As Integer
End Function' PolicyHandle : LSA_HANDLE
' AccountSid : PSID
' AllRights : BOOLEAN
' UserRights : LSA_UNICODE_STRING* optional
' CountOfRights : DWORD
Declare PtrSafe Function LsaRemoveAccountRights Lib "advapi32" ( _
ByVal PolicyHandle As LongPtr, _
ByVal AccountSid As LongPtr, _
ByVal AllRights As Byte, _
ByVal UserRights As LongPtr, _
ByVal CountOfRights As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
LsaRemoveAccountRights = ctypes.windll.advapi32.LsaRemoveAccountRights
LsaRemoveAccountRights.restype = ctypes.c_int
LsaRemoveAccountRights.argtypes = [
ctypes.c_ssize_t, # PolicyHandle : LSA_HANDLE
wintypes.HANDLE, # AccountSid : PSID
wintypes.BOOLEAN, # AllRights : BOOLEAN
ctypes.c_void_p, # UserRights : LSA_UNICODE_STRING* optional
wintypes.DWORD, # CountOfRights : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
LsaRemoveAccountRights = Fiddle::Function.new(
lib['LsaRemoveAccountRights'],
[
Fiddle::TYPE_INTPTR_T, # PolicyHandle : LSA_HANDLE
Fiddle::TYPE_VOIDP, # AccountSid : PSID
Fiddle::TYPE_CHAR, # AllRights : BOOLEAN
Fiddle::TYPE_VOIDP, # UserRights : LSA_UNICODE_STRING* optional
-Fiddle::TYPE_INT, # CountOfRights : DWORD
],
Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn LsaRemoveAccountRights(
PolicyHandle: isize, // LSA_HANDLE
AccountSid: *mut core::ffi::c_void, // PSID
AllRights: u8, // BOOLEAN
UserRights: *mut LSA_UNICODE_STRING, // LSA_UNICODE_STRING* optional
CountOfRights: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ADVAPI32.dll")]
public static extern int LsaRemoveAccountRights(IntPtr PolicyHandle, IntPtr AccountSid, [MarshalAs(UnmanagedType.U1)] bool AllRights, IntPtr UserRights, uint CountOfRights);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_LsaRemoveAccountRights' -Namespace Win32 -PassThru
# $api::LsaRemoveAccountRights(PolicyHandle, AccountSid, AllRights, UserRights, CountOfRights)#uselib "ADVAPI32.dll"
#func global LsaRemoveAccountRights "LsaRemoveAccountRights" sptr, sptr, sptr, sptr, sptr
; LsaRemoveAccountRights PolicyHandle, AccountSid, AllRights, varptr(UserRights), CountOfRights ; 戻り値は stat
; PolicyHandle : LSA_HANDLE -> "sptr"
; AccountSid : PSID -> "sptr"
; AllRights : BOOLEAN -> "sptr"
; UserRights : LSA_UNICODE_STRING* optional -> "sptr"
; CountOfRights : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ADVAPI32.dll" #cfunc global LsaRemoveAccountRights "LsaRemoveAccountRights" sptr, sptr, int, var, int ; res = LsaRemoveAccountRights(PolicyHandle, AccountSid, AllRights, UserRights, CountOfRights) ; PolicyHandle : LSA_HANDLE -> "sptr" ; AccountSid : PSID -> "sptr" ; AllRights : BOOLEAN -> "int" ; UserRights : LSA_UNICODE_STRING* optional -> "var" ; CountOfRights : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global LsaRemoveAccountRights "LsaRemoveAccountRights" sptr, sptr, int, sptr, int ; res = LsaRemoveAccountRights(PolicyHandle, AccountSid, AllRights, varptr(UserRights), CountOfRights) ; PolicyHandle : LSA_HANDLE -> "sptr" ; AccountSid : PSID -> "sptr" ; AllRights : BOOLEAN -> "int" ; UserRights : LSA_UNICODE_STRING* optional -> "sptr" ; CountOfRights : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; NTSTATUS LsaRemoveAccountRights(LSA_HANDLE PolicyHandle, PSID AccountSid, BOOLEAN AllRights, LSA_UNICODE_STRING* UserRights, DWORD CountOfRights) #uselib "ADVAPI32.dll" #cfunc global LsaRemoveAccountRights "LsaRemoveAccountRights" intptr, intptr, int, var, int ; res = LsaRemoveAccountRights(PolicyHandle, AccountSid, AllRights, UserRights, CountOfRights) ; PolicyHandle : LSA_HANDLE -> "intptr" ; AccountSid : PSID -> "intptr" ; AllRights : BOOLEAN -> "int" ; UserRights : LSA_UNICODE_STRING* optional -> "var" ; CountOfRights : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; NTSTATUS LsaRemoveAccountRights(LSA_HANDLE PolicyHandle, PSID AccountSid, BOOLEAN AllRights, LSA_UNICODE_STRING* UserRights, DWORD CountOfRights) #uselib "ADVAPI32.dll" #cfunc global LsaRemoveAccountRights "LsaRemoveAccountRights" intptr, intptr, int, intptr, int ; res = LsaRemoveAccountRights(PolicyHandle, AccountSid, AllRights, varptr(UserRights), CountOfRights) ; PolicyHandle : LSA_HANDLE -> "intptr" ; AccountSid : PSID -> "intptr" ; AllRights : BOOLEAN -> "int" ; UserRights : LSA_UNICODE_STRING* optional -> "intptr" ; CountOfRights : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procLsaRemoveAccountRights = advapi32.NewProc("LsaRemoveAccountRights")
)
// PolicyHandle (LSA_HANDLE), AccountSid (PSID), AllRights (BOOLEAN), UserRights (LSA_UNICODE_STRING* optional), CountOfRights (DWORD)
r1, _, err := procLsaRemoveAccountRights.Call(
uintptr(PolicyHandle),
uintptr(AccountSid),
uintptr(AllRights),
uintptr(UserRights),
uintptr(CountOfRights),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // NTSTATUSfunction LsaRemoveAccountRights(
PolicyHandle: NativeInt; // LSA_HANDLE
AccountSid: THandle; // PSID
AllRights: ByteBool; // BOOLEAN
UserRights: Pointer; // LSA_UNICODE_STRING* optional
CountOfRights: DWORD // DWORD
): Integer; stdcall;
external 'ADVAPI32.dll' name 'LsaRemoveAccountRights';result := DllCall("ADVAPI32\LsaRemoveAccountRights"
, "Ptr", PolicyHandle ; LSA_HANDLE
, "Ptr", AccountSid ; PSID
, "Char", AllRights ; BOOLEAN
, "Ptr", UserRights ; LSA_UNICODE_STRING* optional
, "UInt", CountOfRights ; DWORD
, "Int") ; return: NTSTATUS●LsaRemoveAccountRights(PolicyHandle, AccountSid, AllRights, UserRights, CountOfRights) = DLL("ADVAPI32.dll", "int LsaRemoveAccountRights(int, void*, byte, void*, dword)")
# 呼び出し: LsaRemoveAccountRights(PolicyHandle, AccountSid, AllRights, UserRights, CountOfRights)
# PolicyHandle : LSA_HANDLE -> "int"
# AccountSid : PSID -> "void*"
# AllRights : BOOLEAN -> "byte"
# UserRights : LSA_UNICODE_STRING* optional -> "void*"
# CountOfRights : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "advapi32" fn LsaRemoveAccountRights(
PolicyHandle: isize, // LSA_HANDLE
AccountSid: ?*anyopaque, // PSID
AllRights: u8, // BOOLEAN
UserRights: [*c]LSA_UNICODE_STRING, // LSA_UNICODE_STRING* optional
CountOfRights: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc LsaRemoveAccountRights(
PolicyHandle: int, # LSA_HANDLE
AccountSid: pointer, # PSID
AllRights: uint8, # BOOLEAN
UserRights: ptr LSA_UNICODE_STRING, # LSA_UNICODE_STRING* optional
CountOfRights: uint32 # DWORD
): int32 {.importc: "LsaRemoveAccountRights", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
int LsaRemoveAccountRights(
ptrdiff_t PolicyHandle, // LSA_HANDLE
void* AccountSid, // PSID
ubyte AllRights, // BOOLEAN
LSA_UNICODE_STRING* UserRights, // LSA_UNICODE_STRING* optional
uint CountOfRights // DWORD
);ccall((:LsaRemoveAccountRights, "ADVAPI32.dll"), stdcall, Int32,
(Int, Ptr{Cvoid}, UInt8, Ptr{LSA_UNICODE_STRING}, UInt32),
PolicyHandle, AccountSid, AllRights, UserRights, CountOfRights)
# PolicyHandle : LSA_HANDLE -> Int
# AccountSid : PSID -> Ptr{Cvoid}
# AllRights : BOOLEAN -> UInt8
# UserRights : LSA_UNICODE_STRING* optional -> Ptr{LSA_UNICODE_STRING}
# CountOfRights : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t LsaRemoveAccountRights(
intptr_t PolicyHandle,
void* AccountSid,
uint8_t AllRights,
void* UserRights,
uint32_t CountOfRights);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.LsaRemoveAccountRights(PolicyHandle, AccountSid, AllRights, UserRights, CountOfRights)
-- PolicyHandle : LSA_HANDLE
-- AccountSid : PSID
-- AllRights : BOOLEAN
-- UserRights : LSA_UNICODE_STRING* optional
-- CountOfRights : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const LsaRemoveAccountRights = lib.func('__stdcall', 'LsaRemoveAccountRights', 'int32_t', ['intptr_t', 'void *', 'uint8_t', 'void *', 'uint32_t']);
// LsaRemoveAccountRights(PolicyHandle, AccountSid, AllRights, UserRights, CountOfRights)
// PolicyHandle : LSA_HANDLE -> 'intptr_t'
// AccountSid : PSID -> 'void *'
// AllRights : BOOLEAN -> 'uint8_t'
// UserRights : LSA_UNICODE_STRING* optional -> 'void *'
// CountOfRights : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
LsaRemoveAccountRights: { parameters: ["isize", "pointer", "u8", "pointer", "u32"], result: "i32" },
});
// lib.symbols.LsaRemoveAccountRights(PolicyHandle, AccountSid, AllRights, UserRights, CountOfRights)
// PolicyHandle : LSA_HANDLE -> "isize"
// AccountSid : PSID -> "pointer"
// AllRights : BOOLEAN -> "u8"
// UserRights : LSA_UNICODE_STRING* optional -> "pointer"
// CountOfRights : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t LsaRemoveAccountRights(
intptr_t PolicyHandle,
void* AccountSid,
uint8_t AllRights,
void* UserRights,
uint32_t CountOfRights);
C, "ADVAPI32.dll");
// $ffi->LsaRemoveAccountRights(PolicyHandle, AccountSid, AllRights, UserRights, CountOfRights);
// PolicyHandle : LSA_HANDLE
// AccountSid : PSID
// AllRights : BOOLEAN
// UserRights : LSA_UNICODE_STRING* optional
// CountOfRights : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Advapi32 extends StdCallLibrary {
Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class);
int LsaRemoveAccountRights(
long PolicyHandle, // LSA_HANDLE
Pointer AccountSid, // PSID
byte AllRights, // BOOLEAN
Pointer UserRights, // LSA_UNICODE_STRING* optional
int CountOfRights // DWORD
);
}@[Link("advapi32")]
lib LibADVAPI32
fun LsaRemoveAccountRights = LsaRemoveAccountRights(
PolicyHandle : LibC::SSizeT, # LSA_HANDLE
AccountSid : Void*, # PSID
AllRights : UInt8, # BOOLEAN
UserRights : LSA_UNICODE_STRING*, # LSA_UNICODE_STRING* optional
CountOfRights : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef LsaRemoveAccountRightsNative = Int32 Function(IntPtr, Pointer<Void>, Uint8, Pointer<Void>, Uint32);
typedef LsaRemoveAccountRightsDart = int Function(int, Pointer<Void>, int, Pointer<Void>, int);
final LsaRemoveAccountRights = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<LsaRemoveAccountRightsNative, LsaRemoveAccountRightsDart>('LsaRemoveAccountRights');
// PolicyHandle : LSA_HANDLE -> IntPtr
// AccountSid : PSID -> Pointer<Void>
// AllRights : BOOLEAN -> Uint8
// UserRights : LSA_UNICODE_STRING* optional -> Pointer<Void>
// CountOfRights : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function LsaRemoveAccountRights(
PolicyHandle: NativeInt; // LSA_HANDLE
AccountSid: THandle; // PSID
AllRights: ByteBool; // BOOLEAN
UserRights: Pointer; // LSA_UNICODE_STRING* optional
CountOfRights: DWORD // DWORD
): Integer; stdcall;
external 'ADVAPI32.dll' name 'LsaRemoveAccountRights';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "LsaRemoveAccountRights"
c_LsaRemoveAccountRights :: CIntPtr -> Ptr () -> Word8 -> Ptr () -> Word32 -> IO Int32
-- PolicyHandle : LSA_HANDLE -> CIntPtr
-- AccountSid : PSID -> Ptr ()
-- AllRights : BOOLEAN -> Word8
-- UserRights : LSA_UNICODE_STRING* optional -> Ptr ()
-- CountOfRights : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let lsaremoveaccountrights =
foreign "LsaRemoveAccountRights"
(intptr_t @-> (ptr void) @-> uint8_t @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* PolicyHandle : LSA_HANDLE -> intptr_t *)
(* AccountSid : PSID -> (ptr void) *)
(* AllRights : BOOLEAN -> uint8_t *)
(* UserRights : LSA_UNICODE_STRING* optional -> (ptr void) *)
(* CountOfRights : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("LsaRemoveAccountRights" lsa-remove-account-rights :convention :stdcall) :int32
(policy-handle :int64) ; LSA_HANDLE
(account-sid :pointer) ; PSID
(all-rights :uint8) ; BOOLEAN
(user-rights :pointer) ; LSA_UNICODE_STRING* optional
(count-of-rights :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $LsaRemoveAccountRights = Win32::API::More->new('ADVAPI32',
'int LsaRemoveAccountRights(LPARAM PolicyHandle, HANDLE AccountSid, BYTE AllRights, LPVOID UserRights, DWORD CountOfRights)');
# my $ret = $LsaRemoveAccountRights->Call($PolicyHandle, $AccountSid, $AllRights, $UserRights, $CountOfRights);
# PolicyHandle : LSA_HANDLE -> LPARAM
# AccountSid : PSID -> HANDLE
# AllRights : BOOLEAN -> BYTE
# UserRights : LSA_UNICODE_STRING* optional -> LPVOID
# CountOfRights : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型