ホーム › Networking.ActiveDirectory › DsGetSpnW
DsGetSpnW
関数サービス情報からSPNの配列を生成する(Unicode版)。
シグネチャ
// NTDSAPI.dll (Unicode / -W)
#include <windows.h>
DWORD DsGetSpnW(
DS_SPN_NAME_TYPE ServiceType,
LPCWSTR ServiceClass,
LPCWSTR ServiceName, // optional
WORD InstancePort,
WORD cInstanceNames,
LPCWSTR* pInstanceNames, // optional
const WORD* pInstancePorts, // optional
DWORD* pcSpn,
LPWSTR** prpszSpn
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| ServiceType | DS_SPN_NAME_TYPE | in |
| ServiceClass | LPCWSTR | in |
| ServiceName | LPCWSTR | inoptional |
| InstancePort | WORD | in |
| cInstanceNames | WORD | in |
| pInstanceNames | LPCWSTR* | inoptional |
| pInstancePorts | WORD* | inoptional |
| pcSpn | DWORD* | out |
| prpszSpn | LPWSTR** | out |
戻り値の型: DWORD
各言語での呼び出し定義
// NTDSAPI.dll (Unicode / -W)
#include <windows.h>
DWORD DsGetSpnW(
DS_SPN_NAME_TYPE ServiceType,
LPCWSTR ServiceClass,
LPCWSTR ServiceName, // optional
WORD InstancePort,
WORD cInstanceNames,
LPCWSTR* pInstanceNames, // optional
const WORD* pInstancePorts, // optional
DWORD* pcSpn,
LPWSTR** prpszSpn
);[DllImport("NTDSAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint DsGetSpnW(
int ServiceType, // DS_SPN_NAME_TYPE
[MarshalAs(UnmanagedType.LPWStr)] string ServiceClass, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string ServiceName, // LPCWSTR optional
ushort InstancePort, // WORD
ushort cInstanceNames, // WORD
IntPtr pInstanceNames, // LPCWSTR* optional
IntPtr pInstancePorts, // WORD* optional
out uint pcSpn, // DWORD* out
IntPtr prpszSpn // LPWSTR** out
);<DllImport("NTDSAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DsGetSpnW(
ServiceType As Integer, ' DS_SPN_NAME_TYPE
<MarshalAs(UnmanagedType.LPWStr)> ServiceClass As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> ServiceName As String, ' LPCWSTR optional
InstancePort As UShort, ' WORD
cInstanceNames As UShort, ' WORD
pInstanceNames As IntPtr, ' LPCWSTR* optional
pInstancePorts As IntPtr, ' WORD* optional
<Out> ByRef pcSpn As UInteger, ' DWORD* out
prpszSpn As IntPtr ' LPWSTR** out
) As UInteger
End Function' ServiceType : DS_SPN_NAME_TYPE
' ServiceClass : LPCWSTR
' ServiceName : LPCWSTR optional
' InstancePort : WORD
' cInstanceNames : WORD
' pInstanceNames : LPCWSTR* optional
' pInstancePorts : WORD* optional
' pcSpn : DWORD* out
' prpszSpn : LPWSTR** out
Declare PtrSafe Function DsGetSpnW Lib "ntdsapi" ( _
ByVal ServiceType As Long, _
ByVal ServiceClass As LongPtr, _
ByVal ServiceName As LongPtr, _
ByVal InstancePort As Integer, _
ByVal cInstanceNames As Integer, _
ByVal pInstanceNames As LongPtr, _
ByVal pInstancePorts As LongPtr, _
ByRef pcSpn As Long, _
ByVal prpszSpn 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
DsGetSpnW = ctypes.windll.ntdsapi.DsGetSpnW
DsGetSpnW.restype = wintypes.DWORD
DsGetSpnW.argtypes = [
ctypes.c_int, # ServiceType : DS_SPN_NAME_TYPE
wintypes.LPCWSTR, # ServiceClass : LPCWSTR
wintypes.LPCWSTR, # ServiceName : LPCWSTR optional
ctypes.c_ushort, # InstancePort : WORD
ctypes.c_ushort, # cInstanceNames : WORD
ctypes.c_void_p, # pInstanceNames : LPCWSTR* optional
ctypes.POINTER(ctypes.c_ushort), # pInstancePorts : WORD* optional
ctypes.POINTER(wintypes.DWORD), # pcSpn : DWORD* out
ctypes.c_void_p, # prpszSpn : LPWSTR** out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('NTDSAPI.dll')
DsGetSpnW = Fiddle::Function.new(
lib['DsGetSpnW'],
[
Fiddle::TYPE_INT, # ServiceType : DS_SPN_NAME_TYPE
Fiddle::TYPE_VOIDP, # ServiceClass : LPCWSTR
Fiddle::TYPE_VOIDP, # ServiceName : LPCWSTR optional
-Fiddle::TYPE_SHORT, # InstancePort : WORD
-Fiddle::TYPE_SHORT, # cInstanceNames : WORD
Fiddle::TYPE_VOIDP, # pInstanceNames : LPCWSTR* optional
Fiddle::TYPE_VOIDP, # pInstancePorts : WORD* optional
Fiddle::TYPE_VOIDP, # pcSpn : DWORD* out
Fiddle::TYPE_VOIDP, # prpszSpn : LPWSTR** out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "ntdsapi")]
extern "system" {
fn DsGetSpnW(
ServiceType: i32, // DS_SPN_NAME_TYPE
ServiceClass: *const u16, // LPCWSTR
ServiceName: *const u16, // LPCWSTR optional
InstancePort: u16, // WORD
cInstanceNames: u16, // WORD
pInstanceNames: *const *const u16, // LPCWSTR* optional
pInstancePorts: *const u16, // WORD* optional
pcSpn: *mut u32, // DWORD* out
prpszSpn: *mut *mut *mut u16 // LPWSTR** out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("NTDSAPI.dll", CharSet = CharSet.Unicode)]
public static extern uint DsGetSpnW(int ServiceType, [MarshalAs(UnmanagedType.LPWStr)] string ServiceClass, [MarshalAs(UnmanagedType.LPWStr)] string ServiceName, ushort InstancePort, ushort cInstanceNames, IntPtr pInstanceNames, IntPtr pInstancePorts, out uint pcSpn, IntPtr prpszSpn);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NTDSAPI_DsGetSpnW' -Namespace Win32 -PassThru
# $api::DsGetSpnW(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, pInstanceNames, pInstancePorts, pcSpn, prpszSpn)#uselib "NTDSAPI.dll"
#func global DsGetSpnW "DsGetSpnW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; DsGetSpnW ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, varptr(pInstanceNames), varptr(pInstancePorts), varptr(pcSpn), varptr(prpszSpn) ; 戻り値は stat
; ServiceType : DS_SPN_NAME_TYPE -> "wptr"
; ServiceClass : LPCWSTR -> "wptr"
; ServiceName : LPCWSTR optional -> "wptr"
; InstancePort : WORD -> "wptr"
; cInstanceNames : WORD -> "wptr"
; pInstanceNames : LPCWSTR* optional -> "wptr"
; pInstancePorts : WORD* optional -> "wptr"
; pcSpn : DWORD* out -> "wptr"
; prpszSpn : LPWSTR** out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "NTDSAPI.dll" #cfunc global DsGetSpnW "DsGetSpnW" int, wstr, wstr, int, int, var, var, var, var ; res = DsGetSpnW(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, pInstanceNames, pInstancePorts, pcSpn, prpszSpn) ; ServiceType : DS_SPN_NAME_TYPE -> "int" ; ServiceClass : LPCWSTR -> "wstr" ; ServiceName : LPCWSTR optional -> "wstr" ; InstancePort : WORD -> "int" ; cInstanceNames : WORD -> "int" ; pInstanceNames : LPCWSTR* optional -> "var" ; pInstancePorts : WORD* optional -> "var" ; pcSpn : DWORD* out -> "var" ; prpszSpn : LPWSTR** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "NTDSAPI.dll" #cfunc global DsGetSpnW "DsGetSpnW" int, wstr, wstr, int, int, sptr, sptr, sptr, sptr ; res = DsGetSpnW(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, varptr(pInstanceNames), varptr(pInstancePorts), varptr(pcSpn), varptr(prpszSpn)) ; ServiceType : DS_SPN_NAME_TYPE -> "int" ; ServiceClass : LPCWSTR -> "wstr" ; ServiceName : LPCWSTR optional -> "wstr" ; InstancePort : WORD -> "int" ; cInstanceNames : WORD -> "int" ; pInstanceNames : LPCWSTR* optional -> "sptr" ; pInstancePorts : WORD* optional -> "sptr" ; pcSpn : DWORD* out -> "sptr" ; prpszSpn : LPWSTR** out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD DsGetSpnW(DS_SPN_NAME_TYPE ServiceType, LPCWSTR ServiceClass, LPCWSTR ServiceName, WORD InstancePort, WORD cInstanceNames, LPCWSTR* pInstanceNames, WORD* pInstancePorts, DWORD* pcSpn, LPWSTR** prpszSpn) #uselib "NTDSAPI.dll" #cfunc global DsGetSpnW "DsGetSpnW" int, wstr, wstr, int, int, var, var, var, var ; res = DsGetSpnW(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, pInstanceNames, pInstancePorts, pcSpn, prpszSpn) ; ServiceType : DS_SPN_NAME_TYPE -> "int" ; ServiceClass : LPCWSTR -> "wstr" ; ServiceName : LPCWSTR optional -> "wstr" ; InstancePort : WORD -> "int" ; cInstanceNames : WORD -> "int" ; pInstanceNames : LPCWSTR* optional -> "var" ; pInstancePorts : WORD* optional -> "var" ; pcSpn : DWORD* out -> "var" ; prpszSpn : LPWSTR** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD DsGetSpnW(DS_SPN_NAME_TYPE ServiceType, LPCWSTR ServiceClass, LPCWSTR ServiceName, WORD InstancePort, WORD cInstanceNames, LPCWSTR* pInstanceNames, WORD* pInstancePorts, DWORD* pcSpn, LPWSTR** prpszSpn) #uselib "NTDSAPI.dll" #cfunc global DsGetSpnW "DsGetSpnW" int, wstr, wstr, int, int, intptr, intptr, intptr, intptr ; res = DsGetSpnW(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, varptr(pInstanceNames), varptr(pInstancePorts), varptr(pcSpn), varptr(prpszSpn)) ; ServiceType : DS_SPN_NAME_TYPE -> "int" ; ServiceClass : LPCWSTR -> "wstr" ; ServiceName : LPCWSTR optional -> "wstr" ; InstancePort : WORD -> "int" ; cInstanceNames : WORD -> "int" ; pInstanceNames : LPCWSTR* optional -> "intptr" ; pInstancePorts : WORD* optional -> "intptr" ; pcSpn : DWORD* out -> "intptr" ; prpszSpn : LPWSTR** out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ntdsapi = windows.NewLazySystemDLL("NTDSAPI.dll")
procDsGetSpnW = ntdsapi.NewProc("DsGetSpnW")
)
// ServiceType (DS_SPN_NAME_TYPE), ServiceClass (LPCWSTR), ServiceName (LPCWSTR optional), InstancePort (WORD), cInstanceNames (WORD), pInstanceNames (LPCWSTR* optional), pInstancePorts (WORD* optional), pcSpn (DWORD* out), prpszSpn (LPWSTR** out)
r1, _, err := procDsGetSpnW.Call(
uintptr(ServiceType),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServiceClass))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServiceName))),
uintptr(InstancePort),
uintptr(cInstanceNames),
uintptr(pInstanceNames),
uintptr(pInstancePorts),
uintptr(pcSpn),
uintptr(prpszSpn),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DsGetSpnW(
ServiceType: Integer; // DS_SPN_NAME_TYPE
ServiceClass: PWideChar; // LPCWSTR
ServiceName: PWideChar; // LPCWSTR optional
InstancePort: Word; // WORD
cInstanceNames: Word; // WORD
pInstanceNames: PPWideChar; // LPCWSTR* optional
pInstancePorts: Pointer; // WORD* optional
pcSpn: Pointer; // DWORD* out
prpszSpn: PPWideChar // LPWSTR** out
): DWORD; stdcall;
external 'NTDSAPI.dll' name 'DsGetSpnW';result := DllCall("NTDSAPI\DsGetSpnW"
, "Int", ServiceType ; DS_SPN_NAME_TYPE
, "WStr", ServiceClass ; LPCWSTR
, "WStr", ServiceName ; LPCWSTR optional
, "UShort", InstancePort ; WORD
, "UShort", cInstanceNames ; WORD
, "Ptr", pInstanceNames ; LPCWSTR* optional
, "Ptr", pInstancePorts ; WORD* optional
, "Ptr", pcSpn ; DWORD* out
, "Ptr", prpszSpn ; LPWSTR** out
, "UInt") ; return: DWORD●DsGetSpnW(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, pInstanceNames, pInstancePorts, pcSpn, prpszSpn) = DLL("NTDSAPI.dll", "dword DsGetSpnW(int, char*, char*, int, int, void*, void*, void*, void*)")
# 呼び出し: DsGetSpnW(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, pInstanceNames, pInstancePorts, pcSpn, prpszSpn)
# ServiceType : DS_SPN_NAME_TYPE -> "int"
# ServiceClass : LPCWSTR -> "char*"
# ServiceName : LPCWSTR optional -> "char*"
# InstancePort : WORD -> "int"
# cInstanceNames : WORD -> "int"
# pInstanceNames : LPCWSTR* optional -> "void*"
# pInstancePorts : WORD* optional -> "void*"
# pcSpn : DWORD* out -> "void*"
# prpszSpn : LPWSTR** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。