ホーム › Devices.DeviceAndDriverInstallation › SetupConfigureWmiFromInfSectionW
SetupConfigureWmiFromInfSectionW
関数INFセクションの記述に従いWMIを構成する。
シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupConfigureWmiFromInfSectionW(
void* InfHandle,
LPCWSTR SectionName,
DWORD Flags
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||
|---|---|---|---|---|---|---|---|
| InfHandle | void* | in | 開いている INF ファイルへのハンドル。 | ||||
| SectionName | LPCWSTR | in | WMI セキュリティ情報を含む INF ファイル内のセクションの名前。[DDinstall.WMI] の形式で指定します。 | ||||
| Flags | DWORD | in | このパラメーターには次の値を設定できます。
|
戻り値の型: BOOL
公式ドキュメント
SetupConfigureWmiFromInfSection 関数は、INF ファイルが [DDInstall.WMI] セクションに渡されたときに公開する WMI データのセキュリティを構成します。(Unicode)
戻り値
この関数は WINSETUPAPI BOOL を返します。
解説(Remarks)
以前のバージョンの SetupAPI では、INF ファイル内の WMI 情報はすべてのユーザーに公開されており、アクセスを制限するにはレジストリ キーにバイナリ データを正しく書き込む方法しかありませんでした。現在のバージョンでは、INF ファイルの DDInstall セクションで提供される WMI セキュリティ情報を読み取って処理します。
メモ
setupapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に応じて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして SetupConfigureWmiFromInfSection を定義しています。エンコードに依存しないエイリアスの使用と、エンコードに依存するコードを混在させると、不整合が生じ、コンパイル エラーや実行時エラーの原因となることがあります。詳細については、「Conventions for Function Prototypes」を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupConfigureWmiFromInfSectionW(
void* InfHandle,
LPCWSTR SectionName,
DWORD Flags
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool SetupConfigureWmiFromInfSectionW(
IntPtr InfHandle, // void*
[MarshalAs(UnmanagedType.LPWStr)] string SectionName, // LPCWSTR
uint Flags // DWORD
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SetupConfigureWmiFromInfSectionW(
InfHandle As IntPtr, ' void*
<MarshalAs(UnmanagedType.LPWStr)> SectionName As String, ' LPCWSTR
Flags As UInteger ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' InfHandle : void*
' SectionName : LPCWSTR
' Flags : DWORD
Declare PtrSafe Function SetupConfigureWmiFromInfSectionW Lib "setupapi" ( _
ByVal InfHandle As LongPtr, _
ByVal SectionName As LongPtr, _
ByVal Flags As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetupConfigureWmiFromInfSectionW = ctypes.windll.setupapi.SetupConfigureWmiFromInfSectionW
SetupConfigureWmiFromInfSectionW.restype = wintypes.BOOL
SetupConfigureWmiFromInfSectionW.argtypes = [
ctypes.POINTER(None), # InfHandle : void*
wintypes.LPCWSTR, # SectionName : LPCWSTR
wintypes.DWORD, # Flags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
SetupConfigureWmiFromInfSectionW = Fiddle::Function.new(
lib['SetupConfigureWmiFromInfSectionW'],
[
Fiddle::TYPE_VOIDP, # InfHandle : void*
Fiddle::TYPE_VOIDP, # SectionName : LPCWSTR
-Fiddle::TYPE_INT, # Flags : DWORD
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "setupapi")]
extern "system" {
fn SetupConfigureWmiFromInfSectionW(
InfHandle: *mut (), // void*
SectionName: *const u16, // LPCWSTR
Flags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode)]
public static extern bool SetupConfigureWmiFromInfSectionW(IntPtr InfHandle, [MarshalAs(UnmanagedType.LPWStr)] string SectionName, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupConfigureWmiFromInfSectionW' -Namespace Win32 -PassThru
# $api::SetupConfigureWmiFromInfSectionW(InfHandle, SectionName, Flags)#uselib "SETUPAPI.dll"
#func global SetupConfigureWmiFromInfSectionW "SetupConfigureWmiFromInfSectionW" wptr, wptr, wptr
; SetupConfigureWmiFromInfSectionW InfHandle, SectionName, Flags ; 戻り値は stat
; InfHandle : void* -> "wptr"
; SectionName : LPCWSTR -> "wptr"
; Flags : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SETUPAPI.dll"
#cfunc global SetupConfigureWmiFromInfSectionW "SetupConfigureWmiFromInfSectionW" sptr, wstr, int
; res = SetupConfigureWmiFromInfSectionW(InfHandle, SectionName, Flags)
; InfHandle : void* -> "sptr"
; SectionName : LPCWSTR -> "wstr"
; Flags : DWORD -> "int"; BOOL SetupConfigureWmiFromInfSectionW(void* InfHandle, LPCWSTR SectionName, DWORD Flags)
#uselib "SETUPAPI.dll"
#cfunc global SetupConfigureWmiFromInfSectionW "SetupConfigureWmiFromInfSectionW" intptr, wstr, int
; res = SetupConfigureWmiFromInfSectionW(InfHandle, SectionName, Flags)
; InfHandle : void* -> "intptr"
; SectionName : LPCWSTR -> "wstr"
; Flags : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupConfigureWmiFromInfSectionW = setupapi.NewProc("SetupConfigureWmiFromInfSectionW")
)
// InfHandle (void*), SectionName (LPCWSTR), Flags (DWORD)
r1, _, err := procSetupConfigureWmiFromInfSectionW.Call(
uintptr(InfHandle),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SectionName))),
uintptr(Flags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupConfigureWmiFromInfSectionW(
InfHandle: Pointer; // void*
SectionName: PWideChar; // LPCWSTR
Flags: DWORD // DWORD
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupConfigureWmiFromInfSectionW';result := DllCall("SETUPAPI\SetupConfigureWmiFromInfSectionW"
, "Ptr", InfHandle ; void*
, "WStr", SectionName ; LPCWSTR
, "UInt", Flags ; DWORD
, "Int") ; return: BOOL●SetupConfigureWmiFromInfSectionW(InfHandle, SectionName, Flags) = DLL("SETUPAPI.dll", "bool SetupConfigureWmiFromInfSectionW(void*, char*, dword)")
# 呼び出し: SetupConfigureWmiFromInfSectionW(InfHandle, SectionName, Flags)
# InfHandle : void* -> "void*"
# SectionName : LPCWSTR -> "char*"
# Flags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "setupapi" fn SetupConfigureWmiFromInfSectionW(
InfHandle: ?*anyopaque, // void*
SectionName: [*c]const u16, // LPCWSTR
Flags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SetupConfigureWmiFromInfSectionW(
InfHandle: pointer, # void*
SectionName: WideCString, # LPCWSTR
Flags: uint32 # DWORD
): int32 {.importc: "SetupConfigureWmiFromInfSectionW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "setupapi");
extern(Windows)
int SetupConfigureWmiFromInfSectionW(
void* InfHandle, // void*
const(wchar)* SectionName, // LPCWSTR
uint Flags // DWORD
);ccall((:SetupConfigureWmiFromInfSectionW, "SETUPAPI.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring, UInt32),
InfHandle, SectionName, Flags)
# InfHandle : void* -> Ptr{Cvoid}
# SectionName : LPCWSTR -> Cwstring
# Flags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupConfigureWmiFromInfSectionW(
void* InfHandle,
const uint16_t* SectionName,
uint32_t Flags);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupConfigureWmiFromInfSectionW(InfHandle, SectionName, Flags)
-- InfHandle : void*
-- SectionName : LPCWSTR
-- Flags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupConfigureWmiFromInfSectionW = lib.func('__stdcall', 'SetupConfigureWmiFromInfSectionW', 'int32_t', ['void *', 'str16', 'uint32_t']);
// SetupConfigureWmiFromInfSectionW(InfHandle, SectionName, Flags)
// InfHandle : void* -> 'void *'
// SectionName : LPCWSTR -> 'str16'
// Flags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupConfigureWmiFromInfSectionW: { parameters: ["pointer", "buffer", "u32"], result: "i32" },
});
// lib.symbols.SetupConfigureWmiFromInfSectionW(InfHandle, SectionName, Flags)
// InfHandle : void* -> "pointer"
// SectionName : LPCWSTR -> "buffer"
// Flags : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupConfigureWmiFromInfSectionW(
void* InfHandle,
const uint16_t* SectionName,
uint32_t Flags);
C, "SETUPAPI.dll");
// $ffi->SetupConfigureWmiFromInfSectionW(InfHandle, SectionName, Flags);
// InfHandle : void*
// SectionName : LPCWSTR
// Flags : DWORD
// 構造体/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 Setupapi extends StdCallLibrary {
Setupapi INSTANCE = Native.load("setupapi", Setupapi.class, W32APIOptions.UNICODE_OPTIONS);
boolean SetupConfigureWmiFromInfSectionW(
Pointer InfHandle, // void*
WString SectionName, // LPCWSTR
int Flags // DWORD
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("setupapi")]
lib LibSETUPAPI
fun SetupConfigureWmiFromInfSectionW = SetupConfigureWmiFromInfSectionW(
InfHandle : Void*, # void*
SectionName : UInt16*, # LPCWSTR
Flags : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetupConfigureWmiFromInfSectionWNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Uint32);
typedef SetupConfigureWmiFromInfSectionWDart = int Function(Pointer<Void>, Pointer<Utf16>, int);
final SetupConfigureWmiFromInfSectionW = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupConfigureWmiFromInfSectionWNative, SetupConfigureWmiFromInfSectionWDart>('SetupConfigureWmiFromInfSectionW');
// InfHandle : void* -> Pointer<Void>
// SectionName : LPCWSTR -> Pointer<Utf16>
// Flags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupConfigureWmiFromInfSectionW(
InfHandle: Pointer; // void*
SectionName: PWideChar; // LPCWSTR
Flags: DWORD // DWORD
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupConfigureWmiFromInfSectionW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupConfigureWmiFromInfSectionW"
c_SetupConfigureWmiFromInfSectionW :: Ptr () -> CWString -> Word32 -> IO CInt
-- InfHandle : void* -> Ptr ()
-- SectionName : LPCWSTR -> CWString
-- Flags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupconfigurewmifrominfsectionw =
foreign "SetupConfigureWmiFromInfSectionW"
((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> returning int32_t)
(* InfHandle : void* -> (ptr void) *)
(* SectionName : LPCWSTR -> (ptr uint16_t) *)
(* Flags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)
(cffi:defcfun ("SetupConfigureWmiFromInfSectionW" setup-configure-wmi-from-inf-section-w :convention :stdcall) :int32
(inf-handle :pointer) ; void*
(section-name (:string :encoding :utf-16le)) ; LPCWSTR
(flags :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupConfigureWmiFromInfSectionW = Win32::API::More->new('SETUPAPI',
'BOOL SetupConfigureWmiFromInfSectionW(LPVOID InfHandle, LPCWSTR SectionName, DWORD Flags)');
# my $ret = $SetupConfigureWmiFromInfSectionW->Call($InfHandle, $SectionName, $Flags);
# InfHandle : void* -> LPVOID
# SectionName : LPCWSTR -> LPCWSTR
# Flags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SetupConfigureWmiFromInfSectionA (ANSI版) — INFセクションの記述に従いWMIを構成する。