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

SaferGetPolicyInformation

関数
ソフトウェア制限ポリシー(SAFER)の情報を取得する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SaferGetPolicyInformation(
    DWORD dwScopeId,
    SAFER_POLICY_INFO_CLASS SaferPolicyInfoClass,
    DWORD InfoBufferSize,
    void* InfoBuffer,
    DWORD* InfoBufferRetSize,
    void* lpReserved   // optional
);

パラメーター

名前方向
dwScopeIdDWORDin
SaferPolicyInfoClassSAFER_POLICY_INFO_CLASSin
InfoBufferSizeDWORDin
InfoBuffervoid*out
InfoBufferRetSizeDWORD*out
lpReservedvoid*optional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SaferGetPolicyInformation(
    DWORD dwScopeId,
    SAFER_POLICY_INFO_CLASS SaferPolicyInfoClass,
    DWORD InfoBufferSize,
    void* InfoBuffer,
    DWORD* InfoBufferRetSize,
    void* lpReserved   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SaferGetPolicyInformation(
    uint dwScopeId,   // DWORD
    int SaferPolicyInfoClass,   // SAFER_POLICY_INFO_CLASS
    uint InfoBufferSize,   // DWORD
    IntPtr InfoBuffer,   // void* out
    out uint InfoBufferRetSize,   // DWORD* out
    IntPtr lpReserved   // void* optional
);
<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SaferGetPolicyInformation(
    dwScopeId As UInteger,   ' DWORD
    SaferPolicyInfoClass As Integer,   ' SAFER_POLICY_INFO_CLASS
    InfoBufferSize As UInteger,   ' DWORD
    InfoBuffer As IntPtr,   ' void* out
    <Out> ByRef InfoBufferRetSize As UInteger,   ' DWORD* out
    lpReserved As IntPtr   ' void* optional
) As Boolean
End Function
' dwScopeId : DWORD
' SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS
' InfoBufferSize : DWORD
' InfoBuffer : void* out
' InfoBufferRetSize : DWORD* out
' lpReserved : void* optional
Declare PtrSafe Function SaferGetPolicyInformation Lib "advapi32" ( _
    ByVal dwScopeId As Long, _
    ByVal SaferPolicyInfoClass As Long, _
    ByVal InfoBufferSize As Long, _
    ByVal InfoBuffer As LongPtr, _
    ByRef InfoBufferRetSize As Long, _
    ByVal lpReserved As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SaferGetPolicyInformation = ctypes.windll.advapi32.SaferGetPolicyInformation
SaferGetPolicyInformation.restype = wintypes.BOOL
SaferGetPolicyInformation.argtypes = [
    wintypes.DWORD,  # dwScopeId : DWORD
    ctypes.c_int,  # SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS
    wintypes.DWORD,  # InfoBufferSize : DWORD
    ctypes.POINTER(None),  # InfoBuffer : void* out
    ctypes.POINTER(wintypes.DWORD),  # InfoBufferRetSize : DWORD* out
    ctypes.POINTER(None),  # lpReserved : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
SaferGetPolicyInformation = Fiddle::Function.new(
  lib['SaferGetPolicyInformation'],
  [
    -Fiddle::TYPE_INT,  # dwScopeId : DWORD
    Fiddle::TYPE_INT,  # SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS
    -Fiddle::TYPE_INT,  # InfoBufferSize : DWORD
    Fiddle::TYPE_VOIDP,  # InfoBuffer : void* out
    Fiddle::TYPE_VOIDP,  # InfoBufferRetSize : DWORD* out
    Fiddle::TYPE_VOIDP,  # lpReserved : void* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn SaferGetPolicyInformation(
        dwScopeId: u32,  // DWORD
        SaferPolicyInfoClass: i32,  // SAFER_POLICY_INFO_CLASS
        InfoBufferSize: u32,  // DWORD
        InfoBuffer: *mut (),  // void* out
        InfoBufferRetSize: *mut u32,  // DWORD* out
        lpReserved: *mut ()  // void* optional
    ) -> 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 SaferGetPolicyInformation(uint dwScopeId, int SaferPolicyInfoClass, uint InfoBufferSize, IntPtr InfoBuffer, out uint InfoBufferRetSize, IntPtr lpReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_SaferGetPolicyInformation' -Namespace Win32 -PassThru
# $api::SaferGetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, InfoBufferRetSize, lpReserved)
#uselib "ADVAPI32.dll"
#func global SaferGetPolicyInformation "SaferGetPolicyInformation" sptr, sptr, sptr, sptr, sptr, sptr
; SaferGetPolicyInformation dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, varptr(InfoBufferRetSize), lpReserved   ; 戻り値は stat
; dwScopeId : DWORD -> "sptr"
; SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> "sptr"
; InfoBufferSize : DWORD -> "sptr"
; InfoBuffer : void* out -> "sptr"
; InfoBufferRetSize : DWORD* out -> "sptr"
; lpReserved : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global SaferGetPolicyInformation "SaferGetPolicyInformation" int, int, int, sptr, var, sptr
; res = SaferGetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, InfoBufferRetSize, lpReserved)
; dwScopeId : DWORD -> "int"
; SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> "int"
; InfoBufferSize : DWORD -> "int"
; InfoBuffer : void* out -> "sptr"
; InfoBufferRetSize : DWORD* out -> "var"
; lpReserved : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SaferGetPolicyInformation(DWORD dwScopeId, SAFER_POLICY_INFO_CLASS SaferPolicyInfoClass, DWORD InfoBufferSize, void* InfoBuffer, DWORD* InfoBufferRetSize, void* lpReserved)
#uselib "ADVAPI32.dll"
#cfunc global SaferGetPolicyInformation "SaferGetPolicyInformation" int, int, int, intptr, var, intptr
; res = SaferGetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, InfoBufferRetSize, lpReserved)
; dwScopeId : DWORD -> "int"
; SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> "int"
; InfoBufferSize : DWORD -> "int"
; InfoBuffer : void* out -> "intptr"
; InfoBufferRetSize : DWORD* out -> "var"
; lpReserved : void* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procSaferGetPolicyInformation = advapi32.NewProc("SaferGetPolicyInformation")
)

// dwScopeId (DWORD), SaferPolicyInfoClass (SAFER_POLICY_INFO_CLASS), InfoBufferSize (DWORD), InfoBuffer (void* out), InfoBufferRetSize (DWORD* out), lpReserved (void* optional)
r1, _, err := procSaferGetPolicyInformation.Call(
	uintptr(dwScopeId),
	uintptr(SaferPolicyInfoClass),
	uintptr(InfoBufferSize),
	uintptr(InfoBuffer),
	uintptr(InfoBufferRetSize),
	uintptr(lpReserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SaferGetPolicyInformation(
  dwScopeId: DWORD;   // DWORD
  SaferPolicyInfoClass: Integer;   // SAFER_POLICY_INFO_CLASS
  InfoBufferSize: DWORD;   // DWORD
  InfoBuffer: Pointer;   // void* out
  InfoBufferRetSize: Pointer;   // DWORD* out
  lpReserved: Pointer   // void* optional
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'SaferGetPolicyInformation';
result := DllCall("ADVAPI32\SaferGetPolicyInformation"
    , "UInt", dwScopeId   ; DWORD
    , "Int", SaferPolicyInfoClass   ; SAFER_POLICY_INFO_CLASS
    , "UInt", InfoBufferSize   ; DWORD
    , "Ptr", InfoBuffer   ; void* out
    , "Ptr", InfoBufferRetSize   ; DWORD* out
    , "Ptr", lpReserved   ; void* optional
    , "Int")   ; return: BOOL
●SaferGetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, InfoBufferRetSize, lpReserved) = DLL("ADVAPI32.dll", "bool SaferGetPolicyInformation(dword, int, dword, void*, void*, void*)")
# 呼び出し: SaferGetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, InfoBufferRetSize, lpReserved)
# dwScopeId : DWORD -> "dword"
# SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> "int"
# InfoBufferSize : DWORD -> "dword"
# InfoBuffer : void* out -> "void*"
# InfoBufferRetSize : DWORD* out -> "void*"
# lpReserved : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。