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

NetIsServiceAccount2

関数
指定アカウントがサービスアカウントか判定し種類も取得する。
DLLNETAPI32.dll呼出規約winapi

シグネチャ

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

NTSTATUS NetIsServiceAccount2(
    LPWSTR ServerName,   // optional
    LPWSTR AccountName,
    BOOL* IsService,
    MSA_INFO_ACCOUNT_TYPE* AccountType
);

パラメーター

名前方向
ServerNameLPWSTRinoptional
AccountNameLPWSTRin
IsServiceBOOL*out
AccountTypeMSA_INFO_ACCOUNT_TYPE*out

戻り値の型: NTSTATUS

各言語での呼び出し定義

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

NTSTATUS NetIsServiceAccount2(
    LPWSTR ServerName,   // optional
    LPWSTR AccountName,
    BOOL* IsService,
    MSA_INFO_ACCOUNT_TYPE* AccountType
);
[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern int NetIsServiceAccount2(
    [MarshalAs(UnmanagedType.LPWStr)] string ServerName,   // LPWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string AccountName,   // LPWSTR
    out int IsService,   // BOOL* out
    out int AccountType   // MSA_INFO_ACCOUNT_TYPE* out
);
<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetIsServiceAccount2(
    <MarshalAs(UnmanagedType.LPWStr)> ServerName As String,   ' LPWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> AccountName As String,   ' LPWSTR
    <Out> ByRef IsService As Integer,   ' BOOL* out
    <Out> ByRef AccountType As Integer   ' MSA_INFO_ACCOUNT_TYPE* out
) As Integer
End Function
' ServerName : LPWSTR optional
' AccountName : LPWSTR
' IsService : BOOL* out
' AccountType : MSA_INFO_ACCOUNT_TYPE* out
Declare PtrSafe Function NetIsServiceAccount2 Lib "netapi32" ( _
    ByVal ServerName As LongPtr, _
    ByVal AccountName As LongPtr, _
    ByRef IsService As Long, _
    ByRef AccountType As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NetIsServiceAccount2 = ctypes.windll.netapi32.NetIsServiceAccount2
NetIsServiceAccount2.restype = ctypes.c_int
NetIsServiceAccount2.argtypes = [
    wintypes.LPCWSTR,  # ServerName : LPWSTR optional
    wintypes.LPCWSTR,  # AccountName : LPWSTR
    ctypes.c_void_p,  # IsService : BOOL* out
    ctypes.c_void_p,  # AccountType : MSA_INFO_ACCOUNT_TYPE* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NETAPI32.dll')
NetIsServiceAccount2 = Fiddle::Function.new(
  lib['NetIsServiceAccount2'],
  [
    Fiddle::TYPE_VOIDP,  # ServerName : LPWSTR optional
    Fiddle::TYPE_VOIDP,  # AccountName : LPWSTR
    Fiddle::TYPE_VOIDP,  # IsService : BOOL* out
    Fiddle::TYPE_VOIDP,  # AccountType : MSA_INFO_ACCOUNT_TYPE* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "netapi32")]
extern "system" {
    fn NetIsServiceAccount2(
        ServerName: *mut u16,  // LPWSTR optional
        AccountName: *mut u16,  // LPWSTR
        IsService: *mut i32,  // BOOL* out
        AccountType: *mut i32  // MSA_INFO_ACCOUNT_TYPE* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NETAPI32.dll")]
public static extern int NetIsServiceAccount2([MarshalAs(UnmanagedType.LPWStr)] string ServerName, [MarshalAs(UnmanagedType.LPWStr)] string AccountName, out int IsService, out int AccountType);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_NetIsServiceAccount2' -Namespace Win32 -PassThru
# $api::NetIsServiceAccount2(ServerName, AccountName, IsService, AccountType)
#uselib "NETAPI32.dll"
#func global NetIsServiceAccount2 "NetIsServiceAccount2" sptr, sptr, sptr, sptr
; NetIsServiceAccount2 ServerName, AccountName, IsService, AccountType   ; 戻り値は stat
; ServerName : LPWSTR optional -> "sptr"
; AccountName : LPWSTR -> "sptr"
; IsService : BOOL* out -> "sptr"
; AccountType : MSA_INFO_ACCOUNT_TYPE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "NETAPI32.dll"
#cfunc global NetIsServiceAccount2 "NetIsServiceAccount2" wstr, wstr, int, int
; res = NetIsServiceAccount2(ServerName, AccountName, IsService, AccountType)
; ServerName : LPWSTR optional -> "wstr"
; AccountName : LPWSTR -> "wstr"
; IsService : BOOL* out -> "int"
; AccountType : MSA_INFO_ACCOUNT_TYPE* out -> "int"
; NTSTATUS NetIsServiceAccount2(LPWSTR ServerName, LPWSTR AccountName, BOOL* IsService, MSA_INFO_ACCOUNT_TYPE* AccountType)
#uselib "NETAPI32.dll"
#cfunc global NetIsServiceAccount2 "NetIsServiceAccount2" wstr, wstr, int, int
; res = NetIsServiceAccount2(ServerName, AccountName, IsService, AccountType)
; ServerName : LPWSTR optional -> "wstr"
; AccountName : LPWSTR -> "wstr"
; IsService : BOOL* out -> "int"
; AccountType : MSA_INFO_ACCOUNT_TYPE* out -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procNetIsServiceAccount2 = netapi32.NewProc("NetIsServiceAccount2")
)

// ServerName (LPWSTR optional), AccountName (LPWSTR), IsService (BOOL* out), AccountType (MSA_INFO_ACCOUNT_TYPE* out)
r1, _, err := procNetIsServiceAccount2.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServerName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(AccountName))),
	uintptr(IsService),
	uintptr(AccountType),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // NTSTATUS
function NetIsServiceAccount2(
  ServerName: PWideChar;   // LPWSTR optional
  AccountName: PWideChar;   // LPWSTR
  IsService: Pointer;   // BOOL* out
  AccountType: Pointer   // MSA_INFO_ACCOUNT_TYPE* out
): Integer; stdcall;
  external 'NETAPI32.dll' name 'NetIsServiceAccount2';
result := DllCall("NETAPI32\NetIsServiceAccount2"
    , "WStr", ServerName   ; LPWSTR optional
    , "WStr", AccountName   ; LPWSTR
    , "Ptr", IsService   ; BOOL* out
    , "Ptr", AccountType   ; MSA_INFO_ACCOUNT_TYPE* out
    , "Int")   ; return: NTSTATUS
●NetIsServiceAccount2(ServerName, AccountName, IsService, AccountType) = DLL("NETAPI32.dll", "int NetIsServiceAccount2(char*, char*, void*, void*)")
# 呼び出し: NetIsServiceAccount2(ServerName, AccountName, IsService, AccountType)
# ServerName : LPWSTR optional -> "char*"
# AccountName : LPWSTR -> "char*"
# IsService : BOOL* out -> "void*"
# AccountType : MSA_INFO_ACCOUNT_TYPE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。