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

SetSecurityDescriptorGroup

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

シグネチャ

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

BOOL SetSecurityDescriptorGroup(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    PSID pGroup,   // optional
    BOOL bGroupDefaulted
);

パラメーター

名前方向
pSecurityDescriptorPSECURITY_DESCRIPTORinout
pGroupPSIDinoptional
bGroupDefaultedBOOLin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

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

lib = Fiddle.dlopen('ADVAPI32.dll')
SetSecurityDescriptorGroup = Fiddle::Function.new(
  lib['SetSecurityDescriptorGroup'],
  [
    Fiddle::TYPE_VOIDP,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out
    Fiddle::TYPE_VOIDP,  # pGroup : PSID optional
    Fiddle::TYPE_INT,  # bGroupDefaulted : BOOL
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn SetSecurityDescriptorGroup(
        pSecurityDescriptor: *mut core::ffi::c_void,  // PSECURITY_DESCRIPTOR in/out
        pGroup: *mut core::ffi::c_void,  // PSID optional
        bGroupDefaulted: i32  // BOOL
    ) -> 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 SetSecurityDescriptorGroup(IntPtr pSecurityDescriptor, IntPtr pGroup, bool bGroupDefaulted);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_SetSecurityDescriptorGroup' -Namespace Win32 -PassThru
# $api::SetSecurityDescriptorGroup(pSecurityDescriptor, pGroup, bGroupDefaulted)
#uselib "ADVAPI32.dll"
#func global SetSecurityDescriptorGroup "SetSecurityDescriptorGroup" sptr, sptr, sptr
; SetSecurityDescriptorGroup pSecurityDescriptor, pGroup, bGroupDefaulted   ; 戻り値は stat
; pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "sptr"
; pGroup : PSID optional -> "sptr"
; bGroupDefaulted : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global SetSecurityDescriptorGroup "SetSecurityDescriptorGroup" sptr, sptr, int
; res = SetSecurityDescriptorGroup(pSecurityDescriptor, pGroup, bGroupDefaulted)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "sptr"
; pGroup : PSID optional -> "sptr"
; bGroupDefaulted : BOOL -> "int"
; BOOL SetSecurityDescriptorGroup(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID pGroup, BOOL bGroupDefaulted)
#uselib "ADVAPI32.dll"
#cfunc global SetSecurityDescriptorGroup "SetSecurityDescriptorGroup" intptr, intptr, int
; res = SetSecurityDescriptorGroup(pSecurityDescriptor, pGroup, bGroupDefaulted)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "intptr"
; pGroup : PSID optional -> "intptr"
; bGroupDefaulted : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procSetSecurityDescriptorGroup = advapi32.NewProc("SetSecurityDescriptorGroup")
)

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