ホーム › System.ApplicationInstallationAndServicing › MsiInstallProductA
MsiInstallProductA
関数MSIパッケージから製品をインストールする(ANSI版)。
シグネチャ
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiInstallProductA(
LPCSTR szPackagePath,
LPCSTR szCommandLine // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| szPackagePath | LPCSTR | in | Windows Installer パッケージの場所へのパスを指定する null 終端文字列です。この文字列値には、URL(例: http://packageLocation/package/package.msi)、ネットワークパス(例: \packageLocation\package.msi)、ファイルパス(例: file://packageLocation/package.msi)、またはローカルパス(例: D:\packageLocation\package.msi)を指定できます。 |
| szCommandLine | LPCSTR | inoptional | コマンドラインのプロパティ設定を指定する null 終端文字列です。Property=Setting Property=Setting の形式のリストである必要があります。詳細については、 About Properties を参照してください。 管理インストールを実行するには、szCommandLine に ACTION=ADMIN を含めます。詳細については、 ACTION プロパティを参照してください。 |
戻り値の型: DWORD
公式ドキュメント
製品をインストールまたはアンインストールします。(MsiInstallProductA)
戻り値
| 値 | 意味 |
|---|---|
| 関数が正常に完了しました。 | |
|
詳細については、 Error Codes を参照してください。 |
| 初期化に関連するエラーが発生しました。 |
詳細については、 Displayed Error Messages を参照してください。
解説(Remarks)
MsiInstallProduct 関数は、現在の設定とログモードでユーザーインターフェイスを表示します。
- ユーザーインターフェイスの設定は、 MsiSetInternalUI、 MsiSetExternalUI、または MsiSetExternalUIRecord 関数を使用して変更できます。
- ログモードは、 MsiEnableLog 関数を使用して設定できます。
- szCommandLine に REMOVE=ALL を設定することで、製品を完全に削除できます。
メモ
msi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiInstallProduct を定義します。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在させて使用すると、不一致が生じ、コンパイルエラーまたは実行時エラーを引き起こす可能性があります。詳細については、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)
各言語での呼び出し定義
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiInstallProductA(
LPCSTR szPackagePath,
LPCSTR szCommandLine // optional
);[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiInstallProductA(
[MarshalAs(UnmanagedType.LPStr)] string szPackagePath, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string szCommandLine // LPCSTR optional
);<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiInstallProductA(
<MarshalAs(UnmanagedType.LPStr)> szPackagePath As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> szCommandLine As String ' LPCSTR optional
) As UInteger
End Function' szPackagePath : LPCSTR
' szCommandLine : LPCSTR optional
Declare PtrSafe Function MsiInstallProductA Lib "msi" ( _
ByVal szPackagePath As String, _
ByVal szCommandLine As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MsiInstallProductA = ctypes.windll.msi.MsiInstallProductA
MsiInstallProductA.restype = wintypes.DWORD
MsiInstallProductA.argtypes = [
wintypes.LPCSTR, # szPackagePath : LPCSTR
wintypes.LPCSTR, # szCommandLine : LPCSTR optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiInstallProductA = Fiddle::Function.new(
lib['MsiInstallProductA'],
[
Fiddle::TYPE_VOIDP, # szPackagePath : LPCSTR
Fiddle::TYPE_VOIDP, # szCommandLine : LPCSTR optional
],
-Fiddle::TYPE_INT)#[link(name = "msi")]
extern "system" {
fn MsiInstallProductA(
szPackagePath: *const u8, // LPCSTR
szCommandLine: *const u8 // LPCSTR optional
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Ansi)]
public static extern uint MsiInstallProductA([MarshalAs(UnmanagedType.LPStr)] string szPackagePath, [MarshalAs(UnmanagedType.LPStr)] string szCommandLine);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiInstallProductA' -Namespace Win32 -PassThru
# $api::MsiInstallProductA(szPackagePath, szCommandLine)#uselib "msi.dll"
#func global MsiInstallProductA "MsiInstallProductA" sptr, sptr
; MsiInstallProductA szPackagePath, szCommandLine ; 戻り値は stat
; szPackagePath : LPCSTR -> "sptr"
; szCommandLine : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll"
#cfunc global MsiInstallProductA "MsiInstallProductA" str, str
; res = MsiInstallProductA(szPackagePath, szCommandLine)
; szPackagePath : LPCSTR -> "str"
; szCommandLine : LPCSTR optional -> "str"; DWORD MsiInstallProductA(LPCSTR szPackagePath, LPCSTR szCommandLine)
#uselib "msi.dll"
#cfunc global MsiInstallProductA "MsiInstallProductA" str, str
; res = MsiInstallProductA(szPackagePath, szCommandLine)
; szPackagePath : LPCSTR -> "str"
; szCommandLine : LPCSTR optional -> "str"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiInstallProductA = msi.NewProc("MsiInstallProductA")
)
// szPackagePath (LPCSTR), szCommandLine (LPCSTR optional)
r1, _, err := procMsiInstallProductA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(szPackagePath))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szCommandLine))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiInstallProductA(
szPackagePath: PAnsiChar; // LPCSTR
szCommandLine: PAnsiChar // LPCSTR optional
): DWORD; stdcall;
external 'msi.dll' name 'MsiInstallProductA';result := DllCall("msi\MsiInstallProductA"
, "AStr", szPackagePath ; LPCSTR
, "AStr", szCommandLine ; LPCSTR optional
, "UInt") ; return: DWORD●MsiInstallProductA(szPackagePath, szCommandLine) = DLL("msi.dll", "dword MsiInstallProductA(char*, char*)")
# 呼び出し: MsiInstallProductA(szPackagePath, szCommandLine)
# szPackagePath : LPCSTR -> "char*"
# szCommandLine : LPCSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "msi" fn MsiInstallProductA(
szPackagePath: [*c]const u8, // LPCSTR
szCommandLine: [*c]const u8 // LPCSTR optional
) callconv(std.os.windows.WINAPI) u32;proc MsiInstallProductA(
szPackagePath: cstring, # LPCSTR
szCommandLine: cstring # LPCSTR optional
): uint32 {.importc: "MsiInstallProductA", stdcall, dynlib: "msi.dll".}pragma(lib, "msi");
extern(Windows)
uint MsiInstallProductA(
const(char)* szPackagePath, // LPCSTR
const(char)* szCommandLine // LPCSTR optional
);ccall((:MsiInstallProductA, "msi.dll"), stdcall, UInt32,
(Cstring, Cstring),
szPackagePath, szCommandLine)
# szPackagePath : LPCSTR -> Cstring
# szCommandLine : LPCSTR optional -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiInstallProductA(
const char* szPackagePath,
const char* szCommandLine);
]]
local msi = ffi.load("msi")
-- msi.MsiInstallProductA(szPackagePath, szCommandLine)
-- szPackagePath : LPCSTR
-- szCommandLine : LPCSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiInstallProductA = lib.func('__stdcall', 'MsiInstallProductA', 'uint32_t', ['str', 'str']);
// MsiInstallProductA(szPackagePath, szCommandLine)
// szPackagePath : LPCSTR -> 'str'
// szCommandLine : LPCSTR optional -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiInstallProductA: { parameters: ["buffer", "buffer"], result: "u32" },
});
// lib.symbols.MsiInstallProductA(szPackagePath, szCommandLine)
// szPackagePath : LPCSTR -> "buffer"
// szCommandLine : LPCSTR optional -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiInstallProductA(
const char* szPackagePath,
const char* szCommandLine);
C, "msi.dll");
// $ffi->MsiInstallProductA(szPackagePath, szCommandLine);
// szPackagePath : LPCSTR
// szCommandLine : LPCSTR optional
// 構造体/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 Msi extends StdCallLibrary {
Msi INSTANCE = Native.load("msi", Msi.class, W32APIOptions.ASCII_OPTIONS);
int MsiInstallProductA(
String szPackagePath, // LPCSTR
String szCommandLine // LPCSTR optional
);
}@[Link("msi")]
lib Libmsi
fun MsiInstallProductA = MsiInstallProductA(
szPackagePath : UInt8*, # LPCSTR
szCommandLine : UInt8* # LPCSTR optional
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiInstallProductANative = Uint32 Function(Pointer<Utf8>, Pointer<Utf8>);
typedef MsiInstallProductADart = int Function(Pointer<Utf8>, Pointer<Utf8>);
final MsiInstallProductA = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiInstallProductANative, MsiInstallProductADart>('MsiInstallProductA');
// szPackagePath : LPCSTR -> Pointer<Utf8>
// szCommandLine : LPCSTR optional -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiInstallProductA(
szPackagePath: PAnsiChar; // LPCSTR
szCommandLine: PAnsiChar // LPCSTR optional
): DWORD; stdcall;
external 'msi.dll' name 'MsiInstallProductA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiInstallProductA"
c_MsiInstallProductA :: CString -> CString -> IO Word32
-- szPackagePath : LPCSTR -> CString
-- szCommandLine : LPCSTR optional -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msiinstallproducta =
foreign "MsiInstallProductA"
(string @-> string @-> returning uint32_t)
(* szPackagePath : LPCSTR -> string *)
(* szCommandLine : LPCSTR optional -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)
(cffi:defcfun ("MsiInstallProductA" msi-install-product-a :convention :stdcall) :uint32
(sz-package-path :string) ; LPCSTR
(sz-command-line :string)) ; LPCSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiInstallProductA = Win32::API::More->new('msi',
'DWORD MsiInstallProductA(LPCSTR szPackagePath, LPCSTR szCommandLine)');
# my $ret = $MsiInstallProductA->Call($szPackagePath, $szCommandLine);
# szPackagePath : LPCSTR -> LPCSTR
# szCommandLine : LPCSTR optional -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f MsiInstallProductW (Unicode版) — MSIパッケージから製品をインストールする(Unicode版)。