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

DsBindWithCredW

関数
資格情報を指定してドメインコントローラへ接続する(Unicode版)。
DLLNTDSAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD DsBindWithCredW(
    LPCWSTR DomainControllerName,   // optional
    LPCWSTR DnsDomainName,   // optional
    void* AuthIdentity,   // optional
    HANDLE* phDS
);

パラメーター

名前方向
DomainControllerNameLPCWSTRinoptional
DnsDomainNameLPCWSTRinoptional
AuthIdentityvoid*inoptional
phDSHANDLE*out

戻り値の型: DWORD

各言語での呼び出し定義

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

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

DsBindWithCredW = ctypes.windll.ntdsapi.DsBindWithCredW
DsBindWithCredW.restype = wintypes.DWORD
DsBindWithCredW.argtypes = [
    wintypes.LPCWSTR,  # DomainControllerName : LPCWSTR optional
    wintypes.LPCWSTR,  # DnsDomainName : LPCWSTR optional
    ctypes.POINTER(None),  # AuthIdentity : void* optional
    ctypes.c_void_p,  # phDS : HANDLE* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	ntdsapi = windows.NewLazySystemDLL("NTDSAPI.dll")
	procDsBindWithCredW = ntdsapi.NewProc("DsBindWithCredW")
)

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