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

DsServerRegisterSpnA

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

シグネチャ

// NTDSAPI.dll  (ANSI / -A)
#include <windows.h>

DWORD DsServerRegisterSpnA(
    DS_SPN_WRITE_OP Operation,
    LPCSTR ServiceClass,
    LPCSTR UserObjectDN   // optional
);

パラメーター

名前方向
OperationDS_SPN_WRITE_OPin
ServiceClassLPCSTRin
UserObjectDNLPCSTRinoptional

戻り値の型: DWORD

各言語での呼び出し定義

// NTDSAPI.dll  (ANSI / -A)
#include <windows.h>

DWORD DsServerRegisterSpnA(
    DS_SPN_WRITE_OP Operation,
    LPCSTR ServiceClass,
    LPCSTR UserObjectDN   // optional
);
[DllImport("NTDSAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint DsServerRegisterSpnA(
    int Operation,   // DS_SPN_WRITE_OP
    [MarshalAs(UnmanagedType.LPStr)] string ServiceClass,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string UserObjectDN   // LPCSTR optional
);
<DllImport("NTDSAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function DsServerRegisterSpnA(
    Operation As Integer,   ' DS_SPN_WRITE_OP
    <MarshalAs(UnmanagedType.LPStr)> ServiceClass As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> UserObjectDN As String   ' LPCSTR optional
) As UInteger
End Function
' Operation : DS_SPN_WRITE_OP
' ServiceClass : LPCSTR
' UserObjectDN : LPCSTR optional
Declare PtrSafe Function DsServerRegisterSpnA Lib "ntdsapi" ( _
    ByVal Operation As Long, _
    ByVal ServiceClass As String, _
    ByVal UserObjectDN As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	ntdsapi = windows.NewLazySystemDLL("NTDSAPI.dll")
	procDsServerRegisterSpnA = ntdsapi.NewProc("DsServerRegisterSpnA")
)

// Operation (DS_SPN_WRITE_OP), ServiceClass (LPCSTR), UserObjectDN (LPCSTR optional)
r1, _, err := procDsServerRegisterSpnA.Call(
	uintptr(Operation),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(ServiceClass))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(UserObjectDN))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DsServerRegisterSpnA(
  Operation: Integer;   // DS_SPN_WRITE_OP
  ServiceClass: PAnsiChar;   // LPCSTR
  UserObjectDN: PAnsiChar   // LPCSTR optional
): DWORD; stdcall;
  external 'NTDSAPI.dll' name 'DsServerRegisterSpnA';
result := DllCall("NTDSAPI\DsServerRegisterSpnA"
    , "Int", Operation   ; DS_SPN_WRITE_OP
    , "AStr", ServiceClass   ; LPCSTR
    , "AStr", UserObjectDN   ; LPCSTR optional
    , "UInt")   ; return: DWORD
●DsServerRegisterSpnA(Operation, ServiceClass, UserObjectDN) = DLL("NTDSAPI.dll", "dword DsServerRegisterSpnA(int, char*, char*)")
# 呼び出し: DsServerRegisterSpnA(Operation, ServiceClass, UserObjectDN)
# Operation : DS_SPN_WRITE_OP -> "int"
# ServiceClass : LPCSTR -> "char*"
# UserObjectDN : LPCSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。