Win32 API 日本語リファレンス
ホームNetworkManagement.NetManagement › NetEnumerateComputerNames

NetEnumerateComputerNames

関数
コンピューターに設定された名前の一覧を列挙する。
DLLNETAPI32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

// NETAPI32.dll
#include <windows.h>

DWORD NetEnumerateComputerNames(
    LPCWSTR Server,   // optional
    NET_COMPUTER_NAME_TYPE NameType,
    DWORD Reserved,
    DWORD* EntryCount,
    LPWSTR** ComputerNames
);

パラメーター

名前方向
ServerLPCWSTRinoptional
NameTypeNET_COMPUTER_NAME_TYPEin
ReservedDWORDin
EntryCountDWORD*out
ComputerNamesLPWSTR**out

戻り値の型: DWORD

各言語での呼び出し定義

// NETAPI32.dll
#include <windows.h>

DWORD NetEnumerateComputerNames(
    LPCWSTR Server,   // optional
    NET_COMPUTER_NAME_TYPE NameType,
    DWORD Reserved,
    DWORD* EntryCount,
    LPWSTR** ComputerNames
);
[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint NetEnumerateComputerNames(
    [MarshalAs(UnmanagedType.LPWStr)] string Server,   // LPCWSTR optional
    int NameType,   // NET_COMPUTER_NAME_TYPE
    uint Reserved,   // DWORD
    out uint EntryCount,   // DWORD* out
    IntPtr ComputerNames   // LPWSTR** out
);
<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetEnumerateComputerNames(
    <MarshalAs(UnmanagedType.LPWStr)> Server As String,   ' LPCWSTR optional
    NameType As Integer,   ' NET_COMPUTER_NAME_TYPE
    Reserved As UInteger,   ' DWORD
    <Out> ByRef EntryCount As UInteger,   ' DWORD* out
    ComputerNames As IntPtr   ' LPWSTR** out
) As UInteger
End Function
' Server : LPCWSTR optional
' NameType : NET_COMPUTER_NAME_TYPE
' Reserved : DWORD
' EntryCount : DWORD* out
' ComputerNames : LPWSTR** out
Declare PtrSafe Function NetEnumerateComputerNames Lib "netapi32" ( _
    ByVal Server As LongPtr, _
    ByVal NameType As Long, _
    ByVal Reserved As Long, _
    ByRef EntryCount As Long, _
    ByVal ComputerNames As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NetEnumerateComputerNames = ctypes.windll.netapi32.NetEnumerateComputerNames
NetEnumerateComputerNames.restype = wintypes.DWORD
NetEnumerateComputerNames.argtypes = [
    wintypes.LPCWSTR,  # Server : LPCWSTR optional
    ctypes.c_int,  # NameType : NET_COMPUTER_NAME_TYPE
    wintypes.DWORD,  # Reserved : DWORD
    ctypes.POINTER(wintypes.DWORD),  # EntryCount : DWORD* out
    ctypes.c_void_p,  # ComputerNames : LPWSTR** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NETAPI32.dll')
NetEnumerateComputerNames = Fiddle::Function.new(
  lib['NetEnumerateComputerNames'],
  [
    Fiddle::TYPE_VOIDP,  # Server : LPCWSTR optional
    Fiddle::TYPE_INT,  # NameType : NET_COMPUTER_NAME_TYPE
    -Fiddle::TYPE_INT,  # Reserved : DWORD
    Fiddle::TYPE_VOIDP,  # EntryCount : DWORD* out
    Fiddle::TYPE_VOIDP,  # ComputerNames : LPWSTR** out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "netapi32")]
extern "system" {
    fn NetEnumerateComputerNames(
        Server: *const u16,  // LPCWSTR optional
        NameType: i32,  // NET_COMPUTER_NAME_TYPE
        Reserved: u32,  // DWORD
        EntryCount: *mut u32,  // DWORD* out
        ComputerNames: *mut *mut *mut u16  // LPWSTR** out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint NetEnumerateComputerNames([MarshalAs(UnmanagedType.LPWStr)] string Server, int NameType, uint Reserved, out uint EntryCount, IntPtr ComputerNames);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_NetEnumerateComputerNames' -Namespace Win32 -PassThru
# $api::NetEnumerateComputerNames(Server, NameType, Reserved, EntryCount, ComputerNames)
#uselib "NETAPI32.dll"
#func global NetEnumerateComputerNames "NetEnumerateComputerNames" sptr, sptr, sptr, sptr, sptr
; NetEnumerateComputerNames Server, NameType, Reserved, varptr(EntryCount), varptr(ComputerNames)   ; 戻り値は stat
; Server : LPCWSTR optional -> "sptr"
; NameType : NET_COMPUTER_NAME_TYPE -> "sptr"
; Reserved : DWORD -> "sptr"
; EntryCount : DWORD* out -> "sptr"
; ComputerNames : LPWSTR** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "NETAPI32.dll"
#cfunc global NetEnumerateComputerNames "NetEnumerateComputerNames" wstr, int, int, var, var
; res = NetEnumerateComputerNames(Server, NameType, Reserved, EntryCount, ComputerNames)
; Server : LPCWSTR optional -> "wstr"
; NameType : NET_COMPUTER_NAME_TYPE -> "int"
; Reserved : DWORD -> "int"
; EntryCount : DWORD* out -> "var"
; ComputerNames : LPWSTR** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD NetEnumerateComputerNames(LPCWSTR Server, NET_COMPUTER_NAME_TYPE NameType, DWORD Reserved, DWORD* EntryCount, LPWSTR** ComputerNames)
#uselib "NETAPI32.dll"
#cfunc global NetEnumerateComputerNames "NetEnumerateComputerNames" wstr, int, int, var, var
; res = NetEnumerateComputerNames(Server, NameType, Reserved, EntryCount, ComputerNames)
; Server : LPCWSTR optional -> "wstr"
; NameType : NET_COMPUTER_NAME_TYPE -> "int"
; Reserved : DWORD -> "int"
; EntryCount : DWORD* out -> "var"
; ComputerNames : LPWSTR** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procNetEnumerateComputerNames = netapi32.NewProc("NetEnumerateComputerNames")
)

// Server (LPCWSTR optional), NameType (NET_COMPUTER_NAME_TYPE), Reserved (DWORD), EntryCount (DWORD* out), ComputerNames (LPWSTR** out)
r1, _, err := procNetEnumerateComputerNames.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Server))),
	uintptr(NameType),
	uintptr(Reserved),
	uintptr(EntryCount),
	uintptr(ComputerNames),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function NetEnumerateComputerNames(
  Server: PWideChar;   // LPCWSTR optional
  NameType: Integer;   // NET_COMPUTER_NAME_TYPE
  Reserved: DWORD;   // DWORD
  EntryCount: Pointer;   // DWORD* out
  ComputerNames: PPWideChar   // LPWSTR** out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'NetEnumerateComputerNames';
result := DllCall("NETAPI32\NetEnumerateComputerNames"
    , "WStr", Server   ; LPCWSTR optional
    , "Int", NameType   ; NET_COMPUTER_NAME_TYPE
    , "UInt", Reserved   ; DWORD
    , "Ptr", EntryCount   ; DWORD* out
    , "Ptr", ComputerNames   ; LPWSTR** out
    , "UInt")   ; return: DWORD
●NetEnumerateComputerNames(Server, NameType, Reserved, EntryCount, ComputerNames) = DLL("NETAPI32.dll", "dword NetEnumerateComputerNames(char*, int, dword, void*, void*)")
# 呼び出し: NetEnumerateComputerNames(Server, NameType, Reserved, EntryCount, ComputerNames)
# Server : LPCWSTR optional -> "char*"
# NameType : NET_COMPUTER_NAME_TYPE -> "int"
# Reserved : DWORD -> "dword"
# EntryCount : DWORD* out -> "void*"
# ComputerNames : LPWSTR** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。