ホーム › Networking.ActiveDirectory › DsBindWithSpnW
DsBindWithSpnW
関数SPNと資格情報を指定してドメインコントローラへ接続する(Unicode版)。
シグネチャ
// NTDSAPI.dll (Unicode / -W)
#include <windows.h>
DWORD DsBindWithSpnW(
LPCWSTR DomainControllerName, // optional
LPCWSTR DnsDomainName, // optional
void* AuthIdentity, // optional
LPCWSTR ServicePrincipalName, // optional
HANDLE* phDS
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| DomainControllerName | LPCWSTR | inoptional |
| DnsDomainName | LPCWSTR | inoptional |
| AuthIdentity | void* | inoptional |
| ServicePrincipalName | LPCWSTR | inoptional |
| phDS | HANDLE* | out |
戻り値の型: DWORD
各言語での呼び出し定義
// NTDSAPI.dll (Unicode / -W)
#include <windows.h>
DWORD DsBindWithSpnW(
LPCWSTR DomainControllerName, // optional
LPCWSTR DnsDomainName, // optional
void* AuthIdentity, // optional
LPCWSTR ServicePrincipalName, // optional
HANDLE* phDS
);[DllImport("NTDSAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint DsBindWithSpnW(
[MarshalAs(UnmanagedType.LPWStr)] string DomainControllerName, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string DnsDomainName, // LPCWSTR optional
IntPtr AuthIdentity, // void* optional
[MarshalAs(UnmanagedType.LPWStr)] string ServicePrincipalName, // LPCWSTR optional
IntPtr phDS // HANDLE* out
);<DllImport("NTDSAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DsBindWithSpnW(
<MarshalAs(UnmanagedType.LPWStr)> DomainControllerName As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> DnsDomainName As String, ' LPCWSTR optional
AuthIdentity As IntPtr, ' void* optional
<MarshalAs(UnmanagedType.LPWStr)> ServicePrincipalName As String, ' LPCWSTR optional
phDS As IntPtr ' HANDLE* out
) As UInteger
End Function' DomainControllerName : LPCWSTR optional
' DnsDomainName : LPCWSTR optional
' AuthIdentity : void* optional
' ServicePrincipalName : LPCWSTR optional
' phDS : HANDLE* out
Declare PtrSafe Function DsBindWithSpnW Lib "ntdsapi" ( _
ByVal DomainControllerName As LongPtr, _
ByVal DnsDomainName As LongPtr, _
ByVal AuthIdentity As LongPtr, _
ByVal ServicePrincipalName 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
DsBindWithSpnW = ctypes.windll.ntdsapi.DsBindWithSpnW
DsBindWithSpnW.restype = wintypes.DWORD
DsBindWithSpnW.argtypes = [
wintypes.LPCWSTR, # DomainControllerName : LPCWSTR optional
wintypes.LPCWSTR, # DnsDomainName : LPCWSTR optional
ctypes.POINTER(None), # AuthIdentity : void* optional
wintypes.LPCWSTR, # ServicePrincipalName : LPCWSTR optional
ctypes.c_void_p, # phDS : HANDLE* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('NTDSAPI.dll')
DsBindWithSpnW = Fiddle::Function.new(
lib['DsBindWithSpnW'],
[
Fiddle::TYPE_VOIDP, # DomainControllerName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # DnsDomainName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # AuthIdentity : void* optional
Fiddle::TYPE_VOIDP, # ServicePrincipalName : LPCWSTR 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 DsBindWithSpnW(
DomainControllerName: *const u16, // LPCWSTR optional
DnsDomainName: *const u16, // LPCWSTR optional
AuthIdentity: *mut (), // void* optional
ServicePrincipalName: *const u16, // LPCWSTR 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 DsBindWithSpnW([MarshalAs(UnmanagedType.LPWStr)] string DomainControllerName, [MarshalAs(UnmanagedType.LPWStr)] string DnsDomainName, IntPtr AuthIdentity, [MarshalAs(UnmanagedType.LPWStr)] string ServicePrincipalName, IntPtr phDS);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NTDSAPI_DsBindWithSpnW' -Namespace Win32 -PassThru
# $api::DsBindWithSpnW(DomainControllerName, DnsDomainName, AuthIdentity, ServicePrincipalName, phDS)#uselib "NTDSAPI.dll"
#func global DsBindWithSpnW "DsBindWithSpnW" wptr, wptr, wptr, wptr, wptr
; DsBindWithSpnW DomainControllerName, DnsDomainName, AuthIdentity, ServicePrincipalName, phDS ; 戻り値は stat
; DomainControllerName : LPCWSTR optional -> "wptr"
; DnsDomainName : LPCWSTR optional -> "wptr"
; AuthIdentity : void* optional -> "wptr"
; ServicePrincipalName : LPCWSTR optional -> "wptr"
; phDS : HANDLE* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "NTDSAPI.dll"
#cfunc global DsBindWithSpnW "DsBindWithSpnW" wstr, wstr, sptr, wstr, sptr
; res = DsBindWithSpnW(DomainControllerName, DnsDomainName, AuthIdentity, ServicePrincipalName, phDS)
; DomainControllerName : LPCWSTR optional -> "wstr"
; DnsDomainName : LPCWSTR optional -> "wstr"
; AuthIdentity : void* optional -> "sptr"
; ServicePrincipalName : LPCWSTR optional -> "wstr"
; phDS : HANDLE* out -> "sptr"; DWORD DsBindWithSpnW(LPCWSTR DomainControllerName, LPCWSTR DnsDomainName, void* AuthIdentity, LPCWSTR ServicePrincipalName, HANDLE* phDS)
#uselib "NTDSAPI.dll"
#cfunc global DsBindWithSpnW "DsBindWithSpnW" wstr, wstr, intptr, wstr, intptr
; res = DsBindWithSpnW(DomainControllerName, DnsDomainName, AuthIdentity, ServicePrincipalName, phDS)
; DomainControllerName : LPCWSTR optional -> "wstr"
; DnsDomainName : LPCWSTR optional -> "wstr"
; AuthIdentity : void* optional -> "intptr"
; ServicePrincipalName : LPCWSTR optional -> "wstr"
; phDS : HANDLE* out -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ntdsapi = windows.NewLazySystemDLL("NTDSAPI.dll")
procDsBindWithSpnW = ntdsapi.NewProc("DsBindWithSpnW")
)
// DomainControllerName (LPCWSTR optional), DnsDomainName (LPCWSTR optional), AuthIdentity (void* optional), ServicePrincipalName (LPCWSTR optional), phDS (HANDLE* out)
r1, _, err := procDsBindWithSpnW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DomainControllerName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DnsDomainName))),
uintptr(AuthIdentity),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServicePrincipalName))),
uintptr(phDS),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DsBindWithSpnW(
DomainControllerName: PWideChar; // LPCWSTR optional
DnsDomainName: PWideChar; // LPCWSTR optional
AuthIdentity: Pointer; // void* optional
ServicePrincipalName: PWideChar; // LPCWSTR optional
phDS: Pointer // HANDLE* out
): DWORD; stdcall;
external 'NTDSAPI.dll' name 'DsBindWithSpnW';result := DllCall("NTDSAPI\DsBindWithSpnW"
, "WStr", DomainControllerName ; LPCWSTR optional
, "WStr", DnsDomainName ; LPCWSTR optional
, "Ptr", AuthIdentity ; void* optional
, "WStr", ServicePrincipalName ; LPCWSTR optional
, "Ptr", phDS ; HANDLE* out
, "UInt") ; return: DWORD●DsBindWithSpnW(DomainControllerName, DnsDomainName, AuthIdentity, ServicePrincipalName, phDS) = DLL("NTDSAPI.dll", "dword DsBindWithSpnW(char*, char*, void*, char*, void*)")
# 呼び出し: DsBindWithSpnW(DomainControllerName, DnsDomainName, AuthIdentity, ServicePrincipalName, phDS)
# DomainControllerName : LPCWSTR optional -> "char*"
# DnsDomainName : LPCWSTR optional -> "char*"
# AuthIdentity : void* optional -> "void*"
# ServicePrincipalName : LPCWSTR optional -> "char*"
# phDS : HANDLE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。