Win32 API 日本語リファレンス
ホームSecurity › GetSecurityDescriptorGroup

GetSecurityDescriptorGroup

関数
セキュリティ記述子からプライマリグループSIDを取得する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// ADVAPI32.dll
#include <windows.h>

BOOL GetSecurityDescriptorGroup(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    PSID* pGroup,
    BOOL* lpbGroupDefaulted
);

パラメーター

名前方向
pSecurityDescriptorPSECURITY_DESCRIPTORin
pGroupPSID*out
lpbGroupDefaultedBOOL*out

戻り値の型: BOOL

各言語での呼び出し定義

// ADVAPI32.dll
#include <windows.h>

BOOL GetSecurityDescriptorGroup(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    PSID* pGroup,
    BOOL* lpbGroupDefaulted
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetSecurityDescriptorGroup(
    IntPtr pSecurityDescriptor,   // PSECURITY_DESCRIPTOR
    IntPtr pGroup,   // PSID* out
    out int lpbGroupDefaulted   // BOOL* out
);
<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetSecurityDescriptorGroup(
    pSecurityDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR
    pGroup As IntPtr,   ' PSID* out
    <Out> ByRef lpbGroupDefaulted As Integer   ' BOOL* out
) As Boolean
End Function
' pSecurityDescriptor : PSECURITY_DESCRIPTOR
' pGroup : PSID* out
' lpbGroupDefaulted : BOOL* out
Declare PtrSafe Function GetSecurityDescriptorGroup Lib "advapi32" ( _
    ByVal pSecurityDescriptor As LongPtr, _
    ByVal pGroup As LongPtr, _
    ByRef lpbGroupDefaulted As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetSecurityDescriptorGroup = ctypes.windll.advapi32.GetSecurityDescriptorGroup
GetSecurityDescriptorGroup.restype = wintypes.BOOL
GetSecurityDescriptorGroup.argtypes = [
    wintypes.HANDLE,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
    ctypes.c_void_p,  # pGroup : PSID* out
    ctypes.c_void_p,  # lpbGroupDefaulted : BOOL* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
GetSecurityDescriptorGroup = Fiddle::Function.new(
  lib['GetSecurityDescriptorGroup'],
  [
    Fiddle::TYPE_VOIDP,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
    Fiddle::TYPE_VOIDP,  # pGroup : PSID* out
    Fiddle::TYPE_VOIDP,  # lpbGroupDefaulted : BOOL* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn GetSecurityDescriptorGroup(
        pSecurityDescriptor: *mut core::ffi::c_void,  // PSECURITY_DESCRIPTOR
        pGroup: *mut *mut core::ffi::c_void,  // PSID* out
        lpbGroupDefaulted: *mut i32  // BOOL* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true)]
public static extern bool GetSecurityDescriptorGroup(IntPtr pSecurityDescriptor, IntPtr pGroup, out int lpbGroupDefaulted);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_GetSecurityDescriptorGroup' -Namespace Win32 -PassThru
# $api::GetSecurityDescriptorGroup(pSecurityDescriptor, pGroup, lpbGroupDefaulted)
#uselib "ADVAPI32.dll"
#func global GetSecurityDescriptorGroup "GetSecurityDescriptorGroup" sptr, sptr, sptr
; GetSecurityDescriptorGroup pSecurityDescriptor, pGroup, lpbGroupDefaulted   ; 戻り値は stat
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; pGroup : PSID* out -> "sptr"
; lpbGroupDefaulted : BOOL* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global GetSecurityDescriptorGroup "GetSecurityDescriptorGroup" sptr, sptr, int
; res = GetSecurityDescriptorGroup(pSecurityDescriptor, pGroup, lpbGroupDefaulted)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; pGroup : PSID* out -> "sptr"
; lpbGroupDefaulted : BOOL* out -> "int"
; BOOL GetSecurityDescriptorGroup(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID* pGroup, BOOL* lpbGroupDefaulted)
#uselib "ADVAPI32.dll"
#cfunc global GetSecurityDescriptorGroup "GetSecurityDescriptorGroup" intptr, intptr, int
; res = GetSecurityDescriptorGroup(pSecurityDescriptor, pGroup, lpbGroupDefaulted)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "intptr"
; pGroup : PSID* out -> "intptr"
; lpbGroupDefaulted : BOOL* out -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procGetSecurityDescriptorGroup = advapi32.NewProc("GetSecurityDescriptorGroup")
)

// pSecurityDescriptor (PSECURITY_DESCRIPTOR), pGroup (PSID* out), lpbGroupDefaulted (BOOL* out)
r1, _, err := procGetSecurityDescriptorGroup.Call(
	uintptr(pSecurityDescriptor),
	uintptr(pGroup),
	uintptr(lpbGroupDefaulted),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetSecurityDescriptorGroup(
  pSecurityDescriptor: THandle;   // PSECURITY_DESCRIPTOR
  pGroup: Pointer;   // PSID* out
  lpbGroupDefaulted: Pointer   // BOOL* out
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'GetSecurityDescriptorGroup';
result := DllCall("ADVAPI32\GetSecurityDescriptorGroup"
    , "Ptr", pSecurityDescriptor   ; PSECURITY_DESCRIPTOR
    , "Ptr", pGroup   ; PSID* out
    , "Ptr", lpbGroupDefaulted   ; BOOL* out
    , "Int")   ; return: BOOL
●GetSecurityDescriptorGroup(pSecurityDescriptor, pGroup, lpbGroupDefaulted) = DLL("ADVAPI32.dll", "bool GetSecurityDescriptorGroup(void*, void*, void*)")
# 呼び出し: GetSecurityDescriptorGroup(pSecurityDescriptor, pGroup, lpbGroupDefaulted)
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "void*"
# pGroup : PSID* out -> "void*"
# lpbGroupDefaulted : BOOL* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。