MsiSourceListForceResolutionExW
関数シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiSourceListForceResolutionExW(
LPCWSTR szProductCodeOrPatchCode,
LPCWSTR szUserSid, // optional
MSIINSTALLCONTEXT dwContext,
DWORD dwOptions
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| szProductCodeOrPatchCode | LPCWSTR | in | 製品またはパッチの ProductCode またはパッチ GUID です。null 終端文字列を使用します。文字列が 39 文字を超える場合、関数は失敗して ERROR_INVALID_PARAMETER を返します。このパラメーターを NULL にすることはできません。 | ||||||||
| szUserSid | LPCWSTR | inoptional | このパラメーターには、製品またはパッチを保持するユーザーアカウントを指定する文字列形式の SID を指定できます。SID は検証も解決もされません。誤った SID を指定すると ERROR_UNKNOWN_PRODUCT または ERROR_UNKNOWN_PATCH が返されることがあります。マシンコンテキストを参照する場合、szUserSID は NULL で、dwContext は MSIINSTALLCONTEXT_MACHINE である必要があります。マシン SID ("S-1-5-18") を使用すると ERROR_INVALID PARAMETER が返されます。現在のユーザーアカウントを参照する場合、szUserSID を NULL にでき、dwContext を MSIINSTALLCONTEXT_USERMANAGED または MSIINSTALLCONTEXT_USERUNMANAGED にできます。 | ||||||||
| dwContext | MSIINSTALLCONTEXT | in | このパラメーターは、製品またはパッチのインスタンスのコンテキストを指定します。このパラメーターには、次のいずれかの値を指定できます。
| ||||||||
| dwOptions | DWORD | in | dwOptions の値によって、szProductCodeOrPatchCode の値の解釈が決まります。
|
戻り値の型: DWORD
公式ドキュメント
MsiSourceListForceResolutionEx 関数は、"LastUsedSource" というプロパティの登録を削除します。(Unicode)
戻り値
MsiSourceListForceResolutionEx 関数は、次の値を返します。
| 値 | 意味 |
|---|---|
| ユーザーに、指定されたソースリストを変更する権限がありません。製品またはパッチが見つかったかどうかは示しません。 | |
| 構成データが破損しています。 | |
| Windows Installer サービスにアクセスできませんでした。 | |
| 無効なパラメーターが関数に渡されました。 | |
| "LastUsedSource" の登録がクリアされました。 | |
| パッチが見つかりませんでした。 | |
| 指定された製品またはパッチが見つかりませんでした。 | |
| 予期しない内部エラーが発生しました。 |
解説(Remarks)
管理者は、マシンコンテキストまたは自身のユーザーごとのコンテキスト (管理対象または非管理対象) に存在する製品またはパッチインスタンスのインストールを変更できます。また、任意のユーザーのユーザーごとの管理対象 (per-user-managed) コンテキストに存在する製品またはパッチインスタンスのインストールも変更できます。管理者は、他のユーザーのユーザーごとの非管理対象 (per-user-unmanaged) コンテキストに存在する、その他のユーザーによる製品またはパッチインスタンスのインストールは変更できません。
管理者以外のユーザーは、他のユーザーのユーザーごとのコンテキスト (管理対象または非管理対象) に存在する製品またはパッチインスタンスのインストールを変更できません。自身のユーザーごとの非管理対象 (per-user-unmanaged) コンテキストに存在する製品またはパッチインスタンスのインストールは変更できます。マシンコンテキストまたは自身のユーザーごとの管理対象 (per-user-managed) コンテキストに存在する製品またはパッチインスタンスのインストールは、製品またはパッチのソースを参照することが許可されている場合に限り変更できます。ユーザーはポリシーを設定することでソースの参照を許可できます。詳細については、DisableBrowse、AllowLockdownBrowse、および AlwaysInstallElevated の各ポリシーを参照してください。
msi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiSourceListForceResolutionEx を定義します。エンコーディング中立なエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不一致が生じる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiSourceListForceResolutionExW(
LPCWSTR szProductCodeOrPatchCode,
LPCWSTR szUserSid, // optional
MSIINSTALLCONTEXT dwContext,
DWORD dwOptions
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiSourceListForceResolutionExW(
[MarshalAs(UnmanagedType.LPWStr)] string szProductCodeOrPatchCode, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string szUserSid, // LPCWSTR optional
int dwContext, // MSIINSTALLCONTEXT
uint dwOptions // DWORD
);<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiSourceListForceResolutionExW(
<MarshalAs(UnmanagedType.LPWStr)> szProductCodeOrPatchCode As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> szUserSid As String, ' LPCWSTR optional
dwContext As Integer, ' MSIINSTALLCONTEXT
dwOptions As UInteger ' DWORD
) As UInteger
End Function' szProductCodeOrPatchCode : LPCWSTR
' szUserSid : LPCWSTR optional
' dwContext : MSIINSTALLCONTEXT
' dwOptions : DWORD
Declare PtrSafe Function MsiSourceListForceResolutionExW Lib "msi" ( _
ByVal szProductCodeOrPatchCode As LongPtr, _
ByVal szUserSid As LongPtr, _
ByVal dwContext As Long, _
ByVal dwOptions 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
MsiSourceListForceResolutionExW = ctypes.windll.msi.MsiSourceListForceResolutionExW
MsiSourceListForceResolutionExW.restype = wintypes.DWORD
MsiSourceListForceResolutionExW.argtypes = [
wintypes.LPCWSTR, # szProductCodeOrPatchCode : LPCWSTR
wintypes.LPCWSTR, # szUserSid : LPCWSTR optional
ctypes.c_int, # dwContext : MSIINSTALLCONTEXT
wintypes.DWORD, # dwOptions : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiSourceListForceResolutionExW = Fiddle::Function.new(
lib['MsiSourceListForceResolutionExW'],
[
Fiddle::TYPE_VOIDP, # szProductCodeOrPatchCode : LPCWSTR
Fiddle::TYPE_VOIDP, # szUserSid : LPCWSTR optional
Fiddle::TYPE_INT, # dwContext : MSIINSTALLCONTEXT
-Fiddle::TYPE_INT, # dwOptions : DWORD
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "msi")]
extern "system" {
fn MsiSourceListForceResolutionExW(
szProductCodeOrPatchCode: *const u16, // LPCWSTR
szUserSid: *const u16, // LPCWSTR optional
dwContext: i32, // MSIINSTALLCONTEXT
dwOptions: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiSourceListForceResolutionExW([MarshalAs(UnmanagedType.LPWStr)] string szProductCodeOrPatchCode, [MarshalAs(UnmanagedType.LPWStr)] string szUserSid, int dwContext, uint dwOptions);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiSourceListForceResolutionExW' -Namespace Win32 -PassThru
# $api::MsiSourceListForceResolutionExW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions)#uselib "msi.dll"
#func global MsiSourceListForceResolutionExW "MsiSourceListForceResolutionExW" wptr, wptr, wptr, wptr
; MsiSourceListForceResolutionExW szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions ; 戻り値は stat
; szProductCodeOrPatchCode : LPCWSTR -> "wptr"
; szUserSid : LPCWSTR optional -> "wptr"
; dwContext : MSIINSTALLCONTEXT -> "wptr"
; dwOptions : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll"
#cfunc global MsiSourceListForceResolutionExW "MsiSourceListForceResolutionExW" wstr, wstr, int, int
; res = MsiSourceListForceResolutionExW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions)
; szProductCodeOrPatchCode : LPCWSTR -> "wstr"
; szUserSid : LPCWSTR optional -> "wstr"
; dwContext : MSIINSTALLCONTEXT -> "int"
; dwOptions : DWORD -> "int"; DWORD MsiSourceListForceResolutionExW(LPCWSTR szProductCodeOrPatchCode, LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext, DWORD dwOptions)
#uselib "msi.dll"
#cfunc global MsiSourceListForceResolutionExW "MsiSourceListForceResolutionExW" wstr, wstr, int, int
; res = MsiSourceListForceResolutionExW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions)
; szProductCodeOrPatchCode : LPCWSTR -> "wstr"
; szUserSid : LPCWSTR optional -> "wstr"
; dwContext : MSIINSTALLCONTEXT -> "int"
; dwOptions : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiSourceListForceResolutionExW = msi.NewProc("MsiSourceListForceResolutionExW")
)
// szProductCodeOrPatchCode (LPCWSTR), szUserSid (LPCWSTR optional), dwContext (MSIINSTALLCONTEXT), dwOptions (DWORD)
r1, _, err := procMsiSourceListForceResolutionExW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szProductCodeOrPatchCode))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szUserSid))),
uintptr(dwContext),
uintptr(dwOptions),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiSourceListForceResolutionExW(
szProductCodeOrPatchCode: PWideChar; // LPCWSTR
szUserSid: PWideChar; // LPCWSTR optional
dwContext: Integer; // MSIINSTALLCONTEXT
dwOptions: DWORD // DWORD
): DWORD; stdcall;
external 'msi.dll' name 'MsiSourceListForceResolutionExW';result := DllCall("msi\MsiSourceListForceResolutionExW"
, "WStr", szProductCodeOrPatchCode ; LPCWSTR
, "WStr", szUserSid ; LPCWSTR optional
, "Int", dwContext ; MSIINSTALLCONTEXT
, "UInt", dwOptions ; DWORD
, "UInt") ; return: DWORD●MsiSourceListForceResolutionExW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions) = DLL("msi.dll", "dword MsiSourceListForceResolutionExW(char*, char*, int, dword)")
# 呼び出し: MsiSourceListForceResolutionExW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions)
# szProductCodeOrPatchCode : LPCWSTR -> "char*"
# szUserSid : LPCWSTR optional -> "char*"
# dwContext : MSIINSTALLCONTEXT -> "int"
# dwOptions : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "msi" fn MsiSourceListForceResolutionExW(
szProductCodeOrPatchCode: [*c]const u16, // LPCWSTR
szUserSid: [*c]const u16, // LPCWSTR optional
dwContext: i32, // MSIINSTALLCONTEXT
dwOptions: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiSourceListForceResolutionExW(
szProductCodeOrPatchCode: WideCString, # LPCWSTR
szUserSid: WideCString, # LPCWSTR optional
dwContext: int32, # MSIINSTALLCONTEXT
dwOptions: uint32 # DWORD
): uint32 {.importc: "MsiSourceListForceResolutionExW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
uint MsiSourceListForceResolutionExW(
const(wchar)* szProductCodeOrPatchCode, // LPCWSTR
const(wchar)* szUserSid, // LPCWSTR optional
int dwContext, // MSIINSTALLCONTEXT
uint dwOptions // DWORD
);ccall((:MsiSourceListForceResolutionExW, "msi.dll"), stdcall, UInt32,
(Cwstring, Cwstring, Int32, UInt32),
szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions)
# szProductCodeOrPatchCode : LPCWSTR -> Cwstring
# szUserSid : LPCWSTR optional -> Cwstring
# dwContext : MSIINSTALLCONTEXT -> Int32
# dwOptions : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiSourceListForceResolutionExW(
const uint16_t* szProductCodeOrPatchCode,
const uint16_t* szUserSid,
int32_t dwContext,
uint32_t dwOptions);
]]
local msi = ffi.load("msi")
-- msi.MsiSourceListForceResolutionExW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions)
-- szProductCodeOrPatchCode : LPCWSTR
-- szUserSid : LPCWSTR optional
-- dwContext : MSIINSTALLCONTEXT
-- dwOptions : 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('msi.dll');
const MsiSourceListForceResolutionExW = lib.func('__stdcall', 'MsiSourceListForceResolutionExW', 'uint32_t', ['str16', 'str16', 'int32_t', 'uint32_t']);
// MsiSourceListForceResolutionExW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions)
// szProductCodeOrPatchCode : LPCWSTR -> 'str16'
// szUserSid : LPCWSTR optional -> 'str16'
// dwContext : MSIINSTALLCONTEXT -> 'int32_t'
// dwOptions : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiSourceListForceResolutionExW: { parameters: ["buffer", "buffer", "i32", "u32"], result: "u32" },
});
// lib.symbols.MsiSourceListForceResolutionExW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions)
// szProductCodeOrPatchCode : LPCWSTR -> "buffer"
// szUserSid : LPCWSTR optional -> "buffer"
// dwContext : MSIINSTALLCONTEXT -> "i32"
// dwOptions : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiSourceListForceResolutionExW(
const uint16_t* szProductCodeOrPatchCode,
const uint16_t* szUserSid,
int32_t dwContext,
uint32_t dwOptions);
C, "msi.dll");
// $ffi->MsiSourceListForceResolutionExW(szProductCodeOrPatchCode, szUserSid, dwContext, dwOptions);
// szProductCodeOrPatchCode : LPCWSTR
// szUserSid : LPCWSTR optional
// dwContext : MSIINSTALLCONTEXT
// dwOptions : 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 Msi extends StdCallLibrary {
Msi INSTANCE = Native.load("msi", Msi.class, W32APIOptions.UNICODE_OPTIONS);
int MsiSourceListForceResolutionExW(
WString szProductCodeOrPatchCode, // LPCWSTR
WString szUserSid, // LPCWSTR optional
int dwContext, // MSIINSTALLCONTEXT
int dwOptions // DWORD
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiSourceListForceResolutionExW = MsiSourceListForceResolutionExW(
szProductCodeOrPatchCode : UInt16*, # LPCWSTR
szUserSid : UInt16*, # LPCWSTR optional
dwContext : Int32, # MSIINSTALLCONTEXT
dwOptions : UInt32 # DWORD
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiSourceListForceResolutionExWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Int32, Uint32);
typedef MsiSourceListForceResolutionExWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, int);
final MsiSourceListForceResolutionExW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiSourceListForceResolutionExWNative, MsiSourceListForceResolutionExWDart>('MsiSourceListForceResolutionExW');
// szProductCodeOrPatchCode : LPCWSTR -> Pointer<Utf16>
// szUserSid : LPCWSTR optional -> Pointer<Utf16>
// dwContext : MSIINSTALLCONTEXT -> Int32
// dwOptions : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiSourceListForceResolutionExW(
szProductCodeOrPatchCode: PWideChar; // LPCWSTR
szUserSid: PWideChar; // LPCWSTR optional
dwContext: Integer; // MSIINSTALLCONTEXT
dwOptions: DWORD // DWORD
): DWORD; stdcall;
external 'msi.dll' name 'MsiSourceListForceResolutionExW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiSourceListForceResolutionExW"
c_MsiSourceListForceResolutionExW :: CWString -> CWString -> Int32 -> Word32 -> IO Word32
-- szProductCodeOrPatchCode : LPCWSTR -> CWString
-- szUserSid : LPCWSTR optional -> CWString
-- dwContext : MSIINSTALLCONTEXT -> Int32
-- dwOptions : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msisourcelistforceresolutionexw =
foreign "MsiSourceListForceResolutionExW"
((ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> uint32_t @-> returning uint32_t)
(* szProductCodeOrPatchCode : LPCWSTR -> (ptr uint16_t) *)
(* szUserSid : LPCWSTR optional -> (ptr uint16_t) *)
(* dwContext : MSIINSTALLCONTEXT -> int32_t *)
(* dwOptions : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)
(cffi:defcfun ("MsiSourceListForceResolutionExW" msi-source-list-force-resolution-ex-w :convention :stdcall) :uint32
(sz-product-code-or-patch-code (:string :encoding :utf-16le)) ; LPCWSTR
(sz-user-sid (:string :encoding :utf-16le)) ; LPCWSTR optional
(dw-context :int32) ; MSIINSTALLCONTEXT
(dw-options :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiSourceListForceResolutionExW = Win32::API::More->new('msi',
'DWORD MsiSourceListForceResolutionExW(LPCWSTR szProductCodeOrPatchCode, LPCWSTR szUserSid, int dwContext, DWORD dwOptions)');
# my $ret = $MsiSourceListForceResolutionExW->Call($szProductCodeOrPatchCode, $szUserSid, $dwContext, $dwOptions);
# szProductCodeOrPatchCode : LPCWSTR -> LPCWSTR
# szUserSid : LPCWSTR optional -> LPCWSTR
# dwContext : MSIINSTALLCONTEXT -> int
# dwOptions : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f MsiSourceListForceResolutionExA (ANSI版) — コンテキストを指定してソースリストの再解決を強制する。
- f MsiSourceListForceResolutionW — 次回ソース使用時にソースを再解決するよう強制する。