Win32 API 日本語リファレンス
ホームSystem.ApplicationInstallationAndServicing › MsiInstallProductW

MsiInstallProductW

関数
MSIパッケージから製品をインストールする(Unicode版)。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

// msi.dll  (Unicode / -W)
#include <windows.h>

DWORD MsiInstallProductW(
    LPCWSTR szPackagePath,
    LPCWSTR szCommandLine   // optional
);

パラメーター

名前方向
szPackagePathLPCWSTRin
szCommandLineLPCWSTRinoptional

戻り値の型: DWORD

各言語での呼び出し定義

// msi.dll  (Unicode / -W)
#include <windows.h>

DWORD MsiInstallProductW(
    LPCWSTR szPackagePath,
    LPCWSTR szCommandLine   // optional
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiInstallProductW(
    [MarshalAs(UnmanagedType.LPWStr)] string szPackagePath,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string szCommandLine   // LPCWSTR optional
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiInstallProductW(
    <MarshalAs(UnmanagedType.LPWStr)> szPackagePath As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> szCommandLine As String   ' LPCWSTR optional
) As UInteger
End Function
' szPackagePath : LPCWSTR
' szCommandLine : LPCWSTR optional
Declare PtrSafe Function MsiInstallProductW Lib "msi" ( _
    ByVal szPackagePath As LongPtr, _
    ByVal szCommandLine As LongPtr) 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

MsiInstallProductW = ctypes.windll.msi.MsiInstallProductW
MsiInstallProductW.restype = wintypes.DWORD
MsiInstallProductW.argtypes = [
    wintypes.LPCWSTR,  # szPackagePath : LPCWSTR
    wintypes.LPCWSTR,  # szCommandLine : LPCWSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiInstallProductW = Fiddle::Function.new(
  lib['MsiInstallProductW'],
  [
    Fiddle::TYPE_VOIDP,  # szPackagePath : LPCWSTR
    Fiddle::TYPE_VOIDP,  # szCommandLine : LPCWSTR optional
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiInstallProductW(
        szPackagePath: *const u16,  // LPCWSTR
        szCommandLine: *const u16  // LPCWSTR optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiInstallProductW([MarshalAs(UnmanagedType.LPWStr)] string szPackagePath, [MarshalAs(UnmanagedType.LPWStr)] string szCommandLine);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiInstallProductW' -Namespace Win32 -PassThru
# $api::MsiInstallProductW(szPackagePath, szCommandLine)
#uselib "msi.dll"
#func global MsiInstallProductW "MsiInstallProductW" wptr, wptr
; MsiInstallProductW szPackagePath, szCommandLine   ; 戻り値は stat
; szPackagePath : LPCWSTR -> "wptr"
; szCommandLine : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "msi.dll"
#cfunc global MsiInstallProductW "MsiInstallProductW" wstr, wstr
; res = MsiInstallProductW(szPackagePath, szCommandLine)
; szPackagePath : LPCWSTR -> "wstr"
; szCommandLine : LPCWSTR optional -> "wstr"
; DWORD MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
#uselib "msi.dll"
#cfunc global MsiInstallProductW "MsiInstallProductW" wstr, wstr
; res = MsiInstallProductW(szPackagePath, szCommandLine)
; szPackagePath : LPCWSTR -> "wstr"
; szCommandLine : LPCWSTR optional -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiInstallProductW = msi.NewProc("MsiInstallProductW")
)

// szPackagePath (LPCWSTR), szCommandLine (LPCWSTR optional)
r1, _, err := procMsiInstallProductW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szPackagePath))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szCommandLine))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function MsiInstallProductW(
  szPackagePath: PWideChar;   // LPCWSTR
  szCommandLine: PWideChar   // LPCWSTR optional
): DWORD; stdcall;
  external 'msi.dll' name 'MsiInstallProductW';
result := DllCall("msi\MsiInstallProductW"
    , "WStr", szPackagePath   ; LPCWSTR
    , "WStr", szCommandLine   ; LPCWSTR optional
    , "UInt")   ; return: DWORD
●MsiInstallProductW(szPackagePath, szCommandLine) = DLL("msi.dll", "dword MsiInstallProductW(char*, char*)")
# 呼び出し: MsiInstallProductW(szPackagePath, szCommandLine)
# szPackagePath : LPCWSTR -> "char*"
# szCommandLine : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。