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

NetGetDisplayInformationIndex

関数
指定プレフィックスに対応する表示情報のインデックスを取得する。
DLLNETAPI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD NetGetDisplayInformationIndex(
    LPCWSTR ServerName,
    DWORD Level,
    LPCWSTR Prefix,
    DWORD* Index
);

パラメーター

名前方向説明
ServerNameLPCWSTRin関数を実行するリモートサーバーの DNS 名または NetBIOS 名を指定する定数文字列へのポインターです。このパラメーターが NULL の場合は、ローカルコンピューターが使用されます。
LevelDWORDin

照会するアカウントのレベルを指定します。このパラメーターには次のいずれかの値を指定できます。

意味
1
すべてのローカルおよびグローバル(通常の)ユーザーアカウントを照会します。
2
すべてのワークステーションおよびサーバーのユーザーアカウントを照会します。
3
すべてのグローバルグループを照会します。
PrefixLPCWSTRin検索対象のプレフィックスを指定する文字列へのポインターです。
IndexDWORD*inout要求されたエントリのインデックスを受け取る値へのポインターです。

戻り値の型: DWORD

公式ドキュメント

NetGetDisplayInformationIndex 関数は、名前が指定した文字列で始まる、または名前がその文字列のアルファベット順で後に続く最初の表示情報エントリのインデックスを返します。

戻り値

関数が成功した場合、戻り値は NERR_Success です。

関数が失敗した場合、戻り値は次のいずれかのエラーコードになります。

戻り値 説明
ERROR_ACCESS_DENIED
ユーザーは要求された情報へのアクセス権を持っていません。
ERROR_INVALID_LEVEL
Level パラメーターに指定された値が無効です。
ERROR_NO_MORE_ITEMS
操作対象の項目がこれ以上ありませんでした。
NERR_InvalidComputer
コンピューター名が無効です。

解説(Remarks)

Active Directory を実行しているドメインコントローラー上でこの関数を呼び出す場合、アクセスは セキュリティ保護可能なオブジェクトのアクセス制御リスト(ACL)に基づいて許可または拒否されます。既定の ACL では、すべての認証済みユーザーと「Pre-Windows 2000 compatible access」グループのメンバーが情報を表示できます。メンバーサーバーまたはワークステーション上でこの関数を呼び出す場合、すべての認証済みユーザーが情報を表示できます。これらのプラットフォームにおける匿名アクセスおよび匿名アクセスの制限については、 Security Requirements for the Network Management Functions を参照してください。ACL、ACE、およびアクセストークンの詳細については、 Access Control Model を参照してください。

この関数は、呼び出し元が Read アクセス権を持つ情報のみを返します。呼び出し元は、ドメインオブジェクトに対する List Contents アクセス権と、System コンテナー内にある SAM Server オブジェクトに対する Enumerate Entire SAM Domain アクセス権を持っている必要があります。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

