ホーム › Security.Credentials › CredUIPromptForCredentialsW
CredUIPromptForCredentialsW
関数ユーザー名とパスワードの入力ダイアログを表示する。
シグネチャ
// credui.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR CredUIPromptForCredentialsW(
CREDUI_INFOW* pUiInfo, // optional
LPCWSTR pszTargetName, // optional
SecHandle* pContext, // optional
DWORD dwAuthError,
LPWSTR pszUserName,
DWORD ulUserNameBufferSize,
LPWSTR pszPassword,
DWORD ulPasswordBufferSize,
BOOL* save, // optional
CREDUI_FLAGS dwFlags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pUiInfo | CREDUI_INFOW* | inoptional |
| pszTargetName | LPCWSTR | inoptional |
| pContext | SecHandle* | optional |
| dwAuthError | DWORD | in |
| pszUserName | LPWSTR | inout |
| ulUserNameBufferSize | DWORD | in |
| pszPassword | LPWSTR | inout |
| ulPasswordBufferSize | DWORD | in |
| save | BOOL* | inoutoptional |
| dwFlags | CREDUI_FLAGS | in |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// credui.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR CredUIPromptForCredentialsW(
CREDUI_INFOW* pUiInfo, // optional
LPCWSTR pszTargetName, // optional
SecHandle* pContext, // optional
DWORD dwAuthError,
LPWSTR pszUserName,
DWORD ulUserNameBufferSize,
LPWSTR pszPassword,
DWORD ulPasswordBufferSize,
BOOL* save, // optional
CREDUI_FLAGS dwFlags
);[DllImport("credui.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint CredUIPromptForCredentialsW(
IntPtr pUiInfo, // CREDUI_INFOW* optional
[MarshalAs(UnmanagedType.LPWStr)] string pszTargetName, // LPCWSTR optional
IntPtr pContext, // SecHandle* optional
uint dwAuthError, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszUserName, // LPWSTR in/out
uint ulUserNameBufferSize, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPassword, // LPWSTR in/out
uint ulPasswordBufferSize, // DWORD
IntPtr save, // BOOL* optional, in/out
uint dwFlags // CREDUI_FLAGS
);<DllImport("credui.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function CredUIPromptForCredentialsW(
pUiInfo As IntPtr, ' CREDUI_INFOW* optional
<MarshalAs(UnmanagedType.LPWStr)> pszTargetName As String, ' LPCWSTR optional
pContext As IntPtr, ' SecHandle* optional
dwAuthError As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> pszUserName As System.Text.StringBuilder, ' LPWSTR in/out
ulUserNameBufferSize As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> pszPassword As System.Text.StringBuilder, ' LPWSTR in/out
ulPasswordBufferSize As UInteger, ' DWORD
save As IntPtr, ' BOOL* optional, in/out
dwFlags As UInteger ' CREDUI_FLAGS
) As UInteger
End Function' pUiInfo : CREDUI_INFOW* optional
' pszTargetName : LPCWSTR optional
' pContext : SecHandle* optional
' dwAuthError : DWORD
' pszUserName : LPWSTR in/out
' ulUserNameBufferSize : DWORD
' pszPassword : LPWSTR in/out
' ulPasswordBufferSize : DWORD
' save : BOOL* optional, in/out
' dwFlags : CREDUI_FLAGS
Declare PtrSafe Function CredUIPromptForCredentialsW Lib "credui" ( _
ByVal pUiInfo As LongPtr, _
ByVal pszTargetName As LongPtr, _
ByVal pContext As LongPtr, _
ByVal dwAuthError As Long, _
ByVal pszUserName As LongPtr, _
ByVal ulUserNameBufferSize As Long, _
ByVal pszPassword As LongPtr, _
ByVal ulPasswordBufferSize As Long, _
ByVal save 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
CredUIPromptForCredentialsW = ctypes.windll.credui.CredUIPromptForCredentialsW
CredUIPromptForCredentialsW.restype = wintypes.DWORD
CredUIPromptForCredentialsW.argtypes = [
ctypes.c_void_p, # pUiInfo : CREDUI_INFOW* optional
wintypes.LPCWSTR, # pszTargetName : LPCWSTR optional
ctypes.c_void_p, # pContext : SecHandle* optional
wintypes.DWORD, # dwAuthError : DWORD
wintypes.LPWSTR, # pszUserName : LPWSTR in/out
wintypes.DWORD, # ulUserNameBufferSize : DWORD
wintypes.LPWSTR, # pszPassword : LPWSTR in/out
wintypes.DWORD, # ulPasswordBufferSize : DWORD
ctypes.c_void_p, # save : BOOL* optional, in/out
wintypes.DWORD, # dwFlags : CREDUI_FLAGS
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('credui.dll')
CredUIPromptForCredentialsW = Fiddle::Function.new(
lib['CredUIPromptForCredentialsW'],
[
Fiddle::TYPE_VOIDP, # pUiInfo : CREDUI_INFOW* optional
Fiddle::TYPE_VOIDP, # pszTargetName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pContext : SecHandle* optional
-Fiddle::TYPE_INT, # dwAuthError : DWORD
Fiddle::TYPE_VOIDP, # pszUserName : LPWSTR in/out
-Fiddle::TYPE_INT, # ulUserNameBufferSize : DWORD
Fiddle::TYPE_VOIDP, # pszPassword : LPWSTR in/out
-Fiddle::TYPE_INT, # ulPasswordBufferSize : DWORD
Fiddle::TYPE_VOIDP, # save : 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 CredUIPromptForCredentialsW(
pUiInfo: *mut CREDUI_INFOW, // CREDUI_INFOW* optional
pszTargetName: *const u16, // LPCWSTR optional
pContext: *mut SecHandle, // SecHandle* optional
dwAuthError: u32, // DWORD
pszUserName: *mut u16, // LPWSTR in/out
ulUserNameBufferSize: u32, // DWORD
pszPassword: *mut u16, // LPWSTR in/out
ulPasswordBufferSize: u32, // DWORD
save: *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 CredUIPromptForCredentialsW(IntPtr pUiInfo, [MarshalAs(UnmanagedType.LPWStr)] string pszTargetName, IntPtr pContext, uint dwAuthError, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszUserName, uint ulUserNameBufferSize, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPassword, uint ulPasswordBufferSize, IntPtr save, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'credui_CredUIPromptForCredentialsW' -Namespace Win32 -PassThru
# $api::CredUIPromptForCredentialsW(pUiInfo, pszTargetName, pContext, dwAuthError, pszUserName, ulUserNameBufferSize, pszPassword, ulPasswordBufferSize, save, dwFlags)#uselib "credui.dll"
#func global CredUIPromptForCredentialsW "CredUIPromptForCredentialsW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; CredUIPromptForCredentialsW varptr(pUiInfo), pszTargetName, varptr(pContext), dwAuthError, varptr(pszUserName), ulUserNameBufferSize, varptr(pszPassword), ulPasswordBufferSize, save, dwFlags ; 戻り値は stat
; pUiInfo : CREDUI_INFOW* optional -> "wptr"
; pszTargetName : LPCWSTR optional -> "wptr"
; pContext : SecHandle* optional -> "wptr"
; dwAuthError : DWORD -> "wptr"
; pszUserName : LPWSTR in/out -> "wptr"
; ulUserNameBufferSize : DWORD -> "wptr"
; pszPassword : LPWSTR in/out -> "wptr"
; ulPasswordBufferSize : DWORD -> "wptr"
; save : BOOL* optional, in/out -> "wptr"
; dwFlags : CREDUI_FLAGS -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "credui.dll" #cfunc global CredUIPromptForCredentialsW "CredUIPromptForCredentialsW" var, wstr, var, int, var, int, var, int, int, int ; res = CredUIPromptForCredentialsW(pUiInfo, pszTargetName, pContext, dwAuthError, pszUserName, ulUserNameBufferSize, pszPassword, ulPasswordBufferSize, save, dwFlags) ; pUiInfo : CREDUI_INFOW* optional -> "var" ; pszTargetName : LPCWSTR optional -> "wstr" ; pContext : SecHandle* optional -> "var" ; dwAuthError : DWORD -> "int" ; pszUserName : LPWSTR in/out -> "var" ; ulUserNameBufferSize : DWORD -> "int" ; pszPassword : LPWSTR in/out -> "var" ; ulPasswordBufferSize : DWORD -> "int" ; save : BOOL* optional, in/out -> "int" ; dwFlags : CREDUI_FLAGS -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "credui.dll" #cfunc global CredUIPromptForCredentialsW "CredUIPromptForCredentialsW" sptr, wstr, sptr, int, sptr, int, sptr, int, int, int ; res = CredUIPromptForCredentialsW(varptr(pUiInfo), pszTargetName, varptr(pContext), dwAuthError, varptr(pszUserName), ulUserNameBufferSize, varptr(pszPassword), ulPasswordBufferSize, save, dwFlags) ; pUiInfo : CREDUI_INFOW* optional -> "sptr" ; pszTargetName : LPCWSTR optional -> "wstr" ; pContext : SecHandle* optional -> "sptr" ; dwAuthError : DWORD -> "int" ; pszUserName : LPWSTR in/out -> "sptr" ; ulUserNameBufferSize : DWORD -> "int" ; pszPassword : LPWSTR in/out -> "sptr" ; ulPasswordBufferSize : DWORD -> "int" ; save : BOOL* optional, in/out -> "int" ; dwFlags : CREDUI_FLAGS -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR CredUIPromptForCredentialsW(CREDUI_INFOW* pUiInfo, LPCWSTR pszTargetName, SecHandle* pContext, DWORD dwAuthError, LPWSTR pszUserName, DWORD ulUserNameBufferSize, LPWSTR pszPassword, DWORD ulPasswordBufferSize, BOOL* save, CREDUI_FLAGS dwFlags) #uselib "credui.dll" #cfunc global CredUIPromptForCredentialsW "CredUIPromptForCredentialsW" var, wstr, var, int, var, int, var, int, int, int ; res = CredUIPromptForCredentialsW(pUiInfo, pszTargetName, pContext, dwAuthError, pszUserName, ulUserNameBufferSize, pszPassword, ulPasswordBufferSize, save, dwFlags) ; pUiInfo : CREDUI_INFOW* optional -> "var" ; pszTargetName : LPCWSTR optional -> "wstr" ; pContext : SecHandle* optional -> "var" ; dwAuthError : DWORD -> "int" ; pszUserName : LPWSTR in/out -> "var" ; ulUserNameBufferSize : DWORD -> "int" ; pszPassword : LPWSTR in/out -> "var" ; ulPasswordBufferSize : DWORD -> "int" ; save : BOOL* optional, in/out -> "int" ; dwFlags : CREDUI_FLAGS -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR CredUIPromptForCredentialsW(CREDUI_INFOW* pUiInfo, LPCWSTR pszTargetName, SecHandle* pContext, DWORD dwAuthError, LPWSTR pszUserName, DWORD ulUserNameBufferSize, LPWSTR pszPassword, DWORD ulPasswordBufferSize, BOOL* save, CREDUI_FLAGS dwFlags) #uselib "credui.dll" #cfunc global CredUIPromptForCredentialsW "CredUIPromptForCredentialsW" intptr, wstr, intptr, int, intptr, int, intptr, int, int, int ; res = CredUIPromptForCredentialsW(varptr(pUiInfo), pszTargetName, varptr(pContext), dwAuthError, varptr(pszUserName), ulUserNameBufferSize, varptr(pszPassword), ulPasswordBufferSize, save, dwFlags) ; pUiInfo : CREDUI_INFOW* optional -> "intptr" ; pszTargetName : LPCWSTR optional -> "wstr" ; pContext : SecHandle* optional -> "intptr" ; dwAuthError : DWORD -> "int" ; pszUserName : LPWSTR in/out -> "intptr" ; ulUserNameBufferSize : DWORD -> "int" ; pszPassword : LPWSTR in/out -> "intptr" ; ulPasswordBufferSize : DWORD -> "int" ; save : BOOL* optional, in/out -> "int" ; dwFlags : CREDUI_FLAGS -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
credui = windows.NewLazySystemDLL("credui.dll")
procCredUIPromptForCredentialsW = credui.NewProc("CredUIPromptForCredentialsW")
)
// pUiInfo (CREDUI_INFOW* optional), pszTargetName (LPCWSTR optional), pContext (SecHandle* optional), dwAuthError (DWORD), pszUserName (LPWSTR in/out), ulUserNameBufferSize (DWORD), pszPassword (LPWSTR in/out), ulPasswordBufferSize (DWORD), save (BOOL* optional, in/out), dwFlags (CREDUI_FLAGS)
r1, _, err := procCredUIPromptForCredentialsW.Call(
uintptr(pUiInfo),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszTargetName))),
uintptr(pContext),
uintptr(dwAuthError),
uintptr(pszUserName),
uintptr(ulUserNameBufferSize),
uintptr(pszPassword),
uintptr(ulPasswordBufferSize),
uintptr(save),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction CredUIPromptForCredentialsW(
pUiInfo: Pointer; // CREDUI_INFOW* optional
pszTargetName: PWideChar; // LPCWSTR optional
pContext: Pointer; // SecHandle* optional
dwAuthError: DWORD; // DWORD
pszUserName: PWideChar; // LPWSTR in/out
ulUserNameBufferSize: DWORD; // DWORD
pszPassword: PWideChar; // LPWSTR in/out
ulPasswordBufferSize: DWORD; // DWORD
save: Pointer; // BOOL* optional, in/out
dwFlags: DWORD // CREDUI_FLAGS
): DWORD; stdcall;
external 'credui.dll' name 'CredUIPromptForCredentialsW';result := DllCall("credui\CredUIPromptForCredentialsW"
, "Ptr", pUiInfo ; CREDUI_INFOW* optional
, "WStr", pszTargetName ; LPCWSTR optional
, "Ptr", pContext ; SecHandle* optional
, "UInt", dwAuthError ; DWORD
, "Ptr", pszUserName ; LPWSTR in/out
, "UInt", ulUserNameBufferSize ; DWORD
, "Ptr", pszPassword ; LPWSTR in/out
, "UInt", ulPasswordBufferSize ; DWORD
, "Ptr", save ; BOOL* optional, in/out
, "UInt", dwFlags ; CREDUI_FLAGS
, "UInt") ; return: WIN32_ERROR●CredUIPromptForCredentialsW(pUiInfo, pszTargetName, pContext, dwAuthError, pszUserName, ulUserNameBufferSize, pszPassword, ulPasswordBufferSize, save, dwFlags) = DLL("credui.dll", "dword CredUIPromptForCredentialsW(void*, char*, void*, dword, char*, dword, char*, dword, void*, dword)")
# 呼び出し: CredUIPromptForCredentialsW(pUiInfo, pszTargetName, pContext, dwAuthError, pszUserName, ulUserNameBufferSize, pszPassword, ulPasswordBufferSize, save, dwFlags)
# pUiInfo : CREDUI_INFOW* optional -> "void*"
# pszTargetName : LPCWSTR optional -> "char*"
# pContext : SecHandle* optional -> "void*"
# dwAuthError : DWORD -> "dword"
# pszUserName : LPWSTR in/out -> "char*"
# ulUserNameBufferSize : DWORD -> "dword"
# pszPassword : LPWSTR in/out -> "char*"
# ulPasswordBufferSize : DWORD -> "dword"
# save : BOOL* optional, in/out -> "void*"
# dwFlags : CREDUI_FLAGS -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。