Win32 API 日本語リファレンス
ホームSecurity.Credentials › CredUICmdLinePromptForCredentialsW

CredUICmdLinePromptForCredentialsW

関数
コマンドラインで資格情報の入力を求める。
DLLcredui.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

DWORD CredUICmdLinePromptForCredentialsW(
    LPCWSTR pszTargetName,   // optional
    SecHandle* pContext,   // optional
    DWORD dwAuthError,
    LPWSTR UserName,
    DWORD ulUserBufferSize,
    LPWSTR pszPassword,
    DWORD ulPasswordBufferSize,
    BOOL* pfSave,   // optional
    CREDUI_FLAGS dwFlags
);

パラメーター

名前方向
pszTargetNameLPCWSTRinoptional
pContextSecHandle*optional
dwAuthErrorDWORDin
UserNameLPWSTRinout
ulUserBufferSizeDWORDin
pszPasswordLPWSTRinout
ulPasswordBufferSizeDWORDin
pfSaveBOOL*inoutoptional
dwFlagsCREDUI_FLAGSin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD CredUICmdLinePromptForCredentialsW(
    LPCWSTR pszTargetName,   // optional
    SecHandle* pContext,   // optional
    DWORD dwAuthError,
    LPWSTR UserName,
    DWORD ulUserBufferSize,
    LPWSTR pszPassword,
    DWORD ulPasswordBufferSize,
    BOOL* pfSave,   // optional
    CREDUI_FLAGS dwFlags
);
[DllImport("credui.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint CredUICmdLinePromptForCredentialsW(
    [MarshalAs(UnmanagedType.LPWStr)] string pszTargetName,   // LPCWSTR optional
    IntPtr pContext,   // SecHandle* optional
    uint dwAuthError,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder UserName,   // LPWSTR in/out
    uint ulUserBufferSize,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPassword,   // LPWSTR in/out
    uint ulPasswordBufferSize,   // DWORD
    IntPtr pfSave,   // BOOL* optional, in/out
    uint dwFlags   // CREDUI_FLAGS
);
<DllImport("credui.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function CredUICmdLinePromptForCredentialsW(
    <MarshalAs(UnmanagedType.LPWStr)> pszTargetName As String,   ' LPCWSTR optional
    pContext As IntPtr,   ' SecHandle* optional
    dwAuthError As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> UserName As System.Text.StringBuilder,   ' LPWSTR in/out
    ulUserBufferSize As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> pszPassword As System.Text.StringBuilder,   ' LPWSTR in/out
    ulPasswordBufferSize As UInteger,   ' DWORD
    pfSave As IntPtr,   ' BOOL* optional, in/out
    dwFlags As UInteger   ' CREDUI_FLAGS
) As UInteger
End Function
' pszTargetName : LPCWSTR optional
' pContext : SecHandle* optional
' dwAuthError : DWORD
' UserName : LPWSTR in/out
' ulUserBufferSize : DWORD
' pszPassword : LPWSTR in/out
' ulPasswordBufferSize : DWORD
' pfSave : BOOL* optional, in/out
' dwFlags : CREDUI_FLAGS
Declare PtrSafe Function CredUICmdLinePromptForCredentialsW Lib "credui" ( _
    ByVal pszTargetName As LongPtr, _
    ByVal pContext As LongPtr, _
    ByVal dwAuthError As Long, _
    ByVal UserName As LongPtr, _
    ByVal ulUserBufferSize As Long, _
    ByVal pszPassword As LongPtr, _
    ByVal ulPasswordBufferSize As Long, _
    ByVal pfSave As LongPtr, _
    ByVal dwFlags 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

CredUICmdLinePromptForCredentialsW = ctypes.windll.credui.CredUICmdLinePromptForCredentialsW
CredUICmdLinePromptForCredentialsW.restype = wintypes.DWORD
CredUICmdLinePromptForCredentialsW.argtypes = [
    wintypes.LPCWSTR,  # pszTargetName : LPCWSTR optional
    ctypes.c_void_p,  # pContext : SecHandle* optional
    wintypes.DWORD,  # dwAuthError : DWORD
    wintypes.LPWSTR,  # UserName : LPWSTR in/out
    wintypes.DWORD,  # ulUserBufferSize : DWORD
    wintypes.LPWSTR,  # pszPassword : LPWSTR in/out
    wintypes.DWORD,  # ulPasswordBufferSize : DWORD
    ctypes.c_void_p,  # pfSave : BOOL* optional, in/out
    wintypes.DWORD,  # dwFlags : CREDUI_FLAGS
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('credui.dll')
CredUICmdLinePromptForCredentialsW = Fiddle::Function.new(
  lib['CredUICmdLinePromptForCredentialsW'],
  [
    Fiddle::TYPE_VOIDP,  # pszTargetName : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # pContext : SecHandle* optional
    -Fiddle::TYPE_INT,  # dwAuthError : DWORD
    Fiddle::TYPE_VOIDP,  # UserName : LPWSTR in/out
    -Fiddle::TYPE_INT,  # ulUserBufferSize : DWORD
    Fiddle::TYPE_VOIDP,  # pszPassword : LPWSTR in/out
    -Fiddle::TYPE_INT,  # ulPasswordBufferSize : DWORD
    Fiddle::TYPE_VOIDP,  # pfSave : BOOL* optional, in/out
    -Fiddle::TYPE_INT,  # dwFlags : CREDUI_FLAGS
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "credui")]
extern "system" {
    fn CredUICmdLinePromptForCredentialsW(
        pszTargetName: *const u16,  // LPCWSTR optional
        pContext: *mut SecHandle,  // SecHandle* optional
        dwAuthError: u32,  // DWORD
        UserName: *mut u16,  // LPWSTR in/out
        ulUserBufferSize: u32,  // DWORD
        pszPassword: *mut u16,  // LPWSTR in/out
        ulPasswordBufferSize: u32,  // DWORD
        pfSave: *mut i32,  // BOOL* optional, in/out
        dwFlags: u32  // CREDUI_FLAGS
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("credui.dll", CharSet = CharSet.Unicode)]
public static extern uint CredUICmdLinePromptForCredentialsW([MarshalAs(UnmanagedType.LPWStr)] string pszTargetName, IntPtr pContext, uint dwAuthError, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder UserName, uint ulUserBufferSize, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPassword, uint ulPasswordBufferSize, IntPtr pfSave, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'credui_CredUICmdLinePromptForCredentialsW' -Namespace Win32 -PassThru
# $api::CredUICmdLinePromptForCredentialsW(pszTargetName, pContext, dwAuthError, UserName, ulUserBufferSize, pszPassword, ulPasswordBufferSize, pfSave, dwFlags)
#uselib "credui.dll"
#func global CredUICmdLinePromptForCredentialsW "CredUICmdLinePromptForCredentialsW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; CredUICmdLinePromptForCredentialsW pszTargetName, varptr(pContext), dwAuthError, varptr(UserName), ulUserBufferSize, varptr(pszPassword), ulPasswordBufferSize, pfSave, dwFlags   ; 戻り値は stat
; pszTargetName : LPCWSTR optional -> "wptr"
; pContext : SecHandle* optional -> "wptr"
; dwAuthError : DWORD -> "wptr"
; UserName : LPWSTR in/out -> "wptr"
; ulUserBufferSize : DWORD -> "wptr"
; pszPassword : LPWSTR in/out -> "wptr"
; ulPasswordBufferSize : DWORD -> "wptr"
; pfSave : BOOL* optional, in/out -> "wptr"
; dwFlags : CREDUI_FLAGS -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "credui.dll"
#cfunc global CredUICmdLinePromptForCredentialsW "CredUICmdLinePromptForCredentialsW" wstr, var, int, var, int, var, int, int, int
; res = CredUICmdLinePromptForCredentialsW(pszTargetName, pContext, dwAuthError, UserName, ulUserBufferSize, pszPassword, ulPasswordBufferSize, pfSave, dwFlags)
; pszTargetName : LPCWSTR optional -> "wstr"
; pContext : SecHandle* optional -> "var"
; dwAuthError : DWORD -> "int"
; UserName : LPWSTR in/out -> "var"
; ulUserBufferSize : DWORD -> "int"
; pszPassword : LPWSTR in/out -> "var"
; ulPasswordBufferSize : DWORD -> "int"
; pfSave : BOOL* optional, in/out -> "int"
; dwFlags : CREDUI_FLAGS -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD CredUICmdLinePromptForCredentialsW(LPCWSTR pszTargetName, SecHandle* pContext, DWORD dwAuthError, LPWSTR UserName, DWORD ulUserBufferSize, LPWSTR pszPassword, DWORD ulPasswordBufferSize, BOOL* pfSave, CREDUI_FLAGS dwFlags)
#uselib "credui.dll"
#cfunc global CredUICmdLinePromptForCredentialsW "CredUICmdLinePromptForCredentialsW" wstr, var, int, var, int, var, int, int, int
; res = CredUICmdLinePromptForCredentialsW(pszTargetName, pContext, dwAuthError, UserName, ulUserBufferSize, pszPassword, ulPasswordBufferSize, pfSave, dwFlags)
; pszTargetName : LPCWSTR optional -> "wstr"
; pContext : SecHandle* optional -> "var"
; dwAuthError : DWORD -> "int"
; UserName : LPWSTR in/out -> "var"
; ulUserBufferSize : DWORD -> "int"
; pszPassword : LPWSTR in/out -> "var"
; ulPasswordBufferSize : DWORD -> "int"
; pfSave : BOOL* optional, in/out -> "int"
; dwFlags : CREDUI_FLAGS -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	credui = windows.NewLazySystemDLL("credui.dll")
	procCredUICmdLinePromptForCredentialsW = credui.NewProc("CredUICmdLinePromptForCredentialsW")
)

// pszTargetName (LPCWSTR optional), pContext (SecHandle* optional), dwAuthError (DWORD), UserName (LPWSTR in/out), ulUserBufferSize (DWORD), pszPassword (LPWSTR in/out), ulPasswordBufferSize (DWORD), pfSave (BOOL* optional, in/out), dwFlags (CREDUI_FLAGS)
r1, _, err := procCredUICmdLinePromptForCredentialsW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszTargetName))),
	uintptr(pContext),
	uintptr(dwAuthError),
	uintptr(UserName),
	uintptr(ulUserBufferSize),
	uintptr(pszPassword),
	uintptr(ulPasswordBufferSize),
	uintptr(pfSave),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function CredUICmdLinePromptForCredentialsW(
  pszTargetName: PWideChar;   // LPCWSTR optional
  pContext: Pointer;   // SecHandle* optional
  dwAuthError: DWORD;   // DWORD
  UserName: PWideChar;   // LPWSTR in/out
  ulUserBufferSize: DWORD;   // DWORD
  pszPassword: PWideChar;   // LPWSTR in/out
  ulPasswordBufferSize: DWORD;   // DWORD
  pfSave: Pointer;   // BOOL* optional, in/out
  dwFlags: DWORD   // CREDUI_FLAGS
): DWORD; stdcall;
  external 'credui.dll' name 'CredUICmdLinePromptForCredentialsW';
result := DllCall("credui\CredUICmdLinePromptForCredentialsW"
    , "WStr", pszTargetName   ; LPCWSTR optional
    , "Ptr", pContext   ; SecHandle* optional
    , "UInt", dwAuthError   ; DWORD
    , "Ptr", UserName   ; LPWSTR in/out
    , "UInt", ulUserBufferSize   ; DWORD
    , "Ptr", pszPassword   ; LPWSTR in/out
    , "UInt", ulPasswordBufferSize   ; DWORD
    , "Ptr", pfSave   ; BOOL* optional, in/out
    , "UInt", dwFlags   ; CREDUI_FLAGS
    , "UInt")   ; return: DWORD
●CredUICmdLinePromptForCredentialsW(pszTargetName, pContext, dwAuthError, UserName, ulUserBufferSize, pszPassword, ulPasswordBufferSize, pfSave, dwFlags) = DLL("credui.dll", "dword CredUICmdLinePromptForCredentialsW(char*, void*, dword, char*, dword, char*, dword, void*, dword)")
# 呼び出し: CredUICmdLinePromptForCredentialsW(pszTargetName, pContext, dwAuthError, UserName, ulUserBufferSize, pszPassword, ulPasswordBufferSize, pfSave, dwFlags)
# pszTargetName : LPCWSTR optional -> "char*"
# pContext : SecHandle* optional -> "void*"
# dwAuthError : DWORD -> "dword"
# UserName : LPWSTR in/out -> "char*"
# ulUserBufferSize : DWORD -> "dword"
# pszPassword : LPWSTR in/out -> "char*"
# ulPasswordBufferSize : DWORD -> "dword"
# pfSave : BOOL* optional, in/out -> "void*"
# dwFlags : CREDUI_FLAGS -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。