DWORD NetGetDisplayInformationIndex(
    LPCWSTR ServerName,
    DWORD Level,
    LPCWSTR Prefix,
    DWORD* Index
);
[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint NetGetDisplayInformationIndex(
    [MarshalAs(UnmanagedType.LPWStr)] string ServerName,   // LPCWSTR
    uint Level,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string Prefix,   // LPCWSTR
    ref uint Index   // DWORD* in/out
);
<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetGetDisplayInformationIndex(
    <MarshalAs(UnmanagedType.LPWStr)> ServerName As String,   ' LPCWSTR
    Level As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> Prefix As String,   ' LPCWSTR
    ByRef Index As UInteger   ' DWORD* in/out
) As UInteger
End Function
' ServerName : LPCWSTR
' Level : DWORD
' Prefix : LPCWSTR
' Index : DWORD* in/out
Declare PtrSafe Function NetGetDisplayInformationIndex Lib "netapi32" ( _
    ByVal ServerName As LongPtr, _
    ByVal Level As Long, _
    ByVal Prefix As LongPtr, _
    ByRef Index As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NetGetDisplayInformationIndex = ctypes.windll.netapi32.NetGetDisplayInformationIndex
NetGetDisplayInformationIndex.restype = wintypes.DWORD
NetGetDisplayInformationIndex.argtypes = [
    wintypes.LPCWSTR,  # ServerName : LPCWSTR
    wintypes.DWORD,  # Level : DWORD
    wintypes.LPCWSTR,  # Prefix : LPCWSTR
    ctypes.POINTER(wintypes.DWORD),  # Index : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procNetGetDisplayInformationIndex = netapi32.NewProc("NetGetDisplayInformationIndex")
)

// ServerName (LPCWSTR), Level (DWORD), Prefix (LPCWSTR), Index (DWORD* in/out)
r1, _, err := procNetGetDisplayInformationIndex.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServerName))),
	uintptr(Level),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Prefix))),
	uintptr(Index),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function NetGetDisplayInformationIndex(
  ServerName: PWideChar;   // LPCWSTR
  Level: DWORD;   // DWORD
  Prefix: PWideChar;   // LPCWSTR
  Index: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'NetGetDisplayInformationIndex';
result := DllCall("NETAPI32\NetGetDisplayInformationIndex"
    , "WStr", ServerName   ; LPCWSTR
    , "UInt", Level   ; DWORD
    , "WStr", Prefix   ; LPCWSTR
    , "Ptr", Index   ; DWORD* in/out
    , "UInt")   ; return: DWORD
●NetGetDisplayInformationIndex(ServerName, Level, Prefix, Index) = DLL("NETAPI32.dll", "dword NetGetDisplayInformationIndex(char*, dword, char*, void*)")
# 呼び出し: NetGetDisplayInformationIndex(ServerName, Level, Prefix, Index)
# ServerName : LPCWSTR -> "char*"
# Level : DWORD -> "dword"
# Prefix : LPCWSTR -> "char*"
# Index : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "netapi32" fn NetGetDisplayInformationIndex(
    ServerName: [*c]const u16, // LPCWSTR
    Level: u32, // DWORD
    Prefix: [*c]const u16, // LPCWSTR
    Index: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) u32;
proc NetGetDisplayInformationIndex(
    ServerName: WideCString,  # LPCWSTR
    Level: uint32,  # DWORD
    Prefix: WideCString,  # LPCWSTR
    Index: ptr uint32  # DWORD* in/out
): uint32 {.importc: "NetGetDisplayInformationIndex", stdcall, dynlib: "NETAPI32.dll".}
pragma(lib, "netapi32");
extern(Windows)
uint NetGetDisplayInformationIndex(
    const(wchar)* ServerName,   // LPCWSTR
    uint Level,   // DWORD
    const(wchar)* Prefix,   // LPCWSTR
    uint* Index   // DWORD* in/out
);
ccall((:NetGetDisplayInformationIndex, "NETAPI32.dll"), stdcall, UInt32,
      (Cwstring, UInt32, Cwstring, Ptr{UInt32}),
      ServerName, Level, Prefix, Index)
