NetServerComputerNameAdd
関数シグネチャ
// NETAPI32.dll
#include <windows.h>
DWORD NetServerComputerNameAdd(
LPWSTR ServerName, // optional
LPWSTR EmulatedDomainName, // optional
LPWSTR EmulatedServerName
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ServerName | LPWSTR | inoptional | 関数を実行するリモートサーバーの名前を指定する文字列へのポインターです。このパラメーターが NULL の場合は、ローカルコンピューターが使用されます。 |
| EmulatedDomainName | LPWSTR | inoptional | 指定したサーバーが EmulatedServerName を使用して自身の存在を通知する際に使用するドメイン名を含む文字列へのポインターです。このパラメーターは省略可能です。 |
| EmulatedServerName | LPWSTR | in | ServerName パラメーターで指定された名前に加えて、サーバーがサポートを開始するエミュレート名を含む null で終わる文字列へのポインターです。 |
戻り値の型: DWORD
公式ドキュメント
NetServerComputerNameAdd 関数は、指定したサーバーがアクティブになっているトランスポートを列挙し、エミュレートされたサーバー名を各トランスポートにバインドします。
戻り値
関数が成功すると、戻り値は NERR_Success になります。 NetServerComputerNameAdd は、指定されたエミュレートサーバー名が少なくとも 1 つのトランスポートに追加された場合に成功する点に注意してください。
関数が失敗した場合、戻り値は次のいずれかのエラーコードになります。
| 戻り値 | 説明 |
|---|---|
| ユーザーが要求された情報にアクセスする権限を持っていません。 | |
| ネットワーク上に重複した名前が存在します。 | |
| ネットワーク上でドメイン名が見つかりませんでした。 | |
| 指定されたパラメーターが無効です。 | |
| 使用可能なメモリが不足しています。 |
解説(Remarks)
NetServerComputerNameAdd 関数を正常に実行できるのは、Administrators または Server Operators ローカルグループのメンバーのみです。
ServerName パラメーターで指定されたサーバーは、サポートしていたすべての名前を引き続きサポートし、さらに NetServerComputerNameAdd 関数の呼び出しが成功するたびに提供される新しい名前のサポートを開始します。
NetServerComputerNameAdd の呼び出しによって行われる名前エミュレーションは、サーバーが再起動または再ブートすると終了します。再起動や再ブートを行わずに、以前の NetServerComputerNameAdd の呼び出しで設定した名前エミュレーションを中止するには、NetServerComputerNameDel 関数を呼び出すことができます。
NetServerComputerNameAdd 関数は通常、システム管理者がサーバーを置き換える際に、ユーザーに対してその移行を透過的に保ちたい場合に使用されます。
使用例
次に示すのは、\Server1 が \Server2 への要求にも応答するように要求する NetServerComputerNameAdd 関数の呼び出し例です。
NetServerComputerNameAdd (Server1, NULL, Server2);
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// NETAPI32.dll
#include <windows.h>
DWORD NetServerComputerNameAdd(
LPWSTR ServerName, // optional
LPWSTR EmulatedDomainName, // optional
LPWSTR EmulatedServerName
);[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint NetServerComputerNameAdd(
[MarshalAs(UnmanagedType.LPWStr)] string ServerName, // LPWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string EmulatedDomainName, // LPWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string EmulatedServerName // LPWSTR
);<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetServerComputerNameAdd(
<MarshalAs(UnmanagedType.LPWStr)> ServerName As String, ' LPWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> EmulatedDomainName As String, ' LPWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> EmulatedServerName As String ' LPWSTR
) As UInteger
End Function' ServerName : LPWSTR optional
' EmulatedDomainName : LPWSTR optional
' EmulatedServerName : LPWSTR
Declare PtrSafe Function NetServerComputerNameAdd Lib "netapi32" ( _
ByVal ServerName As LongPtr, _
ByVal EmulatedDomainName As LongPtr, _
ByVal EmulatedServerName As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
NetServerComputerNameAdd = ctypes.windll.netapi32.NetServerComputerNameAdd
NetServerComputerNameAdd.restype = wintypes.DWORD
NetServerComputerNameAdd.argtypes = [
wintypes.LPCWSTR, # ServerName : LPWSTR optional
wintypes.LPCWSTR, # EmulatedDomainName : LPWSTR optional
wintypes.LPCWSTR, # EmulatedServerName : LPWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('NETAPI32.dll')
NetServerComputerNameAdd = Fiddle::Function.new(
lib['NetServerComputerNameAdd'],
[
Fiddle::TYPE_VOIDP, # ServerName : LPWSTR optional
Fiddle::TYPE_VOIDP, # EmulatedDomainName : LPWSTR optional
Fiddle::TYPE_VOIDP, # EmulatedServerName : LPWSTR
],
-Fiddle::TYPE_INT)#[link(name = "netapi32")]
extern "system" {
fn NetServerComputerNameAdd(
ServerName: *mut u16, // LPWSTR optional
EmulatedDomainName: *mut u16, // LPWSTR optional
EmulatedServerName: *mut u16 // LPWSTR
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint NetServerComputerNameAdd([MarshalAs(UnmanagedType.LPWStr)] string ServerName, [MarshalAs(UnmanagedType.LPWStr)] string EmulatedDomainName, [MarshalAs(UnmanagedType.LPWStr)] string EmulatedServerName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_NetServerComputerNameAdd' -Namespace Win32 -PassThru
# $api::NetServerComputerNameAdd(ServerName, EmulatedDomainName, EmulatedServerName)#uselib "NETAPI32.dll"
#func global NetServerComputerNameAdd "NetServerComputerNameAdd" sptr, sptr, sptr
; NetServerComputerNameAdd ServerName, EmulatedDomainName, EmulatedServerName ; 戻り値は stat
; ServerName : LPWSTR optional -> "sptr"
; EmulatedDomainName : LPWSTR optional -> "sptr"
; EmulatedServerName : LPWSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "NETAPI32.dll"
#cfunc global NetServerComputerNameAdd "NetServerComputerNameAdd" wstr, wstr, wstr
; res = NetServerComputerNameAdd(ServerName, EmulatedDomainName, EmulatedServerName)
; ServerName : LPWSTR optional -> "wstr"
; EmulatedDomainName : LPWSTR optional -> "wstr"
; EmulatedServerName : LPWSTR -> "wstr"; DWORD NetServerComputerNameAdd(LPWSTR ServerName, LPWSTR EmulatedDomainName, LPWSTR EmulatedServerName)
#uselib "NETAPI32.dll"
#cfunc global NetServerComputerNameAdd "NetServerComputerNameAdd" wstr, wstr, wstr
; res = NetServerComputerNameAdd(ServerName, EmulatedDomainName, EmulatedServerName)
; ServerName : LPWSTR optional -> "wstr"
; EmulatedDomainName : LPWSTR optional -> "wstr"
; EmulatedServerName : LPWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
procNetServerComputerNameAdd = netapi32.NewProc("NetServerComputerNameAdd")
)
// ServerName (LPWSTR optional), EmulatedDomainName (LPWSTR optional), EmulatedServerName (LPWSTR)
r1, _, err := procNetServerComputerNameAdd.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServerName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(EmulatedDomainName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(EmulatedServerName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction NetServerComputerNameAdd(
ServerName: PWideChar; // LPWSTR optional
EmulatedDomainName: PWideChar; // LPWSTR optional
EmulatedServerName: PWideChar // LPWSTR
): DWORD; stdcall;
external 'NETAPI32.dll' name 'NetServerComputerNameAdd';result := DllCall("NETAPI32\NetServerComputerNameAdd"
, "WStr", ServerName ; LPWSTR optional
, "WStr", EmulatedDomainName ; LPWSTR optional
, "WStr", EmulatedServerName ; LPWSTR
, "UInt") ; return: DWORD●NetServerComputerNameAdd(ServerName, EmulatedDomainName, EmulatedServerName) = DLL("NETAPI32.dll", "dword NetServerComputerNameAdd(char*, char*, char*)")
# 呼び出し: NetServerComputerNameAdd(ServerName, EmulatedDomainName, EmulatedServerName)
# ServerName : LPWSTR optional -> "char*"
# EmulatedDomainName : LPWSTR optional -> "char*"
# EmulatedServerName : LPWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "netapi32" fn NetServerComputerNameAdd(
ServerName: [*c]const u16, // LPWSTR optional
EmulatedDomainName: [*c]const u16, // LPWSTR optional
EmulatedServerName: [*c]const u16 // LPWSTR
) callconv(std.os.windows.WINAPI) u32;proc NetServerComputerNameAdd(
ServerName: WideCString, # LPWSTR optional
EmulatedDomainName: WideCString, # LPWSTR optional
EmulatedServerName: WideCString # LPWSTR
): uint32 {.importc: "NetServerComputerNameAdd", stdcall, dynlib: "NETAPI32.dll".}pragma(lib, "netapi32");
extern(Windows)
uint NetServerComputerNameAdd(
const(wchar)* ServerName, // LPWSTR optional
const(wchar)* EmulatedDomainName, // LPWSTR optional
const(wchar)* EmulatedServerName // LPWSTR
);ccall((:NetServerComputerNameAdd, "NETAPI32.dll"), stdcall, UInt32,
(Cwstring, Cwstring, Cwstring),
ServerName, EmulatedDomainName, EmulatedServerName)
# ServerName : LPWSTR optional -> Cwstring
# EmulatedDomainName : LPWSTR optional -> Cwstring
# EmulatedServerName : LPWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t NetServerComputerNameAdd(
const uint16_t* ServerName,
const uint16_t* EmulatedDomainName,
const uint16_t* EmulatedServerName);
]]
local netapi32 = ffi.load("netapi32")
-- netapi32.NetServerComputerNameAdd(ServerName, EmulatedDomainName, EmulatedServerName)
-- ServerName : LPWSTR optional
-- EmulatedDomainName : LPWSTR optional
-- EmulatedServerName : LPWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('NETAPI32.dll');
const NetServerComputerNameAdd = lib.func('__stdcall', 'NetServerComputerNameAdd', 'uint32_t', ['str16', 'str16', 'str16']);
// NetServerComputerNameAdd(ServerName, EmulatedDomainName, EmulatedServerName)
// ServerName : LPWSTR optional -> 'str16'
// EmulatedDomainName : LPWSTR optional -> 'str16'
// EmulatedServerName : LPWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("NETAPI32.dll", {
NetServerComputerNameAdd: { parameters: ["buffer", "buffer", "buffer"], result: "u32" },
});
// lib.symbols.NetServerComputerNameAdd(ServerName, EmulatedDomainName, EmulatedServerName)
// ServerName : LPWSTR optional -> "buffer"
// EmulatedDomainName : LPWSTR optional -> "buffer"
// EmulatedServerName : LPWSTR -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t NetServerComputerNameAdd(
const uint16_t* ServerName,
const uint16_t* EmulatedDomainName,
const uint16_t* EmulatedServerName);
C, "NETAPI32.dll");
// $ffi->NetServerComputerNameAdd(ServerName, EmulatedDomainName, EmulatedServerName);
// ServerName : LPWSTR optional
// EmulatedDomainName : LPWSTR optional
// EmulatedServerName : LPWSTR
// 構造体/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 Netapi32 extends StdCallLibrary {
Netapi32 INSTANCE = Native.load("netapi32", Netapi32.class);
int NetServerComputerNameAdd(
WString ServerName, // LPWSTR optional
WString EmulatedDomainName, // LPWSTR optional
WString EmulatedServerName // LPWSTR
);
}@[Link("netapi32")]
lib LibNETAPI32
fun NetServerComputerNameAdd = NetServerComputerNameAdd(
ServerName : UInt16*, # LPWSTR optional
EmulatedDomainName : UInt16*, # LPWSTR optional
EmulatedServerName : UInt16* # LPWSTR
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef NetServerComputerNameAddNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
typedef NetServerComputerNameAddDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
final NetServerComputerNameAdd = DynamicLibrary.open('NETAPI32.dll')
.lookupFunction<NetServerComputerNameAddNative, NetServerComputerNameAddDart>('NetServerComputerNameAdd');
// ServerName : LPWSTR optional -> Pointer<Utf16>
// EmulatedDomainName : LPWSTR optional -> Pointer<Utf16>
// EmulatedServerName : LPWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function NetServerComputerNameAdd(
ServerName: PWideChar; // LPWSTR optional
EmulatedDomainName: PWideChar; // LPWSTR optional
EmulatedServerName: PWideChar // LPWSTR
): DWORD; stdcall;
external 'NETAPI32.dll' name 'NetServerComputerNameAdd';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "NetServerComputerNameAdd"
c_NetServerComputerNameAdd :: CWString -> CWString -> CWString -> IO Word32
-- ServerName : LPWSTR optional -> CWString
-- EmulatedDomainName : LPWSTR optional -> CWString
-- EmulatedServerName : LPWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let netservercomputernameadd =
foreign "NetServerComputerNameAdd"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* ServerName : LPWSTR optional -> (ptr uint16_t) *)
(* EmulatedDomainName : LPWSTR optional -> (ptr uint16_t) *)
(* EmulatedServerName : LPWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library netapi32 (t "NETAPI32.dll"))
(cffi:use-foreign-library netapi32)
(cffi:defcfun ("NetServerComputerNameAdd" net-server-computer-name-add :convention :stdcall) :uint32
(server-name (:string :encoding :utf-16le)) ; LPWSTR optional
(emulated-domain-name (:string :encoding :utf-16le)) ; LPWSTR optional
(emulated-server-name (:string :encoding :utf-16le))) ; LPWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $NetServerComputerNameAdd = Win32::API::More->new('NETAPI32',
'DWORD NetServerComputerNameAdd(LPCWSTR ServerName, LPCWSTR EmulatedDomainName, LPCWSTR EmulatedServerName)');
# my $ret = $NetServerComputerNameAdd->Call($ServerName, $EmulatedDomainName, $EmulatedServerName);
# ServerName : LPWSTR optional -> LPCWSTR
# EmulatedDomainName : LPWSTR optional -> LPCWSTR
# EmulatedServerName : LPWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f NetServerComputerNameDel — サーバーからエミュレートするコンピューター名を削除する。
- f NetServerTransportAdd — サーバーをトランスポートプロトコルにバインドする。
- f NetServerTransportAddEx — 拡張情報を指定してサーバーをトランスポートにバインドする。
- f NetServerTransportEnum — サーバーがバインドされているトランスポートを列挙する。