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取得するポリシー情報の種別を示す列挙値。
InfoBufferSizeDWORDinInfoBufferのバイト数。
InfoBuffervoid*out取得したポリシー情報を受け取る出力バッファ。
InfoBufferRetSizeDWORD*out実際に書き込まれた/必要なバイト数を受け取る出力先。
lpReservedvoid*optional予約パラメータ。NULLを指定する。

戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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)。
const std = @import("std");

extern "advapi32" fn SaferGetPolicyInformation(
    dwScopeId: u32, // DWORD
    SaferPolicyInfoClass: i32, // SAFER_POLICY_INFO_CLASS
    InfoBufferSize: u32, // DWORD
    InfoBuffer: ?*anyopaque, // void* out
    InfoBufferRetSize: [*c]u32, // DWORD* out
    lpReserved: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;
proc SaferGetPolicyInformation(
    dwScopeId: uint32,  # DWORD
    SaferPolicyInfoClass: int32,  # SAFER_POLICY_INFO_CLASS
    InfoBufferSize: uint32,  # DWORD
    InfoBuffer: pointer,  # void* out
    InfoBufferRetSize: ptr uint32,  # DWORD* out
    lpReserved: pointer  # void* optional
): int32 {.importc: "SaferGetPolicyInformation", stdcall, dynlib: "ADVAPI32.dll".}
pragma(lib, "advapi32");
extern(Windows)
int SaferGetPolicyInformation(
    uint dwScopeId,   // DWORD
    int SaferPolicyInfoClass,   // SAFER_POLICY_INFO_CLASS
    uint InfoBufferSize,   // DWORD
    void* InfoBuffer,   // void* out
    uint* InfoBufferRetSize,   // DWORD* out
    void* lpReserved   // void* optional
);
ccall((:SaferGetPolicyInformation, "ADVAPI32.dll"), stdcall, Int32,
      (UInt32, Int32, UInt32, Ptr{Cvoid}, Ptr{UInt32}, Ptr{Cvoid}),
      dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, InfoBufferRetSize, lpReserved)
# dwScopeId : DWORD -> UInt32
# SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> Int32
# InfoBufferSize : DWORD -> UInt32
# InfoBuffer : void* out -> Ptr{Cvoid}
# InfoBufferRetSize : DWORD* out -> Ptr{UInt32}
# lpReserved : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SaferGetPolicyInformation(
    uint32_t dwScopeId,
    int32_t SaferPolicyInfoClass,
    uint32_t InfoBufferSize,
    void* InfoBuffer,
    uint32_t* InfoBufferRetSize,
    void* lpReserved);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.SaferGetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, InfoBufferRetSize, lpReserved)
-- dwScopeId : DWORD
-- SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS
-- InfoBufferSize : DWORD
-- InfoBuffer : void* out
-- InfoBufferRetSize : DWORD* out
-- lpReserved : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const SaferGetPolicyInformation = lib.func('__stdcall', 'SaferGetPolicyInformation', 'int32_t', ['uint32_t', 'int32_t', 'uint32_t', 'void *', 'uint32_t *', 'void *']);
// SaferGetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, InfoBufferRetSize, lpReserved)
// dwScopeId : DWORD -> 'uint32_t'
// SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> 'int32_t'
// InfoBufferSize : DWORD -> 'uint32_t'
// InfoBuffer : void* out -> 'void *'
// InfoBufferRetSize : DWORD* out -> 'uint32_t *'
// lpReserved : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ADVAPI32.dll", {
  SaferGetPolicyInformation: { parameters: ["u32", "i32", "u32", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SaferGetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, InfoBufferRetSize, lpReserved)
// dwScopeId : DWORD -> "u32"
// SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> "i32"
// InfoBufferSize : DWORD -> "u32"
// InfoBuffer : void* out -> "pointer"
// InfoBufferRetSize : DWORD* out -> "pointer"
// lpReserved : void* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SaferGetPolicyInformation(
    uint32_t dwScopeId,
    int32_t SaferPolicyInfoClass,
    uint32_t InfoBufferSize,
    void* InfoBuffer,
    uint32_t* InfoBufferRetSize,
    void* lpReserved);
