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

DsServerRegisterSpnW

関数
サーバーのSPNをユーザーオブジェクトに登録する(Unicode版)。
DLLNTDSAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD DsServerRegisterSpnW(
    DS_SPN_WRITE_OP Operation,
    LPCWSTR ServiceClass,
    LPCWSTR UserObjectDN   // optional
);

パラメーター

名前方向
OperationDS_SPN_WRITE_OPin
ServiceClassLPCWSTRin
UserObjectDNLPCWSTRinoptional

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DsServerRegisterSpnW(
    DS_SPN_WRITE_OP Operation,
    LPCWSTR ServiceClass,
    LPCWSTR UserObjectDN   // optional
);
[DllImport("NTDSAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint DsServerRegisterSpnW(
    int Operation,   // DS_SPN_WRITE_OP
    [MarshalAs(UnmanagedType.LPWStr)] string ServiceClass,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string UserObjectDN   // LPCWSTR optional
);
<DllImport("NTDSAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DsServerRegisterSpnW(
    Operation As Integer,   ' DS_SPN_WRITE_OP
    <MarshalAs(UnmanagedType.LPWStr)> ServiceClass As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> UserObjectDN As String   ' LPCWSTR optional
) As UInteger
End Function
' Operation : DS_SPN_WRITE_OP
' ServiceClass : LPCWSTR
' UserObjectDN : LPCWSTR optional
Declare PtrSafe Function DsServerRegisterSpnW Lib "ntdsapi" ( _
    ByVal Operation As Long, _
    ByVal ServiceClass As LongPtr, _
    ByVal UserObjectDN 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

DsServerRegisterSpnW = ctypes.windll.ntdsapi.DsServerRegisterSpnW
DsServerRegisterSpnW.restype = wintypes.DWORD
DsServerRegisterSpnW.argtypes = [
    ctypes.c_int,  # Operation : DS_SPN_WRITE_OP
    wintypes.LPCWSTR,  # ServiceClass : LPCWSTR
    wintypes.LPCWSTR,  # UserObjectDN : LPCWSTR optional
]
require 'fiddle'
require 'fiddle/import'

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

var (
	ntdsapi = windows.NewLazySystemDLL("NTDSAPI.dll")
	procDsServerRegisterSpnW = ntdsapi.NewProc("DsServerRegisterSpnW")
)

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