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

CertEnumSystemStore

関数
指定場所のシステム証明書ストアを列挙する。
DLLCRYPT32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

BOOL CertEnumSystemStore(
    DWORD dwFlags,
    void* pvSystemStoreLocationPara,   // optional
    void* pvArg,   // optional
    PFN_CERT_ENUM_SYSTEM_STORE pfnEnum
);

パラメーター

名前方向説明
dwFlagsDWORDin

システムストアの場所を指定します。このパラメーターには、次のいずれかのフラグを指定できます。

さらに、CERT_SYSTEM_STORE_RELOCATE_FLAG は、ビットごとの OR 演算を使用して、いずれかの上位ワードの場所フラグと組み合わせることができます。
pvSystemStoreLocationParavoid*inoptional

dwFlags パラメーターに CERT_SYSTEM_STORE_RELOCATE_FLAG が設定されている場合、pvSystemStoreLocationPara は、システムストアの名前と場所の両方を示す CERT_SYSTEM_STORE_RELOCATE_PARA 構造体を指します。それ以外の場合、pvSystemStoreLocationPara は、システムストアの名前を表す Unicode 文字列へのポインターです。

CERT_SYSTEM_STORE_LOCAL_MACHINE または CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY の場合、リモートコンピューター上のローカルコンピューターストアを列挙するために、pvSystemStoreLocationPara に Unicode のコンピューター名を指定することもできます。たとえば、"\\computer_name" または "computer_name" のように指定します。computer_name の先頭のバックスラッシュ (\) は省略可能です。

CERT_SYSTEM_STORE_SERVICES または CERT_SYSTEM_STORE_USERS の場合、pvSystemStoreLocationParaNULL であれば、この関数はサービス名/ユーザー名と、各サービス名/ユーザー名のストアの両方を列挙します。それ以外の場合、pvSystemStoreLocationPara は、リモートコンピューター名と、利用可能であればサービス名/ユーザー名を含む Unicode 文字列です。たとえば、"service_name"、"\\computer_name"、または "computer_name" のように指定します。

computer_name のみを指定する場合は、先頭のバックスラッシュ (\) または末尾のバックスラッシュ (\) のいずれかを付ける必要があります。そうしないと、service_name または user_name として解釈されます。

pvArgvoid*inoutoptionalvoid へのポインター。アプリケーションは、これを使用してコールバック列挙関数に渡す任意の情報を保持する構造体を宣言、定義、および初期化できます。
pfnEnumPFN_CERT_ENUM_SYSTEM_STOREin各システムストアの詳細を表示するために使用されるコールバック関数へのポインター。このコールバック関数は、各システムストアに関する情報を表示する際の内容と形式を決定します。アプリケーションは、CertEnumSystemStoreCallback コールバック関数を提供する必要があります。

戻り値の型: BOOL

公式ドキュメント

CertEnumSystemStore 関数は、利用可能なシステムストアを取得します。この関数は、見つかったシステムストアごとに、指定されたコールバック関数を呼び出します。

戻り値

関数が成功した場合、TRUE を返します。

関数が失敗した場合、FALSE を返します。

解説(Remarks)

CertEnumSystemStore を使用するには、アプリケーションは ENUM_ARG 構造体と CertEnumSystemStoreCallback コールバック関数を宣言して定義する必要があります。

この関数を使用する例については、 Example C Program: Listing System and Physical Stores を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