C, "ADVAPI32.dll");
// $ffi->SaferGetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, InfoBufferRetSize, lpReserved);
// dwScopeId : DWORD
// SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS
// InfoBufferSize : DWORD
// InfoBuffer : void* out
// InfoBufferRetSize : DWORD* out
// lpReserved : void* optional
// 構造体/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);
    boolean SaferGetPolicyInformation(
        int dwScopeId,   // DWORD
        int SaferPolicyInfoClass,   // SAFER_POLICY_INFO_CLASS
        int InfoBufferSize,   // DWORD
        Pointer InfoBuffer,   // void* out
        IntByReference InfoBufferRetSize,   // DWORD* out
        Pointer lpReserved   // void* optional
    );
}
@[Link("advapi32")]
lib LibADVAPI32
  fun SaferGetPolicyInformation = SaferGetPolicyInformation(
    dwScopeId : UInt32,   # DWORD
    SaferPolicyInfoClass : Int32,   # SAFER_POLICY_INFO_CLASS
    InfoBufferSize : UInt32,   # DWORD
    InfoBuffer : Void*,   # void* out
    InfoBufferRetSize : UInt32*,   # DWORD* out
    lpReserved : Void*   # void* optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SaferGetPolicyInformationNative = Int32 Function(Uint32, Int32, Uint32, Pointer<Void>, Pointer<Uint32>, Pointer<Void>);
typedef SaferGetPolicyInformationDart = int Function(int, int, int, Pointer<Void>, Pointer<Uint32>, Pointer<Void>);
final SaferGetPolicyInformation = DynamicLibrary.open('ADVAPI32.dll')
    .lookupFunction<SaferGetPolicyInformationNative, SaferGetPolicyInformationDart>('SaferGetPolicyInformation');
// dwScopeId : DWORD -> Uint32
// SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> Int32
// InfoBufferSize : DWORD -> Uint32
// InfoBuffer : void* out -> Pointer<Void>
// InfoBufferRetSize : DWORD* out -> Pointer<Uint32>
// lpReserved : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SaferGetPolicyInformation"
  c_SaferGetPolicyInformation :: Word32 -> Int32 -> Word32 -> Ptr () -> Ptr Word32 -> Ptr () -> IO CInt
-- dwScopeId : DWORD -> Word32
-- SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> Int32
-- InfoBufferSize : DWORD -> Word32
-- InfoBuffer : void* out -> Ptr ()
-- InfoBufferRetSize : DWORD* out -> Ptr Word32
-- lpReserved : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let safergetpolicyinformation =
  foreign "SaferGetPolicyInformation"
    (uint32_t @-> int32_t @-> uint32_t @-> (ptr void) @-> (ptr uint32_t) @-> (ptr void) @-> returning int32_t)
(* dwScopeId : DWORD -> uint32_t *)
(* SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> int32_t *)
(* InfoBufferSize : DWORD -> uint32_t *)
(* InfoBuffer : void* out -> (ptr void) *)
(* InfoBufferRetSize : DWORD* out -> (ptr uint32_t) *)
(* lpReserved : void* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)

(cffi:defcfun ("SaferGetPolicyInformation" safer-get-policy-information :convention :stdcall) :int32
  (dw-scope-id :uint32)   ; DWORD
  (safer-policy-info-class :int32)   ; SAFER_POLICY_INFO_CLASS
  (info-buffer-size :uint32)   ; DWORD
  (info-buffer :pointer)   ; void* out
  (info-buffer-ret-size :pointer)   ; DWORD* out
  (lp-reserved :pointer))   ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SaferGetPolicyInformation = Win32::API::More->new('ADVAPI32',
    'BOOL SaferGetPolicyInformation(DWORD dwScopeId, int SaferPolicyInfoClass, DWORD InfoBufferSize, LPVOID InfoBuffer, LPVOID InfoBufferRetSize, LPVOID lpReserved)');
# my $ret = $SaferGetPolicyInformation->Call($dwScopeId, $SaferPolicyInfoClass, $InfoBufferSize, $InfoBuffer, $InfoBufferRetSize, $lpReserved);
# dwScopeId : DWORD -> DWORD
# SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> int
# InfoBufferSize : DWORD -> DWORD
# InfoBuffer : void* out -> LPVOID
# InfoBufferRetSize : DWORD* out -> LPVOID
# lpReserved : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型