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

SrpDoesPolicyAllowAppExecution

関数
ポリシーが指定パッケージアプリの実行を許可するか判定する。
DLLsrpapi.dll呼出規約winapi対応OSWindows 10 以降

シグネチャ

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

HRESULT SrpDoesPolicyAllowAppExecution(
    const PACKAGE_ID* packageId,
    BOOL* isAllowed
);

パラメーター

名前方向
packageIdPACKAGE_ID*in
isAllowedBOOL*out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SrpDoesPolicyAllowAppExecution(
    const PACKAGE_ID* packageId,
    BOOL* isAllowed
);
[DllImport("srpapi.dll", ExactSpelling = true)]
static extern int SrpDoesPolicyAllowAppExecution(
    IntPtr packageId,   // PACKAGE_ID*
    out int isAllowed   // BOOL* out
);
<DllImport("srpapi.dll", ExactSpelling:=True)>
Public Shared Function SrpDoesPolicyAllowAppExecution(
    packageId As IntPtr,   ' PACKAGE_ID*
    <Out> ByRef isAllowed As Integer   ' BOOL* out
) As Integer
End Function
' packageId : PACKAGE_ID*
' isAllowed : BOOL* out
Declare PtrSafe Function SrpDoesPolicyAllowAppExecution Lib "srpapi" ( _
    ByVal packageId As LongPtr, _
    ByRef isAllowed As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SrpDoesPolicyAllowAppExecution = ctypes.windll.srpapi.SrpDoesPolicyAllowAppExecution
SrpDoesPolicyAllowAppExecution.restype = ctypes.c_int
SrpDoesPolicyAllowAppExecution.argtypes = [
    ctypes.c_void_p,  # packageId : PACKAGE_ID*
    ctypes.c_void_p,  # isAllowed : BOOL* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('srpapi.dll')
SrpDoesPolicyAllowAppExecution = Fiddle::Function.new(
  lib['SrpDoesPolicyAllowAppExecution'],
  [
    Fiddle::TYPE_VOIDP,  # packageId : PACKAGE_ID*
    Fiddle::TYPE_VOIDP,  # isAllowed : BOOL* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "srpapi")]
extern "system" {
    fn SrpDoesPolicyAllowAppExecution(
        packageId: *const PACKAGE_ID,  // PACKAGE_ID*
        isAllowed: *mut i32  // BOOL* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("srpapi.dll")]
public static extern int SrpDoesPolicyAllowAppExecution(IntPtr packageId, out int isAllowed);
"@
$api = Add-Type -MemberDefinition $sig -Name 'srpapi_SrpDoesPolicyAllowAppExecution' -Namespace Win32 -PassThru
# $api::SrpDoesPolicyAllowAppExecution(packageId, isAllowed)
#uselib "srpapi.dll"
#func global SrpDoesPolicyAllowAppExecution "SrpDoesPolicyAllowAppExecution" sptr, sptr
; SrpDoesPolicyAllowAppExecution varptr(packageId), isAllowed   ; 戻り値は stat
; packageId : PACKAGE_ID* -> "sptr"
; isAllowed : BOOL* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "srpapi.dll"
#cfunc global SrpDoesPolicyAllowAppExecution "SrpDoesPolicyAllowAppExecution" var, int
; res = SrpDoesPolicyAllowAppExecution(packageId, isAllowed)
; packageId : PACKAGE_ID* -> "var"
; isAllowed : BOOL* out -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT SrpDoesPolicyAllowAppExecution(PACKAGE_ID* packageId, BOOL* isAllowed)
#uselib "srpapi.dll"
#cfunc global SrpDoesPolicyAllowAppExecution "SrpDoesPolicyAllowAppExecution" var, int
; res = SrpDoesPolicyAllowAppExecution(packageId, isAllowed)
; packageId : PACKAGE_ID* -> "var"
; isAllowed : BOOL* out -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	srpapi = windows.NewLazySystemDLL("srpapi.dll")
	procSrpDoesPolicyAllowAppExecution = srpapi.NewProc("SrpDoesPolicyAllowAppExecution")
)

// packageId (PACKAGE_ID*), isAllowed (BOOL* out)
r1, _, err := procSrpDoesPolicyAllowAppExecution.Call(
	uintptr(packageId),
	uintptr(isAllowed),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SrpDoesPolicyAllowAppExecution(
  packageId: Pointer;   // PACKAGE_ID*
  isAllowed: Pointer   // BOOL* out
): Integer; stdcall;
  external 'srpapi.dll' name 'SrpDoesPolicyAllowAppExecution';
result := DllCall("srpapi\SrpDoesPolicyAllowAppExecution"
    , "Ptr", packageId   ; PACKAGE_ID*
    , "Ptr", isAllowed   ; BOOL* out
    , "Int")   ; return: HRESULT
●SrpDoesPolicyAllowAppExecution(packageId, isAllowed) = DLL("srpapi.dll", "int SrpDoesPolicyAllowAppExecution(void*, void*)")
# 呼び出し: SrpDoesPolicyAllowAppExecution(packageId, isAllowed)
# packageId : PACKAGE_ID* -> "void*"
# isAllowed : BOOL* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。