Win32 API 日本語リファレンス
ホームNetworking.ActiveDirectory › DsMakePasswordCredentialsW

DsMakePasswordCredentialsW

関数
ユーザー名とパスワードから認証資格情報を作成する(Unicode版)。
DLLNTDSAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD DsMakePasswordCredentialsW(
    LPCWSTR User,   // optional
    LPCWSTR Domain,   // optional
    LPCWSTR Password,   // optional
    void** pAuthIdentity
);

パラメーター

名前方向
UserLPCWSTRinoptional
DomainLPCWSTRinoptional
PasswordLPCWSTRinoptional
pAuthIdentityvoid**out

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DsMakePasswordCredentialsW(
    LPCWSTR User,   // optional
    LPCWSTR Domain,   // optional
    LPCWSTR Password,   // optional
    void** pAuthIdentity
);
[DllImport("NTDSAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint DsMakePasswordCredentialsW(
    [MarshalAs(UnmanagedType.LPWStr)] string User,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string Domain,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string Password,   // LPCWSTR optional
    IntPtr pAuthIdentity   // void** out
);
<DllImport("NTDSAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DsMakePasswordCredentialsW(
    <MarshalAs(UnmanagedType.LPWStr)> User As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> Domain As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> Password As String,   ' LPCWSTR optional
    pAuthIdentity As IntPtr   ' void** out
) As UInteger
End Function
' User : LPCWSTR optional
' Domain : LPCWSTR optional
' Password : LPCWSTR optional
' pAuthIdentity : void** out
Declare PtrSafe Function DsMakePasswordCredentialsW Lib "ntdsapi" ( _
    ByVal User As LongPtr, _
    ByVal Domain As LongPtr, _
    ByVal Password As LongPtr, _
    ByVal pAuthIdentity 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

DsMakePasswordCredentialsW = ctypes.windll.ntdsapi.DsMakePasswordCredentialsW
DsMakePasswordCredentialsW.restype = wintypes.DWORD
DsMakePasswordCredentialsW.argtypes = [
    wintypes.LPCWSTR,  # User : LPCWSTR optional
    wintypes.LPCWSTR,  # Domain : LPCWSTR optional
    wintypes.LPCWSTR,  # Password : LPCWSTR optional
    ctypes.c_void_p,  # pAuthIdentity : void** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	ntdsapi = windows.NewLazySystemDLL("NTDSAPI.dll")
	procDsMakePasswordCredentialsW = ntdsapi.NewProc("DsMakePasswordCredentialsW")
)

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