# ServerName : LPCWSTR -> Cwstring
# Level : DWORD -> UInt32
# Prefix : LPCWSTR -> Cwstring
# Index : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t NetGetDisplayInformationIndex(
    const uint16_t* ServerName,
    uint32_t Level,
    const uint16_t* Prefix,
    uint32_t* Index);
]]
local netapi32 = ffi.load("netapi32")
-- netapi32.NetGetDisplayInformationIndex(ServerName, Level, Prefix, Index)
-- ServerName : LPCWSTR
-- Level : DWORD
-- Prefix : LPCWSTR
-- Index : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('NETAPI32.dll');
const NetGetDisplayInformationIndex = lib.func('__stdcall', 'NetGetDisplayInformationIndex', 'uint32_t', ['str16', 'uint32_t', 'str16', 'uint32_t *']);
// NetGetDisplayInformationIndex(ServerName, Level, Prefix, Index)
// ServerName : LPCWSTR -> 'str16'
// Level : DWORD -> 'uint32_t'
// Prefix : LPCWSTR -> 'str16'
// Index : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("NETAPI32.dll", {
  NetGetDisplayInformationIndex: { parameters: ["buffer", "u32", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.NetGetDisplayInformationIndex(ServerName, Level, Prefix, Index)
// ServerName : LPCWSTR -> "buffer"
// Level : DWORD -> "u32"
// Prefix : LPCWSTR -> "buffer"
// Index : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t NetGetDisplayInformationIndex(
    const uint16_t* ServerName,
    uint32_t Level,
    const uint16_t* Prefix,
    uint32_t* Index);
C, "NETAPI32.dll");
// $ffi->NetGetDisplayInformationIndex(ServerName, Level, Prefix, Index);
// ServerName : LPCWSTR
// Level : DWORD
// Prefix : LPCWSTR
// Index : DWORD* in/out
// 構造体/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 NetGetDisplayInformationIndex(
        WString ServerName,   // LPCWSTR
        int Level,   // DWORD
        WString Prefix,   // LPCWSTR
        IntByReference Index   // DWORD* in/out
    );
}
@[Link("netapi32")]
lib LibNETAPI32
  fun NetGetDisplayInformationIndex = NetGetDisplayInformationIndex(
    ServerName : UInt16*,   # LPCWSTR
    Level : UInt32,   # DWORD
    Prefix : UInt16*,   # LPCWSTR
    Index : UInt32*   # DWORD* in/out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef NetGetDisplayInformationIndexNative = Uint32 Function(Pointer<Utf16>, Uint32, Pointer<Utf16>, Pointer<Uint32>);
typedef NetGetDisplayInformationIndexDart = int Function(Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Uint32>);
final NetGetDisplayInformationIndex = DynamicLibrary.open('NETAPI32.dll')
    .lookupFunction<NetGetDisplayInformationIndexNative, NetGetDisplayInformationIndexDart>('NetGetDisplayInformationIndex');
// ServerName : LPCWSTR -> Pointer<Utf16>
// Level : DWORD -> Uint32
// Prefix : LPCWSTR -> Pointer<Utf16>
// Index : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function NetGetDisplayInformationIndex(
  ServerName: PWideChar;   // LPCWSTR
  Level: DWORD;   // DWORD
  Prefix: PWideChar;   // LPCWSTR
  Index: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'NetGetDisplayInformationIndex';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "NetGetDisplayInformationIndex"
  c_NetGetDisplayInformationIndex :: CWString -> Word32 -> CWString -> Ptr Word32 -> IO Word32
-- ServerName : LPCWSTR -> CWString
-- Level : DWORD -> Word32
-- Prefix : LPCWSTR -> CWString
-- Index : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let netgetdisplayinformationindex =
  foreign "NetGetDisplayInformationIndex"
    ((ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* ServerName : LPCWSTR -> (ptr uint16_t) *)
(* Level : DWORD -> uint32_t *)
(* Prefix : LPCWSTR -> (ptr uint16_t) *)
(* Index : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library netapi32 (t "NETAPI32.dll"))
(cffi:use-foreign-library netapi32)

(cffi:defcfun ("NetGetDisplayInformationIndex" net-get-display-information-index :convention :stdcall) :uint32
  (server-name (:string :encoding :utf-16le))   ; LPCWSTR
  (level :uint32)   ; DWORD
  (prefix (:string :encoding :utf-16le))   ; LPCWSTR
  (index :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $NetGetDisplayInformationIndex = Win32::API::More->new('NETAPI32',
    'DWORD NetGetDisplayInformationIndex(LPCWSTR ServerName, DWORD Level, LPCWSTR Prefix, LPVOID Index)');
# my $ret = $NetGetDisplayInformationIndex->Call($ServerName, $Level, $Prefix, $Index);
# ServerName : LPCWSTR -> LPCWSTR
# Level : DWORD -> DWORD
# Prefix : LPCWSTR -> LPCWSTR
# Index : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目