GetUserObjectSecurity
関数ユーザーオブジェクトのセキュリティ記述子を取得する。
シグネチャ
// USER32.dll
#include <windows.h>
BOOL GetUserObjectSecurity(
HANDLE hObj,
DWORD* pSIRequested,
PSECURITY_DESCRIPTOR pSID, // optional
DWORD nLength,
DWORD* lpnLengthNeeded
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hObj | HANDLE | in |
| pSIRequested | DWORD* | in |
| pSID | PSECURITY_DESCRIPTOR | outoptional |
| nLength | DWORD | in |
| lpnLengthNeeded | DWORD* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
BOOL GetUserObjectSecurity(
HANDLE hObj,
DWORD* pSIRequested,
PSECURITY_DESCRIPTOR pSID, // optional
DWORD nLength,
DWORD* lpnLengthNeeded
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetUserObjectSecurity(
IntPtr hObj, // HANDLE
ref uint pSIRequested, // DWORD*
IntPtr pSID, // PSECURITY_DESCRIPTOR optional, out
uint nLength, // DWORD
out uint lpnLengthNeeded // DWORD* out
);<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetUserObjectSecurity(
hObj As IntPtr, ' HANDLE
ByRef pSIRequested As UInteger, ' DWORD*
pSID As IntPtr, ' PSECURITY_DESCRIPTOR optional, out
nLength As UInteger, ' DWORD
<Out> ByRef lpnLengthNeeded As UInteger ' DWORD* out
) As Boolean
End Function' hObj : HANDLE
' pSIRequested : DWORD*
' pSID : PSECURITY_DESCRIPTOR optional, out
' nLength : DWORD
' lpnLengthNeeded : DWORD* out
Declare PtrSafe Function GetUserObjectSecurity Lib "user32" ( _
ByVal hObj As LongPtr, _
ByRef pSIRequested As Long, _
ByVal pSID As LongPtr, _
ByVal nLength As Long, _
ByRef lpnLengthNeeded As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetUserObjectSecurity = ctypes.windll.user32.GetUserObjectSecurity
GetUserObjectSecurity.restype = wintypes.BOOL
GetUserObjectSecurity.argtypes = [
wintypes.HANDLE, # hObj : HANDLE
ctypes.POINTER(wintypes.DWORD), # pSIRequested : DWORD*
wintypes.HANDLE, # pSID : PSECURITY_DESCRIPTOR optional, out
wintypes.DWORD, # nLength : DWORD
ctypes.POINTER(wintypes.DWORD), # lpnLengthNeeded : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
GetUserObjectSecurity = Fiddle::Function.new(
lib['GetUserObjectSecurity'],
[
Fiddle::TYPE_VOIDP, # hObj : HANDLE
Fiddle::TYPE_VOIDP, # pSIRequested : DWORD*
Fiddle::TYPE_VOIDP, # pSID : PSECURITY_DESCRIPTOR optional, out
-Fiddle::TYPE_INT, # nLength : DWORD
Fiddle::TYPE_VOIDP, # lpnLengthNeeded : DWORD* out
],
Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn GetUserObjectSecurity(
hObj: *mut core::ffi::c_void, // HANDLE
pSIRequested: *mut u32, // DWORD*
pSID: *mut core::ffi::c_void, // PSECURITY_DESCRIPTOR optional, out
nLength: u32, // DWORD
lpnLengthNeeded: *mut u32 // DWORD* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true)]
public static extern bool GetUserObjectSecurity(IntPtr hObj, ref uint pSIRequested, IntPtr pSID, uint nLength, out uint lpnLengthNeeded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetUserObjectSecurity' -Namespace Win32 -PassThru
# $api::GetUserObjectSecurity(hObj, pSIRequested, pSID, nLength, lpnLengthNeeded)#uselib "USER32.dll"
#func global GetUserObjectSecurity "GetUserObjectSecurity" sptr, sptr, sptr, sptr, sptr
; GetUserObjectSecurity hObj, varptr(pSIRequested), pSID, nLength, varptr(lpnLengthNeeded) ; 戻り値は stat
; hObj : HANDLE -> "sptr"
; pSIRequested : DWORD* -> "sptr"
; pSID : PSECURITY_DESCRIPTOR optional, out -> "sptr"
; nLength : DWORD -> "sptr"
; lpnLengthNeeded : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global GetUserObjectSecurity "GetUserObjectSecurity" sptr, var, sptr, int, var ; res = GetUserObjectSecurity(hObj, pSIRequested, pSID, nLength, lpnLengthNeeded) ; hObj : HANDLE -> "sptr" ; pSIRequested : DWORD* -> "var" ; pSID : PSECURITY_DESCRIPTOR optional, out -> "sptr" ; nLength : DWORD -> "int" ; lpnLengthNeeded : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global GetUserObjectSecurity "GetUserObjectSecurity" sptr, sptr, sptr, int, sptr ; res = GetUserObjectSecurity(hObj, varptr(pSIRequested), pSID, nLength, varptr(lpnLengthNeeded)) ; hObj : HANDLE -> "sptr" ; pSIRequested : DWORD* -> "sptr" ; pSID : PSECURITY_DESCRIPTOR optional, out -> "sptr" ; nLength : DWORD -> "int" ; lpnLengthNeeded : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetUserObjectSecurity(HANDLE hObj, DWORD* pSIRequested, PSECURITY_DESCRIPTOR pSID, DWORD nLength, DWORD* lpnLengthNeeded) #uselib "USER32.dll" #cfunc global GetUserObjectSecurity "GetUserObjectSecurity" intptr, var, intptr, int, var ; res = GetUserObjectSecurity(hObj, pSIRequested, pSID, nLength, lpnLengthNeeded) ; hObj : HANDLE -> "intptr" ; pSIRequested : DWORD* -> "var" ; pSID : PSECURITY_DESCRIPTOR optional, out -> "intptr" ; nLength : DWORD -> "int" ; lpnLengthNeeded : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetUserObjectSecurity(HANDLE hObj, DWORD* pSIRequested, PSECURITY_DESCRIPTOR pSID, DWORD nLength, DWORD* lpnLengthNeeded) #uselib "USER32.dll" #cfunc global GetUserObjectSecurity "GetUserObjectSecurity" intptr, intptr, intptr, int, intptr ; res = GetUserObjectSecurity(hObj, varptr(pSIRequested), pSID, nLength, varptr(lpnLengthNeeded)) ; hObj : HANDLE -> "intptr" ; pSIRequested : DWORD* -> "intptr" ; pSID : PSECURITY_DESCRIPTOR optional, out -> "intptr" ; nLength : DWORD -> "int" ; lpnLengthNeeded : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procGetUserObjectSecurity = user32.NewProc("GetUserObjectSecurity")
)
// hObj (HANDLE), pSIRequested (DWORD*), pSID (PSECURITY_DESCRIPTOR optional, out), nLength (DWORD), lpnLengthNeeded (DWORD* out)
r1, _, err := procGetUserObjectSecurity.Call(
uintptr(hObj),
uintptr(pSIRequested),
uintptr(pSID),
uintptr(nLength),
uintptr(lpnLengthNeeded),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetUserObjectSecurity(
hObj: THandle; // HANDLE
pSIRequested: Pointer; // DWORD*
pSID: THandle; // PSECURITY_DESCRIPTOR optional, out
nLength: DWORD; // DWORD
lpnLengthNeeded: Pointer // DWORD* out
): BOOL; stdcall;
external 'USER32.dll' name 'GetUserObjectSecurity';result := DllCall("USER32\GetUserObjectSecurity"
, "Ptr", hObj ; HANDLE
, "Ptr", pSIRequested ; DWORD*
, "Ptr", pSID ; PSECURITY_DESCRIPTOR optional, out
, "UInt", nLength ; DWORD
, "Ptr", lpnLengthNeeded ; DWORD* out
, "Int") ; return: BOOL●GetUserObjectSecurity(hObj, pSIRequested, pSID, nLength, lpnLengthNeeded) = DLL("USER32.dll", "bool GetUserObjectSecurity(void*, void*, void*, dword, void*)")
# 呼び出し: GetUserObjectSecurity(hObj, pSIRequested, pSID, nLength, lpnLengthNeeded)
# hObj : HANDLE -> "void*"
# pSIRequested : DWORD* -> "void*"
# pSID : PSECURITY_DESCRIPTOR optional, out -> "void*"
# nLength : DWORD -> "dword"
# lpnLengthNeeded : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。