BOOL CertEnumSystemStore(
    DWORD dwFlags,
    void* pvSystemStoreLocationPara,   // optional
    void* pvArg,   // optional
    PFN_CERT_ENUM_SYSTEM_STORE pfnEnum
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", ExactSpelling = true)]
static extern bool CertEnumSystemStore(
    uint dwFlags,   // DWORD
    IntPtr pvSystemStoreLocationPara,   // void* optional
    IntPtr pvArg,   // void* optional, in/out
    IntPtr pfnEnum   // PFN_CERT_ENUM_SYSTEM_STORE
);
<DllImport("CRYPT32.dll", ExactSpelling:=True)>
Public Shared Function CertEnumSystemStore(
    dwFlags As UInteger,   ' DWORD
    pvSystemStoreLocationPara As IntPtr,   ' void* optional
    pvArg As IntPtr,   ' void* optional, in/out
    pfnEnum As IntPtr   ' PFN_CERT_ENUM_SYSTEM_STORE
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' dwFlags : DWORD
' pvSystemStoreLocationPara : void* optional
' pvArg : void* optional, in/out
' pfnEnum : PFN_CERT_ENUM_SYSTEM_STORE
Declare PtrSafe Function CertEnumSystemStore Lib "crypt32" ( _
    ByVal dwFlags As Long, _
    ByVal pvSystemStoreLocationPara As LongPtr, _
    ByVal pvArg As LongPtr, _
    ByVal pfnEnum As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CertEnumSystemStore = ctypes.windll.crypt32.CertEnumSystemStore
CertEnumSystemStore.restype = wintypes.BOOL
CertEnumSystemStore.argtypes = [
    wintypes.DWORD,  # dwFlags : DWORD
    ctypes.POINTER(None),  # pvSystemStoreLocationPara : void* optional
    ctypes.POINTER(None),  # pvArg : void* optional, in/out
    ctypes.c_void_p,  # pfnEnum : PFN_CERT_ENUM_SYSTEM_STORE
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CRYPT32.dll')
CertEnumSystemStore = Fiddle::Function.new(
  lib['CertEnumSystemStore'],
  [
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
    Fiddle::TYPE_VOIDP,  # pvSystemStoreLocationPara : void* optional
    Fiddle::TYPE_VOIDP,  # pvArg : void* optional, in/out
    Fiddle::TYPE_VOIDP,  # pfnEnum : PFN_CERT_ENUM_SYSTEM_STORE
  ],
  Fiddle::TYPE_INT)
#[link(name = "crypt32")]
extern "system" {
    fn CertEnumSystemStore(
        dwFlags: u32,  // DWORD
        pvSystemStoreLocationPara: *mut (),  // void* optional
        pvArg: *mut (),  // void* optional, in/out
        pfnEnum: *const core::ffi::c_void  // PFN_CERT_ENUM_SYSTEM_STORE
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll")]
public static extern bool CertEnumSystemStore(uint dwFlags, IntPtr pvSystemStoreLocationPara, IntPtr pvArg, IntPtr pfnEnum);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CertEnumSystemStore' -Namespace Win32 -PassThru
# $api::CertEnumSystemStore(dwFlags, pvSystemStoreLocationPara, pvArg, pfnEnum)
#uselib "CRYPT32.dll"
#func global CertEnumSystemStore "CertEnumSystemStore" sptr, sptr, sptr, sptr
; CertEnumSystemStore dwFlags, pvSystemStoreLocationPara, pvArg, pfnEnum   ; 戻り値は stat
; dwFlags : DWORD -> "sptr"
; pvSystemStoreLocationPara : void* optional -> "sptr"
; pvArg : void* optional, in/out -> "sptr"
; pfnEnum : PFN_CERT_ENUM_SYSTEM_STORE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "CRYPT32.dll"
#cfunc global CertEnumSystemStore "CertEnumSystemStore" int, sptr, sptr, sptr
; res = CertEnumSystemStore(dwFlags, pvSystemStoreLocationPara, pvArg, pfnEnum)
; dwFlags : DWORD -> "int"
; pvSystemStoreLocationPara : void* optional -> "sptr"
; pvArg : void* optional, in/out -> "sptr"
; pfnEnum : PFN_CERT_ENUM_SYSTEM_STORE -> "sptr"
; BOOL CertEnumSystemStore(DWORD dwFlags, void* pvSystemStoreLocationPara, void* pvArg, PFN_CERT_ENUM_SYSTEM_STORE pfnEnum)
#uselib "CRYPT32.dll"
#cfunc global CertEnumSystemStore "CertEnumSystemStore" int, intptr, intptr, intptr
; res = CertEnumSystemStore(dwFlags, pvSystemStoreLocationPara, pvArg, pfnEnum)
; dwFlags : DWORD -> "int"
; pvSystemStoreLocationPara : void* optional -> "intptr"
; pvArg : void* optional, in/out -> "intptr"
; pfnEnum : PFN_CERT_ENUM_SYSTEM_STORE -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCertEnumSystemStore = crypt32.NewProc("CertEnumSystemStore")
)

// dwFlags (DWORD), pvSystemStoreLocationPara (void* optional), pvArg (void* optional, in/out), pfnEnum (PFN_CERT_ENUM_SYSTEM_STORE)
r1, _, err := procCertEnumSystemStore.Call(
	uintptr(dwFlags),
	uintptr(pvSystemStoreLocationPara),
	uintptr(pvArg),
	uintptr(pfnEnum),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CertEnumSystemStore(
  dwFlags: DWORD;   // DWORD
  pvSystemStoreLocationPara: Pointer;   // void* optional
  pvArg: Pointer;   // void* optional, in/out
  pfnEnum: Pointer   // PFN_CERT_ENUM_SYSTEM_STORE
): BOOL; stdcall;
  external 'CRYPT32.dll' name 'CertEnumSystemStore';
result := DllCall("CRYPT32\CertEnumSystemStore"
    , "UInt", dwFlags   ; DWORD
    , "Ptr", pvSystemStoreLocationPara   ; void* optional
    , "Ptr", pvArg   ; void* optional, in/out
    , "Ptr", pfnEnum   ; PFN_CERT_ENUM_SYSTEM_STORE
    , "Int")   ; return: BOOL
●CertEnumSystemStore(dwFlags, pvSystemStoreLocationPara, pvArg, pfnEnum) = DLL("CRYPT32.dll", "bool CertEnumSystemStore(dword, void*, void*, void*)")
# 呼び出し: CertEnumSystemStore(dwFlags, pvSystemStoreLocationPara, pvArg, pfnEnum)
# dwFlags : DWORD -> "dword"
# pvSystemStoreLocationPara : void* optional -> "void*"
# pvArg : void* optional, in/out -> "void*"
# pfnEnum : PFN_CERT_ENUM_SYSTEM_STORE -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef CertEnumSystemStoreNative = Int32 Function(Uint32, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef CertEnumSystemStoreDart = int Function(int, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final CertEnumSystemStore = DynamicLibrary.open('CRYPT32.dll')
    .lookupFunction<CertEnumSystemStoreNative, CertEnumSystemStoreDart>('CertEnumSystemStore');
// dwFlags : DWORD -> Uint32
// pvSystemStoreLocationPara : void* optional -> Pointer<Void>
// pvArg : void* optional, in/out -> Pointer<Void>
// pfnEnum : PFN_CERT_ENUM_SYSTEM_STORE -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CertEnumSystemStore(
  dwFlags: DWORD;   // DWORD
  pvSystemStoreLocationPara: Pointer;   // void* optional
  pvArg: Pointer;   // void* optional, in/out
  pfnEnum: Pointer   // PFN_CERT_ENUM_SYSTEM_STORE
): BOOL; stdcall;
  external 'CRYPT32.dll' name 'CertEnumSystemStore';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CertEnumSystemStore"
  c_CertEnumSystemStore :: Word32 -> Ptr () -> Ptr () -> Ptr () -> IO CInt
-- dwFlags : DWORD -> Word32
-- pvSystemStoreLocationPara : void* optional -> Ptr ()
-- pvArg : void* optional, in/out -> Ptr ()
-- pfnEnum : PFN_CERT_ENUM_SYSTEM_STORE -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let certenumsystemstore =
  foreign "CertEnumSystemStore"
    (uint32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* dwFlags : DWORD -> uint32_t *)
(* pvSystemStoreLocationPara : void* optional -> (ptr void) *)
(* pvArg : void* optional, in/out -> (ptr void) *)
(* pfnEnum : PFN_CERT_ENUM_SYSTEM_STORE -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library crypt32 (t "CRYPT32.dll"))
(cffi:use-foreign-library crypt32)

(cffi:defcfun ("CertEnumSystemStore" cert-enum-system-store :convention :stdcall) :int32
  (dw-flags :uint32)   ; DWORD
  (pv-system-store-location-para :pointer)   ; void* optional
  (pv-arg :pointer)   ; void* optional, in/out
  (pfn-enum :pointer))   ; PFN_CERT_ENUM_SYSTEM_STORE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CertEnumSystemStore = Win32::API::More->new('CRYPT32',
    'BOOL CertEnumSystemStore(DWORD dwFlags, LPVOID pvSystemStoreLocationPara, LPVOID pvArg, LPVOID pfnEnum)');
# my $ret = $CertEnumSystemStore->Call($dwFlags, $pvSystemStoreLocationPara, $pvArg, $pfnEnum);
# dwFlags : DWORD -> DWORD
# pvSystemStoreLocationPara : void* optional -> LPVOID
# pvArg : void* optional, in/out -> LPVOID
# pfnEnum : PFN_CERT_ENUM_SYSTEM_STORE -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。

関連項目

公式の関連項目
使用する型