ホーム › NetworkManagement.NetManagement › NetIsServiceAccount2
NetIsServiceAccount2
関数指定アカウントがサービスアカウントか判定し種類も取得する。
シグネチャ
// NETAPI32.dll
#include <windows.h>
NTSTATUS NetIsServiceAccount2(
LPWSTR ServerName, // optional
LPWSTR AccountName,
BOOL* IsService,
MSA_INFO_ACCOUNT_TYPE* AccountType
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ServerName | LPWSTR | inoptional | 操作対象サーバー名。NULLでローカルコンピュータを指す。 |
| AccountName | LPWSTR | in | 判定対象のアカウント名。 |
| IsService | BOOL* | out | マネージドサービスアカウントか否かを受け取るBOOL出力ポインタ。 |
| AccountType | MSA_INFO_ACCOUNT_TYPE* | out | アカウントの種別(MSA_INFO_ACCOUNT_TYPE)を受け取る出力ポインタ。 |
戻り値の型: 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 bool 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 Boolean, ' 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 bool 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, varptr(IsService), varptr(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, var, var ; res = NetIsServiceAccount2(ServerName, AccountName, IsService, AccountType) ; ServerName : LPWSTR optional -> "wstr" ; AccountName : LPWSTR -> "wstr" ; IsService : BOOL* out -> "var" ; AccountType : MSA_INFO_ACCOUNT_TYPE* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "NETAPI32.dll" #cfunc global NetIsServiceAccount2 "NetIsServiceAccount2" wstr, wstr, sptr, sptr ; res = NetIsServiceAccount2(ServerName, AccountName, varptr(IsService), varptr(AccountType)) ; ServerName : LPWSTR optional -> "wstr" ; AccountName : LPWSTR -> "wstr" ; IsService : BOOL* out -> "sptr" ; AccountType : MSA_INFO_ACCOUNT_TYPE* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; NTSTATUS NetIsServiceAccount2(LPWSTR ServerName, LPWSTR AccountName, BOOL* IsService, MSA_INFO_ACCOUNT_TYPE* AccountType) #uselib "NETAPI32.dll" #cfunc global NetIsServiceAccount2 "NetIsServiceAccount2" wstr, wstr, var, var ; res = NetIsServiceAccount2(ServerName, AccountName, IsService, AccountType) ; ServerName : LPWSTR optional -> "wstr" ; AccountName : LPWSTR -> "wstr" ; IsService : BOOL* out -> "var" ; AccountType : MSA_INFO_ACCOUNT_TYPE* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; NTSTATUS NetIsServiceAccount2(LPWSTR ServerName, LPWSTR AccountName, BOOL* IsService, MSA_INFO_ACCOUNT_TYPE* AccountType) #uselib "NETAPI32.dll" #cfunc global NetIsServiceAccount2 "NetIsServiceAccount2" wstr, wstr, intptr, intptr ; res = NetIsServiceAccount2(ServerName, AccountName, varptr(IsService), varptr(AccountType)) ; ServerName : LPWSTR optional -> "wstr" ; AccountName : LPWSTR -> "wstr" ; IsService : BOOL* out -> "intptr" ; AccountType : MSA_INFO_ACCOUNT_TYPE* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
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 // NTSTATUSfunction 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)。const std = @import("std");
extern "netapi32" fn NetIsServiceAccount2(
ServerName: [*c]const u16, // LPWSTR optional
AccountName: [*c]const u16, // LPWSTR
IsService: [*c]i32, // BOOL* out
AccountType: [*c]i32 // MSA_INFO_ACCOUNT_TYPE* out
) callconv(std.os.windows.WINAPI) i32;proc NetIsServiceAccount2(
ServerName: WideCString, # LPWSTR optional
AccountName: WideCString, # LPWSTR
IsService: ptr int32, # BOOL* out
AccountType: ptr int32 # MSA_INFO_ACCOUNT_TYPE* out
): int32 {.importc: "NetIsServiceAccount2", stdcall, dynlib: "NETAPI32.dll".}pragma(lib, "netapi32");
extern(Windows)
int NetIsServiceAccount2(
const(wchar)* ServerName, // LPWSTR optional
const(wchar)* AccountName, // LPWSTR
int* IsService, // BOOL* out
int* AccountType // MSA_INFO_ACCOUNT_TYPE* out
);ccall((:NetIsServiceAccount2, "NETAPI32.dll"), stdcall, Int32,
(Cwstring, Cwstring, Ptr{Int32}, Ptr{Int32}),
ServerName, AccountName, IsService, AccountType)
# ServerName : LPWSTR optional -> Cwstring
# AccountName : LPWSTR -> Cwstring
# IsService : BOOL* out -> Ptr{Int32}
# AccountType : MSA_INFO_ACCOUNT_TYPE* out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t NetIsServiceAccount2(
const uint16_t* ServerName,
const uint16_t* AccountName,
int32_t* IsService,
int32_t* AccountType);
]]
local netapi32 = ffi.load("netapi32")
-- netapi32.NetIsServiceAccount2(ServerName, AccountName, IsService, AccountType)
-- ServerName : LPWSTR optional
-- AccountName : LPWSTR
-- IsService : BOOL* out
-- AccountType : MSA_INFO_ACCOUNT_TYPE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('NETAPI32.dll');
const NetIsServiceAccount2 = lib.func('__stdcall', 'NetIsServiceAccount2', 'int32_t', ['str16', 'str16', 'int32_t *', 'int32_t *']);
// NetIsServiceAccount2(ServerName, AccountName, IsService, AccountType)
// ServerName : LPWSTR optional -> 'str16'
// AccountName : LPWSTR -> 'str16'
// IsService : BOOL* out -> 'int32_t *'
// AccountType : MSA_INFO_ACCOUNT_TYPE* out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("NETAPI32.dll", {
NetIsServiceAccount2: { parameters: ["buffer", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.NetIsServiceAccount2(ServerName, AccountName, IsService, AccountType)
// ServerName : LPWSTR optional -> "buffer"
// AccountName : LPWSTR -> "buffer"
// IsService : BOOL* out -> "pointer"
// AccountType : MSA_INFO_ACCOUNT_TYPE* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t NetIsServiceAccount2(
const uint16_t* ServerName,
const uint16_t* AccountName,
int32_t* IsService,
int32_t* AccountType);
C, "NETAPI32.dll");
// $ffi->NetIsServiceAccount2(ServerName, AccountName, IsService, AccountType);
// ServerName : LPWSTR optional
// AccountName : LPWSTR
// IsService : BOOL* out
// AccountType : MSA_INFO_ACCOUNT_TYPE* 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 NetIsServiceAccount2(
WString ServerName, // LPWSTR optional
WString AccountName, // LPWSTR
IntByReference IsService, // BOOL* out
IntByReference AccountType // MSA_INFO_ACCOUNT_TYPE* out
);
}@[Link("netapi32")]
lib LibNETAPI32
fun NetIsServiceAccount2 = NetIsServiceAccount2(
ServerName : UInt16*, # LPWSTR optional
AccountName : UInt16*, # LPWSTR
IsService : Int32*, # BOOL* out
AccountType : Int32* # MSA_INFO_ACCOUNT_TYPE* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef NetIsServiceAccount2Native = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Int32>, Pointer<Int32>);
typedef NetIsServiceAccount2Dart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Int32>, Pointer<Int32>);
final NetIsServiceAccount2 = DynamicLibrary.open('NETAPI32.dll')
.lookupFunction<NetIsServiceAccount2Native, NetIsServiceAccount2Dart>('NetIsServiceAccount2');
// ServerName : LPWSTR optional -> Pointer<Utf16>
// AccountName : LPWSTR -> Pointer<Utf16>
// IsService : BOOL* out -> Pointer<Int32>
// AccountType : MSA_INFO_ACCOUNT_TYPE* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "NetIsServiceAccount2"
c_NetIsServiceAccount2 :: CWString -> CWString -> Ptr CInt -> Ptr Int32 -> IO Int32
-- ServerName : LPWSTR optional -> CWString
-- AccountName : LPWSTR -> CWString
-- IsService : BOOL* out -> Ptr CInt
-- AccountType : MSA_INFO_ACCOUNT_TYPE* out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let netisserviceaccount2 =
foreign "NetIsServiceAccount2"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr int32_t) @-> (ptr int32_t) @-> returning int32_t)
(* ServerName : LPWSTR optional -> (ptr uint16_t) *)
(* AccountName : LPWSTR -> (ptr uint16_t) *)
(* IsService : BOOL* out -> (ptr int32_t) *)
(* AccountType : MSA_INFO_ACCOUNT_TYPE* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library netapi32 (t "NETAPI32.dll"))
(cffi:use-foreign-library netapi32)
(cffi:defcfun ("NetIsServiceAccount2" net-is-service-account2 :convention :stdcall) :int32
(server-name (:string :encoding :utf-16le)) ; LPWSTR optional
(account-name (:string :encoding :utf-16le)) ; LPWSTR
(is-service :pointer) ; BOOL* out
(account-type :pointer)) ; MSA_INFO_ACCOUNT_TYPE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $NetIsServiceAccount2 = Win32::API::More->new('NETAPI32',
'int NetIsServiceAccount2(LPCWSTR ServerName, LPCWSTR AccountName, LPVOID IsService, LPVOID AccountType)');
# my $ret = $NetIsServiceAccount2->Call($ServerName, $AccountName, $IsService, $AccountType);
# ServerName : LPWSTR optional -> LPCWSTR
# AccountName : LPWSTR -> LPCWSTR
# IsService : BOOL* out -> LPVOID
# AccountType : MSA_INFO_ACCOUNT_TYPE* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f NetIsServiceAccount — 指定アカウントが管理されたサービスアカウントか判定する。