ホーム › Networking.ActiveDirectory › DsServerRegisterSpnA
DsServerRegisterSpnA
関数サーバーのSPNをユーザーオブジェクトに登録する(ANSI版)。
シグネチャ
// NTDSAPI.dll (ANSI / -A)
#include <windows.h>
DWORD DsServerRegisterSpnA(
DS_SPN_WRITE_OP Operation,
LPCSTR ServiceClass,
LPCSTR UserObjectDN // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Operation | DS_SPN_WRITE_OP | in | SPNの追加・置換・削除を指定するDS_SPN_WRITE_OP列挙値。 |
| ServiceClass | LPCSTR | in | 登録するサービスクラス名(ANSI)。 |
| UserObjectDN | LPCSTR | inoptional | SPNを登録する対象ユーザーオブジェクトのDN。NULLで自コンピュータ。 |
戻り値の型: 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 // DWORDfunction 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)。const std = @import("std");
extern "ntdsapi" fn DsServerRegisterSpnA(
Operation: i32, // DS_SPN_WRITE_OP
ServiceClass: [*c]const u8, // LPCSTR
UserObjectDN: [*c]const u8 // LPCSTR optional
) callconv(std.os.windows.WINAPI) u32;proc DsServerRegisterSpnA(
Operation: int32, # DS_SPN_WRITE_OP
ServiceClass: cstring, # LPCSTR
UserObjectDN: cstring # LPCSTR optional
): uint32 {.importc: "DsServerRegisterSpnA", stdcall, dynlib: "NTDSAPI.dll".}pragma(lib, "ntdsapi");
extern(Windows)
uint DsServerRegisterSpnA(
int Operation, // DS_SPN_WRITE_OP
const(char)* ServiceClass, // LPCSTR
const(char)* UserObjectDN // LPCSTR optional
);ccall((:DsServerRegisterSpnA, "NTDSAPI.dll"), stdcall, UInt32,
(Int32, Cstring, Cstring),
Operation, ServiceClass, UserObjectDN)
# Operation : DS_SPN_WRITE_OP -> Int32
# ServiceClass : LPCSTR -> Cstring
# UserObjectDN : LPCSTR optional -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t DsServerRegisterSpnA(
int32_t Operation,
const char* ServiceClass,
const char* UserObjectDN);
]]
local ntdsapi = ffi.load("ntdsapi")
-- ntdsapi.DsServerRegisterSpnA(Operation, ServiceClass, UserObjectDN)
-- Operation : DS_SPN_WRITE_OP
-- ServiceClass : LPCSTR
-- UserObjectDN : LPCSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('NTDSAPI.dll');
const DsServerRegisterSpnA = lib.func('__stdcall', 'DsServerRegisterSpnA', 'uint32_t', ['int32_t', 'str', 'str']);
// DsServerRegisterSpnA(Operation, ServiceClass, UserObjectDN)
// Operation : DS_SPN_WRITE_OP -> 'int32_t'
// ServiceClass : LPCSTR -> 'str'
// UserObjectDN : LPCSTR optional -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("NTDSAPI.dll", {
DsServerRegisterSpnA: { parameters: ["i32", "buffer", "buffer"], result: "u32" },
});
// lib.symbols.DsServerRegisterSpnA(Operation, ServiceClass, UserObjectDN)
// Operation : DS_SPN_WRITE_OP -> "i32"
// ServiceClass : LPCSTR -> "buffer"
// UserObjectDN : LPCSTR optional -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t DsServerRegisterSpnA(
int32_t Operation,
const char* ServiceClass,
const char* UserObjectDN);
C, "NTDSAPI.dll");
// $ffi->DsServerRegisterSpnA(Operation, ServiceClass, UserObjectDN);
// Operation : DS_SPN_WRITE_OP
// ServiceClass : LPCSTR
// UserObjectDN : LPCSTR optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Ntdsapi extends StdCallLibrary {
Ntdsapi INSTANCE = Native.load("ntdsapi", Ntdsapi.class, W32APIOptions.ASCII_OPTIONS);
int DsServerRegisterSpnA(
int Operation, // DS_SPN_WRITE_OP
String ServiceClass, // LPCSTR
String UserObjectDN // LPCSTR optional
);
}@[Link("ntdsapi")]
lib LibNTDSAPI
fun DsServerRegisterSpnA = DsServerRegisterSpnA(
Operation : Int32, # DS_SPN_WRITE_OP
ServiceClass : UInt8*, # LPCSTR
UserObjectDN : UInt8* # LPCSTR optional
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DsServerRegisterSpnANative = Uint32 Function(Int32, Pointer<Utf8>, Pointer<Utf8>);
typedef DsServerRegisterSpnADart = int Function(int, Pointer<Utf8>, Pointer<Utf8>);
final DsServerRegisterSpnA = DynamicLibrary.open('NTDSAPI.dll')
.lookupFunction<DsServerRegisterSpnANative, DsServerRegisterSpnADart>('DsServerRegisterSpnA');
// Operation : DS_SPN_WRITE_OP -> Int32
// ServiceClass : LPCSTR -> Pointer<Utf8>
// UserObjectDN : LPCSTR optional -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DsServerRegisterSpnA(
Operation: Integer; // DS_SPN_WRITE_OP
ServiceClass: PAnsiChar; // LPCSTR
UserObjectDN: PAnsiChar // LPCSTR optional
): DWORD; stdcall;
external 'NTDSAPI.dll' name 'DsServerRegisterSpnA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DsServerRegisterSpnA"
c_DsServerRegisterSpnA :: Int32 -> CString -> CString -> IO Word32
-- Operation : DS_SPN_WRITE_OP -> Int32
-- ServiceClass : LPCSTR -> CString
-- UserObjectDN : LPCSTR optional -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dsserverregisterspna =
foreign "DsServerRegisterSpnA"
(int32_t @-> string @-> string @-> returning uint32_t)
(* Operation : DS_SPN_WRITE_OP -> int32_t *)
(* ServiceClass : LPCSTR -> string *)
(* UserObjectDN : LPCSTR optional -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library ntdsapi (t "NTDSAPI.dll"))
(cffi:use-foreign-library ntdsapi)
(cffi:defcfun ("DsServerRegisterSpnA" ds-server-register-spn-a :convention :stdcall) :uint32
(operation :int32) ; DS_SPN_WRITE_OP
(service-class :string) ; LPCSTR
(user-object-dn :string)) ; LPCSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DsServerRegisterSpnA = Win32::API::More->new('NTDSAPI',
'DWORD DsServerRegisterSpnA(int Operation, LPCSTR ServiceClass, LPCSTR UserObjectDN)');
# my $ret = $DsServerRegisterSpnA->Call($Operation, $ServiceClass, $UserObjectDN);
# Operation : DS_SPN_WRITE_OP -> int
# ServiceClass : LPCSTR -> LPCSTR
# UserObjectDN : LPCSTR optional -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f DsServerRegisterSpnW (Unicode版) — サーバーのSPNをユーザーオブジェクトに登録する(Unicode版)。
使用する型