InstallHinfSectionW
関数シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
void InstallHinfSectionW(
HWND Window,
HINSTANCE ModuleHandle,
LPCWSTR CommandLine,
INT ShowCommand
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Window | HWND | in | 親ウィンドウのハンドル。通常、hwnd は Null です。 |
| ModuleHandle | HINSTANCE | in | 予約済みです。Null にする必要があります。 |
| CommandLine | LPCWSTR | in | コマンドラインを格納するバッファーへのポインター。null 終端文字列を使用してください。 |
| ShowCommand | INT | in | 予約済みです。0 にする必要があります。 |
戻り値の型: void
公式ドキュメント
InstallHinfSection は Setupapi.dll がエクスポートするエントリポイント関数で、.inf ファイル内のセクションを実行するために使用します。InstallHinfSection は、「解説」セクションで説明するように Rundll32.exe ユーティリティを呼び出して起動することもできます。(Unicode)
解説(Remarks)
エクスポートは次の 3 つが存在することに注意してください。 InstallHinfSection (RunDll32 用)、InstallHinfSectionA、InstallHinfSectionW です。
指定した .inf ファイルの Install セクションを実行するには、次の構文を使用して Rundll32.exe から InstallHinfSection を呼び出します。
RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection <section> <mode> <path>
これにより、"<section> <mode> <path>" が CmdLineBuffer に渡されます。
あるいは、プログラムから InstallHinfSection、InstallHinfSectionA、InstallHinfSectionW を直接呼び出し、CmdLineBuffer パラメーターに次の内容を設定することもできます。
"<section> <mode> <path>"
ここで、path は .inf ファイルへの完全パス、mode は再起動モードのパラメーター、section は .inf ファイル内の任意の Install セクションです。コマンドラインでは、SETUPAPI.DLL と InstallHinfSection の間のコンマ区切りが必須です。コマンドライン上で、コンマと SETUPAPI.DLL の間、およびコンマと InstallHinfSection の間に空白を入れることはできない点に注意してください。
path には .inf ファイルへの完全パスを指定することを推奨します。
section には .inf ファイル内の任意の Install セクションを指定できます。空白は使用できません。
mode には次の値を組み合わせて使用します。インストールの既定のパスを INF ファイルの場所に設定するには、128 を含める必要があります。含めない場合は、システム提供の INF と見なされます。再起動の動作を指定するには、値を加算します。推奨される値は 128 または 132 のみであり、それ以外の値を指定すると、不必要にコンピューターが再起動したり、必要なときに再起動しなかったりする場合があることに注意してください。
| 値 | 説明 |
|---|---|
| 0 | システム提供の INF。 |
| 128 | インストールの既定のパスを INF ファイルの場所に設定します。これが一般的な設定です。 |
| +0 | コンピューターを再起動しません。 |
| +1 | あらゆる場合にコンピューターを再起動します。 |
| +2 | 再起動するかどうかを常にユーザーに確認します。 |
| +3 | 再起動が必要な場合、ユーザーに許可を求めずにコンピューターを再起動します。 |
| +4 | コンピューターの再起動が必要な場合、再起動する前にユーザーに許可を求めます。 |
たとえば、次のコマンドラインは Shell.inf ファイルの DefaultInstall セクションを実行します。セットアップが再起動を必要と判断した場合、ユーザーには "Reboot the computer, Yes/No" というダイアログボックスが表示されます。
RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 132 C:\Example\SHELL.INF
setupapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして InstallHinfSection を定義しています。エンコーディング中立のエイリアスと、エンコーディング中立でないコードを混在させて使用すると不一致が生じ、コンパイルエラーや実行時エラーの原因となる場合があります。詳細については、関数プロトタイプの規則を参照してください。
x86 または amd64 以外のアーキテクチャで使用する場合、または S モードのシステムで使用する場合、InstallHInfSection は、INF ファイルに CatalogFile ディレクティブを含む INF Version セクションがあることを必要とします。この CatalogFile ディレクティブは、INF ファイルのハッシュと、その INF ファイルが INF SourceDisksFiles セクションで参照するファイルのハッシュを含む、署名済みカタログファイルを指している必要があります。
ネイティブアーキテクチャが x86 でも amd64 でもないシステムで使用する場合、InstallHInfSection はネイティブアーキテクチャのプロセスから使用してください。非ネイティブアーキテクチャのプロセスから使用すると、InstallHInfSection は多くの種類のシステム状態を変更する操作をブロックします。
InstallHinfSection は、診断情報を SetupAPI アプリケーションインストールテキストログに記録します。このログファイルは、通常は既定で無効になっています。SetupAPI のログレベルの設定で説明されているとおり、SetupAPI の LogLevel 値の General logging levels の部分を変更することで有効にできます。パフォーマンス上の理由から、このログファイルは問題のトラブルシューティングを行うときにのみ有効にしてください。ログファイルを有効にすると、%windir%\inf\setupapi.app.log に出力されます。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
void InstallHinfSectionW(
HWND Window,
HINSTANCE ModuleHandle,
LPCWSTR CommandLine,
INT ShowCommand
);[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern void InstallHinfSectionW(
IntPtr Window, // HWND
IntPtr ModuleHandle, // HINSTANCE
[MarshalAs(UnmanagedType.LPWStr)] string CommandLine, // LPCWSTR
int ShowCommand // INT
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Sub InstallHinfSectionW(
Window As IntPtr, ' HWND
ModuleHandle As IntPtr, ' HINSTANCE
<MarshalAs(UnmanagedType.LPWStr)> CommandLine As String, ' LPCWSTR
ShowCommand As Integer ' INT
)
End Sub' Window : HWND
' ModuleHandle : HINSTANCE
' CommandLine : LPCWSTR
' ShowCommand : INT
Declare PtrSafe Sub InstallHinfSectionW Lib "setupapi" ( _
ByVal Window As LongPtr, _
ByVal ModuleHandle As LongPtr, _
ByVal CommandLine As LongPtr, _
ByVal ShowCommand 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
InstallHinfSectionW = ctypes.windll.setupapi.InstallHinfSectionW
InstallHinfSectionW.restype = None
InstallHinfSectionW.argtypes = [
wintypes.HANDLE, # Window : HWND
wintypes.HANDLE, # ModuleHandle : HINSTANCE
wintypes.LPCWSTR, # CommandLine : LPCWSTR
ctypes.c_int, # ShowCommand : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
InstallHinfSectionW = Fiddle::Function.new(
lib['InstallHinfSectionW'],
[
Fiddle::TYPE_VOIDP, # Window : HWND
Fiddle::TYPE_VOIDP, # ModuleHandle : HINSTANCE
Fiddle::TYPE_VOIDP, # CommandLine : LPCWSTR
Fiddle::TYPE_INT, # ShowCommand : INT
],
Fiddle::TYPE_VOID)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "setupapi")]
extern "system" {
fn InstallHinfSectionW(
Window: *mut core::ffi::c_void, // HWND
ModuleHandle: *mut core::ffi::c_void, // HINSTANCE
CommandLine: *const u16, // LPCWSTR
ShowCommand: i32 // INT
);
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode)]
public static extern void InstallHinfSectionW(IntPtr Window, IntPtr ModuleHandle, [MarshalAs(UnmanagedType.LPWStr)] string CommandLine, int ShowCommand);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_InstallHinfSectionW' -Namespace Win32 -PassThru
# $api::InstallHinfSectionW(Window, ModuleHandle, CommandLine, ShowCommand)#uselib "SETUPAPI.dll"
#func global InstallHinfSectionW "InstallHinfSectionW" wptr, wptr, wptr, wptr
; InstallHinfSectionW Window, ModuleHandle, CommandLine, ShowCommand
; Window : HWND -> "wptr"
; ModuleHandle : HINSTANCE -> "wptr"
; CommandLine : LPCWSTR -> "wptr"
; ShowCommand : INT -> "wptr"#uselib "SETUPAPI.dll"
#func global InstallHinfSectionW "InstallHinfSectionW" sptr, sptr, wstr, int
; InstallHinfSectionW Window, ModuleHandle, CommandLine, ShowCommand
; Window : HWND -> "sptr"
; ModuleHandle : HINSTANCE -> "sptr"
; CommandLine : LPCWSTR -> "wstr"
; ShowCommand : INT -> "int"; void InstallHinfSectionW(HWND Window, HINSTANCE ModuleHandle, LPCWSTR CommandLine, INT ShowCommand)
#uselib "SETUPAPI.dll"
#func global InstallHinfSectionW "InstallHinfSectionW" intptr, intptr, wstr, int
; InstallHinfSectionW Window, ModuleHandle, CommandLine, ShowCommand
; Window : HWND -> "intptr"
; ModuleHandle : HINSTANCE -> "intptr"
; CommandLine : LPCWSTR -> "wstr"
; ShowCommand : INT -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procInstallHinfSectionW = setupapi.NewProc("InstallHinfSectionW")
)
// Window (HWND), ModuleHandle (HINSTANCE), CommandLine (LPCWSTR), ShowCommand (INT)
r1, _, err := procInstallHinfSectionW.Call(
uintptr(Window),
uintptr(ModuleHandle),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(CommandLine))),
uintptr(ShowCommand),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure InstallHinfSectionW(
Window: THandle; // HWND
ModuleHandle: THandle; // HINSTANCE
CommandLine: PWideChar; // LPCWSTR
ShowCommand: Integer // INT
); stdcall;
external 'SETUPAPI.dll' name 'InstallHinfSectionW';result := DllCall("SETUPAPI\InstallHinfSectionW"
, "Ptr", Window ; HWND
, "Ptr", ModuleHandle ; HINSTANCE
, "WStr", CommandLine ; LPCWSTR
, "Int", ShowCommand ; INT
, "Int") ; return: void●InstallHinfSectionW(Window, ModuleHandle, CommandLine, ShowCommand) = DLL("SETUPAPI.dll", "int InstallHinfSectionW(void*, void*, char*, int)")
# 呼び出し: InstallHinfSectionW(Window, ModuleHandle, CommandLine, ShowCommand)
# Window : HWND -> "void*"
# ModuleHandle : HINSTANCE -> "void*"
# CommandLine : LPCWSTR -> "char*"
# ShowCommand : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "setupapi" fn InstallHinfSectionW(
Window: ?*anyopaque, // HWND
ModuleHandle: ?*anyopaque, // HINSTANCE
CommandLine: [*c]const u16, // LPCWSTR
ShowCommand: i32 // INT
) callconv(std.os.windows.WINAPI) void;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc InstallHinfSectionW(
Window: pointer, # HWND
ModuleHandle: pointer, # HINSTANCE
CommandLine: WideCString, # LPCWSTR
ShowCommand: int32 # INT
) {.importc: "InstallHinfSectionW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "setupapi");
extern(Windows)
void InstallHinfSectionW(
void* Window, // HWND
void* ModuleHandle, // HINSTANCE
const(wchar)* CommandLine, // LPCWSTR
int ShowCommand // INT
);ccall((:InstallHinfSectionW, "SETUPAPI.dll"), stdcall, Cvoid,
(Ptr{Cvoid}, Ptr{Cvoid}, Cwstring, Int32),
Window, ModuleHandle, CommandLine, ShowCommand)
# Window : HWND -> Ptr{Cvoid}
# ModuleHandle : HINSTANCE -> Ptr{Cvoid}
# CommandLine : LPCWSTR -> Cwstring
# ShowCommand : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
void InstallHinfSectionW(
void* Window,
void* ModuleHandle,
const uint16_t* CommandLine,
int32_t ShowCommand);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.InstallHinfSectionW(Window, ModuleHandle, CommandLine, ShowCommand)
-- Window : HWND
-- ModuleHandle : HINSTANCE
-- CommandLine : LPCWSTR
-- ShowCommand : INT
-- 構造体/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 InstallHinfSectionW = lib.func('__stdcall', 'InstallHinfSectionW', 'void', ['void *', 'void *', 'str16', 'int32_t']);
// InstallHinfSectionW(Window, ModuleHandle, CommandLine, ShowCommand)
// Window : HWND -> 'void *'
// ModuleHandle : HINSTANCE -> 'void *'
// CommandLine : LPCWSTR -> 'str16'
// ShowCommand : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
InstallHinfSectionW: { parameters: ["pointer", "pointer", "buffer", "i32"], result: "void" },
});
// lib.symbols.InstallHinfSectionW(Window, ModuleHandle, CommandLine, ShowCommand)
// Window : HWND -> "pointer"
// ModuleHandle : HINSTANCE -> "pointer"
// CommandLine : LPCWSTR -> "buffer"
// ShowCommand : INT -> "i32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void InstallHinfSectionW(
void* Window,
void* ModuleHandle,
const uint16_t* CommandLine,
int32_t ShowCommand);
C, "SETUPAPI.dll");
// $ffi->InstallHinfSectionW(Window, ModuleHandle, CommandLine, ShowCommand);
// Window : HWND
// ModuleHandle : HINSTANCE
// CommandLine : LPCWSTR
// ShowCommand : INT
// 構造体/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);
void InstallHinfSectionW(
Pointer Window, // HWND
Pointer ModuleHandle, // HINSTANCE
WString CommandLine, // LPCWSTR
int ShowCommand // INT
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("setupapi")]
lib LibSETUPAPI
fun InstallHinfSectionW = InstallHinfSectionW(
Window : Void*, # HWND
ModuleHandle : Void*, # HINSTANCE
CommandLine : UInt16*, # LPCWSTR
ShowCommand : Int32 # INT
) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef InstallHinfSectionWNative = Void Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Int32);
typedef InstallHinfSectionWDart = void Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, int);
final InstallHinfSectionW = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<InstallHinfSectionWNative, InstallHinfSectionWDart>('InstallHinfSectionW');
// Window : HWND -> Pointer<Void>
// ModuleHandle : HINSTANCE -> Pointer<Void>
// CommandLine : LPCWSTR -> Pointer<Utf16>
// ShowCommand : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
procedure InstallHinfSectionW(
Window: THandle; // HWND
ModuleHandle: THandle; // HINSTANCE
CommandLine: PWideChar; // LPCWSTR
ShowCommand: Integer // INT
); stdcall;
external 'SETUPAPI.dll' name 'InstallHinfSectionW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "InstallHinfSectionW"
c_InstallHinfSectionW :: Ptr () -> Ptr () -> CWString -> Int32 -> IO ()
-- Window : HWND -> Ptr ()
-- ModuleHandle : HINSTANCE -> Ptr ()
-- CommandLine : LPCWSTR -> CWString
-- ShowCommand : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let installhinfsectionw =
foreign "InstallHinfSectionW"
((ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> int32_t @-> returning void)
(* Window : HWND -> (ptr void) *)
(* ModuleHandle : HINSTANCE -> (ptr void) *)
(* CommandLine : LPCWSTR -> (ptr uint16_t) *)
(* ShowCommand : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)
(cffi:defcfun ("InstallHinfSectionW" install-hinf-section-w :convention :stdcall) :void
(window :pointer) ; HWND
(module-handle :pointer) ; HINSTANCE
(command-line (:string :encoding :utf-16le)) ; LPCWSTR
(show-command :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $InstallHinfSectionW = Win32::API::More->new('SETUPAPI',
'void InstallHinfSectionW(HANDLE Window, HANDLE ModuleHandle, LPCWSTR CommandLine, int ShowCommand)');
# my $ret = $InstallHinfSectionW->Call($Window, $ModuleHandle, $CommandLine, $ShowCommand);
# Window : HWND -> HANDLE
# ModuleHandle : HINSTANCE -> HANDLE
# CommandLine : LPCWSTR -> LPCWSTR
# ShowCommand : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f InstallHinfSectionA (ANSI版) — rundll32経由でINFセクションを実行するインストールエントリ。