ホーム › Security.AppLocker › SaferSetPolicyInformation
SaferSetPolicyInformation
関数ソフトウェア制限ポリシー(SAFER)の情報を設定する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
BOOL SaferSetPolicyInformation(
DWORD dwScopeId,
SAFER_POLICY_INFO_CLASS SaferPolicyInfoClass,
DWORD InfoBufferSize,
void* InfoBuffer,
void* lpReserved // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| dwScopeId | DWORD | in |
| SaferPolicyInfoClass | SAFER_POLICY_INFO_CLASS | in |
| InfoBufferSize | DWORD | in |
| InfoBuffer | void* | in |
| lpReserved | void* | optional |
戻り値の型: BOOL
各言語での呼び出し定義
// ADVAPI32.dll
#include <windows.h>
BOOL SaferSetPolicyInformation(
DWORD dwScopeId,
SAFER_POLICY_INFO_CLASS SaferPolicyInfoClass,
DWORD InfoBufferSize,
void* InfoBuffer,
void* lpReserved // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SaferSetPolicyInformation(
uint dwScopeId, // DWORD
int SaferPolicyInfoClass, // SAFER_POLICY_INFO_CLASS
uint InfoBufferSize, // DWORD
IntPtr InfoBuffer, // void*
IntPtr lpReserved // void* optional
);<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SaferSetPolicyInformation(
dwScopeId As UInteger, ' DWORD
SaferPolicyInfoClass As Integer, ' SAFER_POLICY_INFO_CLASS
InfoBufferSize As UInteger, ' DWORD
InfoBuffer As IntPtr, ' void*
lpReserved As IntPtr ' void* optional
) As Boolean
End Function' dwScopeId : DWORD
' SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS
' InfoBufferSize : DWORD
' InfoBuffer : void*
' lpReserved : void* optional
Declare PtrSafe Function SaferSetPolicyInformation Lib "advapi32" ( _
ByVal dwScopeId As Long, _
ByVal SaferPolicyInfoClass As Long, _
ByVal InfoBufferSize As Long, _
ByVal InfoBuffer As LongPtr, _
ByVal lpReserved As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SaferSetPolicyInformation = ctypes.windll.advapi32.SaferSetPolicyInformation
SaferSetPolicyInformation.restype = wintypes.BOOL
SaferSetPolicyInformation.argtypes = [
wintypes.DWORD, # dwScopeId : DWORD
ctypes.c_int, # SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS
wintypes.DWORD, # InfoBufferSize : DWORD
ctypes.POINTER(None), # InfoBuffer : void*
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')
SaferSetPolicyInformation = Fiddle::Function.new(
lib['SaferSetPolicyInformation'],
[
-Fiddle::TYPE_INT, # dwScopeId : DWORD
Fiddle::TYPE_INT, # SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS
-Fiddle::TYPE_INT, # InfoBufferSize : DWORD
Fiddle::TYPE_VOIDP, # InfoBuffer : void*
Fiddle::TYPE_VOIDP, # lpReserved : void* optional
],
Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn SaferSetPolicyInformation(
dwScopeId: u32, // DWORD
SaferPolicyInfoClass: i32, // SAFER_POLICY_INFO_CLASS
InfoBufferSize: u32, // DWORD
InfoBuffer: *mut (), // void*
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 SaferSetPolicyInformation(uint dwScopeId, int SaferPolicyInfoClass, uint InfoBufferSize, IntPtr InfoBuffer, IntPtr lpReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_SaferSetPolicyInformation' -Namespace Win32 -PassThru
# $api::SaferSetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved)#uselib "ADVAPI32.dll"
#func global SaferSetPolicyInformation "SaferSetPolicyInformation" sptr, sptr, sptr, sptr, sptr
; SaferSetPolicyInformation dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved ; 戻り値は stat
; dwScopeId : DWORD -> "sptr"
; SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> "sptr"
; InfoBufferSize : DWORD -> "sptr"
; InfoBuffer : void* -> "sptr"
; lpReserved : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll"
#cfunc global SaferSetPolicyInformation "SaferSetPolicyInformation" int, int, int, sptr, sptr
; res = SaferSetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved)
; dwScopeId : DWORD -> "int"
; SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> "int"
; InfoBufferSize : DWORD -> "int"
; InfoBuffer : void* -> "sptr"
; lpReserved : void* optional -> "sptr"; BOOL SaferSetPolicyInformation(DWORD dwScopeId, SAFER_POLICY_INFO_CLASS SaferPolicyInfoClass, DWORD InfoBufferSize, void* InfoBuffer, void* lpReserved)
#uselib "ADVAPI32.dll"
#cfunc global SaferSetPolicyInformation "SaferSetPolicyInformation" int, int, int, intptr, intptr
; res = SaferSetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved)
; dwScopeId : DWORD -> "int"
; SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> "int"
; InfoBufferSize : DWORD -> "int"
; InfoBuffer : void* -> "intptr"
; lpReserved : void* optional -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procSaferSetPolicyInformation = advapi32.NewProc("SaferSetPolicyInformation")
)
// dwScopeId (DWORD), SaferPolicyInfoClass (SAFER_POLICY_INFO_CLASS), InfoBufferSize (DWORD), InfoBuffer (void*), lpReserved (void* optional)
r1, _, err := procSaferSetPolicyInformation.Call(
uintptr(dwScopeId),
uintptr(SaferPolicyInfoClass),
uintptr(InfoBufferSize),
uintptr(InfoBuffer),
uintptr(lpReserved),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SaferSetPolicyInformation(
dwScopeId: DWORD; // DWORD
SaferPolicyInfoClass: Integer; // SAFER_POLICY_INFO_CLASS
InfoBufferSize: DWORD; // DWORD
InfoBuffer: Pointer; // void*
lpReserved: Pointer // void* optional
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'SaferSetPolicyInformation';result := DllCall("ADVAPI32\SaferSetPolicyInformation"
, "UInt", dwScopeId ; DWORD
, "Int", SaferPolicyInfoClass ; SAFER_POLICY_INFO_CLASS
, "UInt", InfoBufferSize ; DWORD
, "Ptr", InfoBuffer ; void*
, "Ptr", lpReserved ; void* optional
, "Int") ; return: BOOL●SaferSetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved) = DLL("ADVAPI32.dll", "bool SaferSetPolicyInformation(dword, int, dword, void*, void*)")
# 呼び出し: SaferSetPolicyInformation(dwScopeId, SaferPolicyInfoClass, InfoBufferSize, InfoBuffer, lpReserved)
# dwScopeId : DWORD -> "dword"
# SaferPolicyInfoClass : SAFER_POLICY_INFO_CLASS -> "int"
# InfoBufferSize : DWORD -> "dword"
# InfoBuffer : void* -> "void*"
# lpReserved : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。