MsiSourceListAddSourceA
関数シグネチャ
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiSourceListAddSourceA(
LPCSTR szProduct,
LPCSTR szUserName, // optional
DWORD dwReserved, // optional
LPCSTR szSource
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| szProduct | LPCSTR | in | 変更対象となる製品の ProductCode です。 |
| szUserName | LPCSTR | inoptional | ユーザー単位インストールの場合のユーザー名です。Windows 2000 または Windows XP では、ユーザー名は常に DOMAIN\USERNAME 形式(ローカルユーザーの場合は MACHINENAME\USERNAME)で指定する必要があります。 マシン単位インストールの場合は、空文字列または NULL を指定します。 |
| dwReserved | DWORD | optional | 将来使用するために予約されています。この値は 0 に設定する必要があります。 |
| szSource | LPCSTR | in | ソースを指定する文字列へのポインターです。 |
戻り値の型: DWORD
公式ドキュメント
指定したユーザーコンテキストにおいて、製品またはパッチに対する指定された種類のソースを含む有効なネットワークソースの一覧に追加します。(ANSI)
戻り値
| 戻り値コード | 説明 |
|---|---|
| ユーザーにソースを追加する権限がありません。 | |
| 構成データが破損しています。 | |
| ユーザー名を解決できませんでした。 | |
| 関数が成功しませんでした。 | |
| インストーラーサービスにアクセスできませんでした。 | |
| 無効なパラメーターが関数に渡されました。 | |
| ソースが追加されました。 | |
| 指定された製品は不明です。 |
解説(Remarks)
管理者は、マシン単位インストール、自身のユーザー単位の非管理対象インストール、および任意のユーザーのユーザー単位の管理対象インストールを変更できます。管理者以外のユーザーは、マシン単位インストールと自身の(管理対象または非管理対象の)ユーザー単位インストールのみを変更できます。ポリシーを設定することで、ユーザーがソースを参照できるようにすることができます。詳細については、DisableBrowse、AllowLockdownBrowse、および AlwaysInstallElevated の各ポリシーを参照してください。
この関数は、新しいソースを有効なソースの一覧に追加するだけである点に注意してください。製品のインストールに別のソースが使用されていた場合、現在のソースが利用できなくなるまで、新しいソースは使用されません。
指定したソースが製品に対する有効なソースイメージであることを保証するのは、呼び出し元の責任です。
ユーザー名が空文字列または NULL の場合、関数は製品のマシン単位インストールに対して動作します。この場合、製品がユーザー単位の状態でのみインストールされていると、関数は ERROR_UNKNOWN_PRODUCT を返します。
ユーザー名が空文字列または NULL でない場合、製品インストールを変更する対象ユーザーの名前を指定します。ユーザー名が現在のユーザー名である場合、関数はまず製品の非管理対象インストールの変更を試みます。製品の非管理対象インストールが見つからない場合、関数は次に製品の管理対象ユーザー単位インストールの変更を試みます。製品の管理対象または非管理対象のユーザー単位インストールがいずれも見つからない場合、たとえ製品がマシン単位でインストールされていても、関数は ERROR_UNKNOWN_PRODUCT を返します。
この関数は、現在のユーザー以外のユーザーに対する非管理対象インストールを変更することはできません。ユーザー名が空文字列または NULL ではなく、かつ現在のユーザーでない場合、関数は指定されたユーザーに対する製品の管理対象ユーザー単位インストールのみを確認します。指定されたユーザーに対して製品が管理対象ユーザー単位としてインストールされていない場合、たとえ製品がマシン単位でインストールされていても、関数は ERROR_UNKNOWN_PRODUCT を返します。
msi.h ヘッダーは MsiSourceListAddSource をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択します。エンコーディング非依存のエイリアスと、エンコーディング非依存ではないコードを混在して使用すると、不一致が生じてコンパイルエラーや実行時エラーの原因となる場合があります。詳細については、関数プロトタイプの規約を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiSourceListAddSourceA(
LPCSTR szProduct,
LPCSTR szUserName, // optional
DWORD dwReserved, // optional
LPCSTR szSource
);[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiSourceListAddSourceA(
[MarshalAs(UnmanagedType.LPStr)] string szProduct, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string szUserName, // LPCSTR optional
uint dwReserved, // DWORD optional
[MarshalAs(UnmanagedType.LPStr)] string szSource // LPCSTR
);<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiSourceListAddSourceA(
<MarshalAs(UnmanagedType.LPStr)> szProduct As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> szUserName As String, ' LPCSTR optional
dwReserved As UInteger, ' DWORD optional
<MarshalAs(UnmanagedType.LPStr)> szSource As String ' LPCSTR
) As UInteger
End Function' szProduct : LPCSTR
' szUserName : LPCSTR optional
' dwReserved : DWORD optional
' szSource : LPCSTR
Declare PtrSafe Function MsiSourceListAddSourceA Lib "msi" ( _
ByVal szProduct As String, _
ByVal szUserName As String, _
ByVal dwReserved As Long, _
ByVal szSource As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MsiSourceListAddSourceA = ctypes.windll.msi.MsiSourceListAddSourceA
MsiSourceListAddSourceA.restype = wintypes.DWORD
MsiSourceListAddSourceA.argtypes = [
wintypes.LPCSTR, # szProduct : LPCSTR
wintypes.LPCSTR, # szUserName : LPCSTR optional
wintypes.DWORD, # dwReserved : DWORD optional
wintypes.LPCSTR, # szSource : LPCSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiSourceListAddSourceA = Fiddle::Function.new(
lib['MsiSourceListAddSourceA'],
[
Fiddle::TYPE_VOIDP, # szProduct : LPCSTR
Fiddle::TYPE_VOIDP, # szUserName : LPCSTR optional
-Fiddle::TYPE_INT, # dwReserved : DWORD optional
Fiddle::TYPE_VOIDP, # szSource : LPCSTR
],
-Fiddle::TYPE_INT)#[link(name = "msi")]
extern "system" {
fn MsiSourceListAddSourceA(
szProduct: *const u8, // LPCSTR
szUserName: *const u8, // LPCSTR optional
dwReserved: u32, // DWORD optional
szSource: *const u8 // LPCSTR
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Ansi)]
public static extern uint MsiSourceListAddSourceA([MarshalAs(UnmanagedType.LPStr)] string szProduct, [MarshalAs(UnmanagedType.LPStr)] string szUserName, uint dwReserved, [MarshalAs(UnmanagedType.LPStr)] string szSource);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiSourceListAddSourceA' -Namespace Win32 -PassThru
# $api::MsiSourceListAddSourceA(szProduct, szUserName, dwReserved, szSource)#uselib "msi.dll"
#func global MsiSourceListAddSourceA "MsiSourceListAddSourceA" sptr, sptr, sptr, sptr
; MsiSourceListAddSourceA szProduct, szUserName, dwReserved, szSource ; 戻り値は stat
; szProduct : LPCSTR -> "sptr"
; szUserName : LPCSTR optional -> "sptr"
; dwReserved : DWORD optional -> "sptr"
; szSource : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll"
#cfunc global MsiSourceListAddSourceA "MsiSourceListAddSourceA" str, str, int, str
; res = MsiSourceListAddSourceA(szProduct, szUserName, dwReserved, szSource)
; szProduct : LPCSTR -> "str"
; szUserName : LPCSTR optional -> "str"
; dwReserved : DWORD optional -> "int"
; szSource : LPCSTR -> "str"; DWORD MsiSourceListAddSourceA(LPCSTR szProduct, LPCSTR szUserName, DWORD dwReserved, LPCSTR szSource)
#uselib "msi.dll"
#cfunc global MsiSourceListAddSourceA "MsiSourceListAddSourceA" str, str, int, str
; res = MsiSourceListAddSourceA(szProduct, szUserName, dwReserved, szSource)
; szProduct : LPCSTR -> "str"
; szUserName : LPCSTR optional -> "str"
; dwReserved : DWORD optional -> "int"
; szSource : LPCSTR -> "str"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiSourceListAddSourceA = msi.NewProc("MsiSourceListAddSourceA")
)
// szProduct (LPCSTR), szUserName (LPCSTR optional), dwReserved (DWORD optional), szSource (LPCSTR)
r1, _, err := procMsiSourceListAddSourceA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(szProduct))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szUserName))),
uintptr(dwReserved),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szSource))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiSourceListAddSourceA(
szProduct: PAnsiChar; // LPCSTR
szUserName: PAnsiChar; // LPCSTR optional
dwReserved: DWORD; // DWORD optional
szSource: PAnsiChar // LPCSTR
): DWORD; stdcall;
external 'msi.dll' name 'MsiSourceListAddSourceA';result := DllCall("msi\MsiSourceListAddSourceA"
, "AStr", szProduct ; LPCSTR
, "AStr", szUserName ; LPCSTR optional
, "UInt", dwReserved ; DWORD optional
, "AStr", szSource ; LPCSTR
, "UInt") ; return: DWORD●MsiSourceListAddSourceA(szProduct, szUserName, dwReserved, szSource) = DLL("msi.dll", "dword MsiSourceListAddSourceA(char*, char*, dword, char*)")
# 呼び出し: MsiSourceListAddSourceA(szProduct, szUserName, dwReserved, szSource)
# szProduct : LPCSTR -> "char*"
# szUserName : LPCSTR optional -> "char*"
# dwReserved : DWORD optional -> "dword"
# szSource : LPCSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "msi" fn MsiSourceListAddSourceA(
szProduct: [*c]const u8, // LPCSTR
szUserName: [*c]const u8, // LPCSTR optional
dwReserved: u32, // DWORD optional
szSource: [*c]const u8 // LPCSTR
) callconv(std.os.windows.WINAPI) u32;proc MsiSourceListAddSourceA(
szProduct: cstring, # LPCSTR
szUserName: cstring, # LPCSTR optional
dwReserved: uint32, # DWORD optional
szSource: cstring # LPCSTR
): uint32 {.importc: "MsiSourceListAddSourceA", stdcall, dynlib: "msi.dll".}pragma(lib, "msi");
extern(Windows)
uint MsiSourceListAddSourceA(
const(char)* szProduct, // LPCSTR
const(char)* szUserName, // LPCSTR optional
uint dwReserved, // DWORD optional
const(char)* szSource // LPCSTR
);ccall((:MsiSourceListAddSourceA, "msi.dll"), stdcall, UInt32,
(Cstring, Cstring, UInt32, Cstring),
szProduct, szUserName, dwReserved, szSource)
# szProduct : LPCSTR -> Cstring
# szUserName : LPCSTR optional -> Cstring
# dwReserved : DWORD optional -> UInt32
# szSource : LPCSTR -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiSourceListAddSourceA(
const char* szProduct,
const char* szUserName,
uint32_t dwReserved,
const char* szSource);
]]
local msi = ffi.load("msi")
-- msi.MsiSourceListAddSourceA(szProduct, szUserName, dwReserved, szSource)
-- szProduct : LPCSTR
-- szUserName : LPCSTR optional
-- dwReserved : DWORD optional
-- szSource : LPCSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiSourceListAddSourceA = lib.func('__stdcall', 'MsiSourceListAddSourceA', 'uint32_t', ['str', 'str', 'uint32_t', 'str']);
// MsiSourceListAddSourceA(szProduct, szUserName, dwReserved, szSource)
// szProduct : LPCSTR -> 'str'
// szUserName : LPCSTR optional -> 'str'
// dwReserved : DWORD optional -> 'uint32_t'
// szSource : LPCSTR -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiSourceListAddSourceA: { parameters: ["buffer", "buffer", "u32", "buffer"], result: "u32" },
});
// lib.symbols.MsiSourceListAddSourceA(szProduct, szUserName, dwReserved, szSource)
// szProduct : LPCSTR -> "buffer"
// szUserName : LPCSTR optional -> "buffer"
// dwReserved : DWORD optional -> "u32"
// szSource : LPCSTR -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiSourceListAddSourceA(
const char* szProduct,
const char* szUserName,
uint32_t dwReserved,
const char* szSource);
C, "msi.dll");
// $ffi->MsiSourceListAddSourceA(szProduct, szUserName, dwReserved, szSource);
// szProduct : LPCSTR
// szUserName : LPCSTR optional
// dwReserved : DWORD optional
// szSource : LPCSTR
// 構造体/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 MsiSourceListAddSourceA(
String szProduct, // LPCSTR
String szUserName, // LPCSTR optional
int dwReserved, // DWORD optional
String szSource // LPCSTR
);
}@[Link("msi")]
lib Libmsi
fun MsiSourceListAddSourceA = MsiSourceListAddSourceA(
szProduct : UInt8*, # LPCSTR
szUserName : UInt8*, # LPCSTR optional
dwReserved : UInt32, # DWORD optional
szSource : UInt8* # LPCSTR
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiSourceListAddSourceANative = Uint32 Function(Pointer<Utf8>, Pointer<Utf8>, Uint32, Pointer<Utf8>);
typedef MsiSourceListAddSourceADart = int Function(Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Utf8>);
final MsiSourceListAddSourceA = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiSourceListAddSourceANative, MsiSourceListAddSourceADart>('MsiSourceListAddSourceA');
// szProduct : LPCSTR -> Pointer<Utf8>
// szUserName : LPCSTR optional -> Pointer<Utf8>
// dwReserved : DWORD optional -> Uint32
// szSource : LPCSTR -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiSourceListAddSourceA(
szProduct: PAnsiChar; // LPCSTR
szUserName: PAnsiChar; // LPCSTR optional
dwReserved: DWORD; // DWORD optional
szSource: PAnsiChar // LPCSTR
): DWORD; stdcall;
external 'msi.dll' name 'MsiSourceListAddSourceA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiSourceListAddSourceA"
c_MsiSourceListAddSourceA :: CString -> CString -> Word32 -> CString -> IO Word32
-- szProduct : LPCSTR -> CString
-- szUserName : LPCSTR optional -> CString
-- dwReserved : DWORD optional -> Word32
-- szSource : LPCSTR -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msisourcelistaddsourcea =
foreign "MsiSourceListAddSourceA"
(string @-> string @-> uint32_t @-> string @-> returning uint32_t)
(* szProduct : LPCSTR -> string *)
(* szUserName : LPCSTR optional -> string *)
(* dwReserved : DWORD optional -> uint32_t *)
(* szSource : LPCSTR -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)
(cffi:defcfun ("MsiSourceListAddSourceA" msi-source-list-add-source-a :convention :stdcall) :uint32
(sz-product :string) ; LPCSTR
(sz-user-name :string) ; LPCSTR optional
(dw-reserved :uint32) ; DWORD optional
(sz-source :string)) ; LPCSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiSourceListAddSourceA = Win32::API::More->new('msi',
'DWORD MsiSourceListAddSourceA(LPCSTR szProduct, LPCSTR szUserName, DWORD dwReserved, LPCSTR szSource)');
# my $ret = $MsiSourceListAddSourceA->Call($szProduct, $szUserName, $dwReserved, $szSource);
# szProduct : LPCSTR -> LPCSTR
# szUserName : LPCSTR optional -> LPCSTR
# dwReserved : DWORD optional -> DWORD
# szSource : LPCSTR -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f MsiSourceListAddSourceW (Unicode版) — 製品のソースリストにネットワークソースを追加する。
- f MsiSourceListAddSourceExA — コンテキストや種別を指定して製品やパッチのソースを追加する。
- f LookupAccountNameA — アカウント名からSIDとドメイン名を取得する(ANSI版)。