ホーム › NetworkManagement.NetManagement › NetJoinDomain
NetJoinDomain
関数コンピューターをワークグループまたはドメインに参加させる。
シグネチャ
// NETAPI32.dll
#include <windows.h>
DWORD NetJoinDomain(
LPCWSTR lpServer, // optional
LPCWSTR lpDomain,
LPCWSTR lpMachineAccountOU, // optional
LPCWSTR lpAccount, // optional
LPCWSTR lpPassword, // optional
NET_JOIN_DOMAIN_JOIN_OPTIONS fJoinOptions
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpServer | LPCWSTR | inoptional |
| lpDomain | LPCWSTR | in |
| lpMachineAccountOU | LPCWSTR | inoptional |
| lpAccount | LPCWSTR | inoptional |
| lpPassword | LPCWSTR | inoptional |
| fJoinOptions | NET_JOIN_DOMAIN_JOIN_OPTIONS | in |
戻り値の型: DWORD
各言語での呼び出し定義
// NETAPI32.dll
#include <windows.h>
DWORD NetJoinDomain(
LPCWSTR lpServer, // optional
LPCWSTR lpDomain,
LPCWSTR lpMachineAccountOU, // optional
LPCWSTR lpAccount, // optional
LPCWSTR lpPassword, // optional
NET_JOIN_DOMAIN_JOIN_OPTIONS fJoinOptions
);[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint NetJoinDomain(
[MarshalAs(UnmanagedType.LPWStr)] string lpServer, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string lpDomain, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string lpMachineAccountOU, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string lpAccount, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string lpPassword, // LPCWSTR optional
uint fJoinOptions // NET_JOIN_DOMAIN_JOIN_OPTIONS
);<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetJoinDomain(
<MarshalAs(UnmanagedType.LPWStr)> lpServer As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> lpDomain As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> lpMachineAccountOU As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> lpAccount As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> lpPassword As String, ' LPCWSTR optional
fJoinOptions As UInteger ' NET_JOIN_DOMAIN_JOIN_OPTIONS
) As UInteger
End Function' lpServer : LPCWSTR optional
' lpDomain : LPCWSTR
' lpMachineAccountOU : LPCWSTR optional
' lpAccount : LPCWSTR optional
' lpPassword : LPCWSTR optional
' fJoinOptions : NET_JOIN_DOMAIN_JOIN_OPTIONS
Declare PtrSafe Function NetJoinDomain Lib "netapi32" ( _
ByVal lpServer As LongPtr, _
ByVal lpDomain As LongPtr, _
ByVal lpMachineAccountOU As LongPtr, _
ByVal lpAccount As LongPtr, _
ByVal lpPassword As LongPtr, _
ByVal fJoinOptions As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
NetJoinDomain = ctypes.windll.netapi32.NetJoinDomain
NetJoinDomain.restype = wintypes.DWORD
NetJoinDomain.argtypes = [
wintypes.LPCWSTR, # lpServer : LPCWSTR optional
wintypes.LPCWSTR, # lpDomain : LPCWSTR
wintypes.LPCWSTR, # lpMachineAccountOU : LPCWSTR optional
wintypes.LPCWSTR, # lpAccount : LPCWSTR optional
wintypes.LPCWSTR, # lpPassword : LPCWSTR optional
wintypes.DWORD, # fJoinOptions : NET_JOIN_DOMAIN_JOIN_OPTIONS
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('NETAPI32.dll')
NetJoinDomain = Fiddle::Function.new(
lib['NetJoinDomain'],
[
Fiddle::TYPE_VOIDP, # lpServer : LPCWSTR optional
Fiddle::TYPE_VOIDP, # lpDomain : LPCWSTR
Fiddle::TYPE_VOIDP, # lpMachineAccountOU : LPCWSTR optional
Fiddle::TYPE_VOIDP, # lpAccount : LPCWSTR optional
Fiddle::TYPE_VOIDP, # lpPassword : LPCWSTR optional
-Fiddle::TYPE_INT, # fJoinOptions : NET_JOIN_DOMAIN_JOIN_OPTIONS
],
-Fiddle::TYPE_INT)#[link(name = "netapi32")]
extern "system" {
fn NetJoinDomain(
lpServer: *const u16, // LPCWSTR optional
lpDomain: *const u16, // LPCWSTR
lpMachineAccountOU: *const u16, // LPCWSTR optional
lpAccount: *const u16, // LPCWSTR optional
lpPassword: *const u16, // LPCWSTR optional
fJoinOptions: u32 // NET_JOIN_DOMAIN_JOIN_OPTIONS
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint NetJoinDomain([MarshalAs(UnmanagedType.LPWStr)] string lpServer, [MarshalAs(UnmanagedType.LPWStr)] string lpDomain, [MarshalAs(UnmanagedType.LPWStr)] string lpMachineAccountOU, [MarshalAs(UnmanagedType.LPWStr)] string lpAccount, [MarshalAs(UnmanagedType.LPWStr)] string lpPassword, uint fJoinOptions);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_NetJoinDomain' -Namespace Win32 -PassThru
# $api::NetJoinDomain(lpServer, lpDomain, lpMachineAccountOU, lpAccount, lpPassword, fJoinOptions)#uselib "NETAPI32.dll"
#func global NetJoinDomain "NetJoinDomain" sptr, sptr, sptr, sptr, sptr, sptr
; NetJoinDomain lpServer, lpDomain, lpMachineAccountOU, lpAccount, lpPassword, fJoinOptions ; 戻り値は stat
; lpServer : LPCWSTR optional -> "sptr"
; lpDomain : LPCWSTR -> "sptr"
; lpMachineAccountOU : LPCWSTR optional -> "sptr"
; lpAccount : LPCWSTR optional -> "sptr"
; lpPassword : LPCWSTR optional -> "sptr"
; fJoinOptions : NET_JOIN_DOMAIN_JOIN_OPTIONS -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "NETAPI32.dll"
#cfunc global NetJoinDomain "NetJoinDomain" wstr, wstr, wstr, wstr, wstr, int
; res = NetJoinDomain(lpServer, lpDomain, lpMachineAccountOU, lpAccount, lpPassword, fJoinOptions)
; lpServer : LPCWSTR optional -> "wstr"
; lpDomain : LPCWSTR -> "wstr"
; lpMachineAccountOU : LPCWSTR optional -> "wstr"
; lpAccount : LPCWSTR optional -> "wstr"
; lpPassword : LPCWSTR optional -> "wstr"
; fJoinOptions : NET_JOIN_DOMAIN_JOIN_OPTIONS -> "int"; DWORD NetJoinDomain(LPCWSTR lpServer, LPCWSTR lpDomain, LPCWSTR lpMachineAccountOU, LPCWSTR lpAccount, LPCWSTR lpPassword, NET_JOIN_DOMAIN_JOIN_OPTIONS fJoinOptions)
#uselib "NETAPI32.dll"
#cfunc global NetJoinDomain "NetJoinDomain" wstr, wstr, wstr, wstr, wstr, int
; res = NetJoinDomain(lpServer, lpDomain, lpMachineAccountOU, lpAccount, lpPassword, fJoinOptions)
; lpServer : LPCWSTR optional -> "wstr"
; lpDomain : LPCWSTR -> "wstr"
; lpMachineAccountOU : LPCWSTR optional -> "wstr"
; lpAccount : LPCWSTR optional -> "wstr"
; lpPassword : LPCWSTR optional -> "wstr"
; fJoinOptions : NET_JOIN_DOMAIN_JOIN_OPTIONS -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
procNetJoinDomain = netapi32.NewProc("NetJoinDomain")
)
// lpServer (LPCWSTR optional), lpDomain (LPCWSTR), lpMachineAccountOU (LPCWSTR optional), lpAccount (LPCWSTR optional), lpPassword (LPCWSTR optional), fJoinOptions (NET_JOIN_DOMAIN_JOIN_OPTIONS)
r1, _, err := procNetJoinDomain.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpServer))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpDomain))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpMachineAccountOU))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpAccount))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpPassword))),
uintptr(fJoinOptions),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction NetJoinDomain(
lpServer: PWideChar; // LPCWSTR optional
lpDomain: PWideChar; // LPCWSTR
lpMachineAccountOU: PWideChar; // LPCWSTR optional
lpAccount: PWideChar; // LPCWSTR optional
lpPassword: PWideChar; // LPCWSTR optional
fJoinOptions: DWORD // NET_JOIN_DOMAIN_JOIN_OPTIONS
): DWORD; stdcall;
external 'NETAPI32.dll' name 'NetJoinDomain';result := DllCall("NETAPI32\NetJoinDomain"
, "WStr", lpServer ; LPCWSTR optional
, "WStr", lpDomain ; LPCWSTR
, "WStr", lpMachineAccountOU ; LPCWSTR optional
, "WStr", lpAccount ; LPCWSTR optional
, "WStr", lpPassword ; LPCWSTR optional
, "UInt", fJoinOptions ; NET_JOIN_DOMAIN_JOIN_OPTIONS
, "UInt") ; return: DWORD●NetJoinDomain(lpServer, lpDomain, lpMachineAccountOU, lpAccount, lpPassword, fJoinOptions) = DLL("NETAPI32.dll", "dword NetJoinDomain(char*, char*, char*, char*, char*, dword)")
# 呼び出し: NetJoinDomain(lpServer, lpDomain, lpMachineAccountOU, lpAccount, lpPassword, fJoinOptions)
# lpServer : LPCWSTR optional -> "char*"
# lpDomain : LPCWSTR -> "char*"
# lpMachineAccountOU : LPCWSTR optional -> "char*"
# lpAccount : LPCWSTR optional -> "char*"
# lpPassword : LPCWSTR optional -> "char*"
# fJoinOptions : NET_JOIN_DOMAIN_JOIN_OPTIONS -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。