EnumServicesStatusExA
関数シグネチャ
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
BOOL EnumServicesStatusExA(
SC_HANDLE hSCManager,
SC_ENUM_TYPE InfoLevel,
ENUM_SERVICE_TYPE dwServiceType,
ENUM_SERVICE_STATE dwServiceState,
BYTE* lpServices, // optional
DWORD cbBufSize,
DWORD* pcbBytesNeeded,
DWORD* lpServicesReturned,
DWORD* lpResumeHandle, // optional
LPCSTR pszGroupName // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hSCManager | SC_HANDLE | in | サービス制御マネージャーデータベースへのハンドル。このハンドルは OpenSCManager 関数によって返され、SC_MANAGER_ENUMERATE_SERVICE アクセス権を持っている必要があります。詳細については、 Service Security and Access Rights を参照してください。 | ||||||||||||||
| InfoLevel | SC_ENUM_TYPE | in | 返されるサービス属性。データベース内の各サービスの名前とサービス状態情報を取得するには、SC_ENUM_PROCESS_INFO を使用します。lpServices パラメーターは、 ENUM_SERVICE_STATUS_PROCESS 構造体の配列を受け取るバッファーへのポインターです。バッファーは、これらの構造体およびそのメンバーが指す文字列を格納できる十分な大きさである必要があります。 現在、他の情報レベルは定義されていません。 | ||||||||||||||
| dwServiceType | ENUM_SERVICE_TYPE | in | 列挙するサービスの種類。このパラメーターには、次の値を 1 つ以上指定できます。
| ||||||||||||||
| dwServiceState | ENUM_SERVICE_STATE | in | 列挙するサービスの状態。このパラメーターには、次のいずれかの値を指定できます。
| ||||||||||||||
| lpServices | BYTE* | outoptional | 状態情報を受け取るバッファーへのポインター。このデータの形式は InfoLevel パラメーターの値によって異なります。 この配列の最大サイズは 256K バイトです。必要なサイズを確認するには、このパラメーターに NULL を、cbBufSize パラメーターに 0 を指定します。関数は失敗し、GetLastError は ERROR_MORE_DATA を返します。必要なサイズは pcbBytesNeeded パラメーターで受け取ります。 Windows Server 2003 および Windows XP: この配列の最大サイズは 64K バイトです。この制限は Windows Server 2003 with SP1 および Windows XP with SP2 以降で引き上げられました。 | ||||||||||||||
| cbBufSize | DWORD | in | lpServices パラメーターが指すバッファーのサイズ(バイト単位)。 | ||||||||||||||
| pcbBytesNeeded | DWORD* | out | バッファーが小さすぎる場合に、残りのサービスエントリを返すために必要なバイト数を受け取る変数へのポインター。 | ||||||||||||||
| lpServicesReturned | DWORD* | out | 返されたサービスエントリの数を受け取る変数へのポインター。 | ||||||||||||||
| lpResumeHandle | DWORD* | inoutoptional | 入力時に列挙の開始位置を指定する変数へのポインター。 EnumServicesStatusEx 関数を初めて呼び出すときは、この値を 0 に設定する必要があります。出力時には、関数が成功した場合この値は 0 になります。ただし、関数が 0 を返し、 GetLastError 関数が ERROR_MORE_DATA を返す場合、この値は、追加データを取得するために EnumServicesStatusEx 関数を呼び出す際に次に読み取るサービスエントリを示します。 | ||||||||||||||
| pszGroupName | LPCSTR | inoptional | ロード順序グループ名。このパラメーターが文字列の場合、列挙されるのはその文字列で指定された名前のグループに属するサービスのみです。このパラメーターが空文字列の場合、いずれのグループにも属さないサービスのみが列挙されます。このパラメーターが NULL の場合、グループメンバーシップは無視され、すべてのサービスが列挙されます。 |
戻り値の型: BOOL
公式ドキュメント
指定したサービス制御マネージャーデータベース内のサービスを列挙します。各サービスの名前と状態に加え、指定した情報レベルに基づく追加データが返されます。(ANSI)
戻り値
関数が成功すると、戻り値は 0 以外になります。
関数が失敗すると、戻り値は 0 になります。拡張エラー情報を取得するには、 GetLastError を呼び出します。次のエラーが返される場合があります。
| Return code | Description |
|---|---|
| ハンドルが SC_MANAGER_ENUMERATE_SERVICE アクセス権を持っていません。 | |
| バッファーが小さすぎます。アクティブなデータベース内のすべてのデータを返すことができませんでした。pcbBytesNeeded パラメーターには、残りのエントリを受け取るために必要なバイト数が格納されます。 | |
| 不正なパラメーター値が使用されました。 | |
| ハンドルが無効です。 | |
| InfoLevel パラメーターにサポートされていない値が含まれています。 | |
| システムをシャットダウン中です。この関数は呼び出せません。 |
解説(Remarks)
呼び出し元があるサービスに対して SERVICE_QUERY_STATUS アクセス権を持っていない場合、そのサービスはクライアントに返されるサービスの一覧から黙って除外されます。
winsvc.h ヘッダーは EnumServicesStatusEx を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不整合が生じる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
BOOL EnumServicesStatusExA(
SC_HANDLE hSCManager,
SC_ENUM_TYPE InfoLevel,
ENUM_SERVICE_TYPE dwServiceType,
ENUM_SERVICE_STATE dwServiceState,
BYTE* lpServices, // optional
DWORD cbBufSize,
DWORD* pcbBytesNeeded,
DWORD* lpServicesReturned,
DWORD* lpResumeHandle, // optional
LPCSTR pszGroupName // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool EnumServicesStatusExA(
IntPtr hSCManager, // SC_HANDLE
int InfoLevel, // SC_ENUM_TYPE
uint dwServiceType, // ENUM_SERVICE_TYPE
uint dwServiceState, // ENUM_SERVICE_STATE
IntPtr lpServices, // BYTE* optional, out
uint cbBufSize, // DWORD
out uint pcbBytesNeeded, // DWORD* out
out uint lpServicesReturned, // DWORD* out
IntPtr lpResumeHandle, // DWORD* optional, in/out
[MarshalAs(UnmanagedType.LPStr)] string pszGroupName // LPCSTR optional
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function EnumServicesStatusExA(
hSCManager As IntPtr, ' SC_HANDLE
InfoLevel As Integer, ' SC_ENUM_TYPE
dwServiceType As UInteger, ' ENUM_SERVICE_TYPE
dwServiceState As UInteger, ' ENUM_SERVICE_STATE
lpServices As IntPtr, ' BYTE* optional, out
cbBufSize As UInteger, ' DWORD
<Out> ByRef pcbBytesNeeded As UInteger, ' DWORD* out
<Out> ByRef lpServicesReturned As UInteger, ' DWORD* out
lpResumeHandle As IntPtr, ' DWORD* optional, in/out
<MarshalAs(UnmanagedType.LPStr)> pszGroupName As String ' LPCSTR optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hSCManager : SC_HANDLE
' InfoLevel : SC_ENUM_TYPE
' dwServiceType : ENUM_SERVICE_TYPE
' dwServiceState : ENUM_SERVICE_STATE
' lpServices : BYTE* optional, out
' cbBufSize : DWORD
' pcbBytesNeeded : DWORD* out
' lpServicesReturned : DWORD* out
' lpResumeHandle : DWORD* optional, in/out
' pszGroupName : LPCSTR optional
Declare PtrSafe Function EnumServicesStatusExA Lib "advapi32" ( _
ByVal hSCManager As LongPtr, _
ByVal InfoLevel As Long, _
ByVal dwServiceType As Long, _
ByVal dwServiceState As Long, _
ByVal lpServices As LongPtr, _
ByVal cbBufSize As Long, _
ByRef pcbBytesNeeded As Long, _
ByRef lpServicesReturned As Long, _
ByVal lpResumeHandle As LongPtr, _
ByVal pszGroupName As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
EnumServicesStatusExA = ctypes.windll.advapi32.EnumServicesStatusExA
EnumServicesStatusExA.restype = wintypes.BOOL
EnumServicesStatusExA.argtypes = [
wintypes.HANDLE, # hSCManager : SC_HANDLE
ctypes.c_int, # InfoLevel : SC_ENUM_TYPE
wintypes.DWORD, # dwServiceType : ENUM_SERVICE_TYPE
wintypes.DWORD, # dwServiceState : ENUM_SERVICE_STATE
ctypes.POINTER(ctypes.c_ubyte), # lpServices : BYTE* optional, out
wintypes.DWORD, # cbBufSize : DWORD
ctypes.POINTER(wintypes.DWORD), # pcbBytesNeeded : DWORD* out
ctypes.POINTER(wintypes.DWORD), # lpServicesReturned : DWORD* out
ctypes.POINTER(wintypes.DWORD), # lpResumeHandle : DWORD* optional, in/out
wintypes.LPCSTR, # pszGroupName : LPCSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
EnumServicesStatusExA = Fiddle::Function.new(
lib['EnumServicesStatusExA'],
[
Fiddle::TYPE_VOIDP, # hSCManager : SC_HANDLE
Fiddle::TYPE_INT, # InfoLevel : SC_ENUM_TYPE
-Fiddle::TYPE_INT, # dwServiceType : ENUM_SERVICE_TYPE
-Fiddle::TYPE_INT, # dwServiceState : ENUM_SERVICE_STATE
Fiddle::TYPE_VOIDP, # lpServices : BYTE* optional, out
-Fiddle::TYPE_INT, # cbBufSize : DWORD
Fiddle::TYPE_VOIDP, # pcbBytesNeeded : DWORD* out
Fiddle::TYPE_VOIDP, # lpServicesReturned : DWORD* out
Fiddle::TYPE_VOIDP, # lpResumeHandle : DWORD* optional, in/out
Fiddle::TYPE_VOIDP, # pszGroupName : LPCSTR optional
],
Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn EnumServicesStatusExA(
hSCManager: *mut core::ffi::c_void, // SC_HANDLE
InfoLevel: i32, // SC_ENUM_TYPE
dwServiceType: u32, // ENUM_SERVICE_TYPE
dwServiceState: u32, // ENUM_SERVICE_STATE
lpServices: *mut u8, // BYTE* optional, out
cbBufSize: u32, // DWORD
pcbBytesNeeded: *mut u32, // DWORD* out
lpServicesReturned: *mut u32, // DWORD* out
lpResumeHandle: *mut u32, // DWORD* optional, in/out
pszGroupName: *const u8 // LPCSTR optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool EnumServicesStatusExA(IntPtr hSCManager, int InfoLevel, uint dwServiceType, uint dwServiceState, IntPtr lpServices, uint cbBufSize, out uint pcbBytesNeeded, out uint lpServicesReturned, IntPtr lpResumeHandle, [MarshalAs(UnmanagedType.LPStr)] string pszGroupName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_EnumServicesStatusExA' -Namespace Win32 -PassThru
# $api::EnumServicesStatusExA(hSCManager, InfoLevel, dwServiceType, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, pszGroupName)#uselib "ADVAPI32.dll"
#func global EnumServicesStatusExA "EnumServicesStatusExA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; EnumServicesStatusExA hSCManager, InfoLevel, dwServiceType, dwServiceState, varptr(lpServices), cbBufSize, varptr(pcbBytesNeeded), varptr(lpServicesReturned), varptr(lpResumeHandle), pszGroupName ; 戻り値は stat
; hSCManager : SC_HANDLE -> "sptr"
; InfoLevel : SC_ENUM_TYPE -> "sptr"
; dwServiceType : ENUM_SERVICE_TYPE -> "sptr"
; dwServiceState : ENUM_SERVICE_STATE -> "sptr"
; lpServices : BYTE* optional, out -> "sptr"
; cbBufSize : DWORD -> "sptr"
; pcbBytesNeeded : DWORD* out -> "sptr"
; lpServicesReturned : DWORD* out -> "sptr"
; lpResumeHandle : DWORD* optional, in/out -> "sptr"
; pszGroupName : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll" #cfunc global EnumServicesStatusExA "EnumServicesStatusExA" sptr, int, int, int, var, int, var, var, var, str ; res = EnumServicesStatusExA(hSCManager, InfoLevel, dwServiceType, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, pszGroupName) ; hSCManager : SC_HANDLE -> "sptr" ; InfoLevel : SC_ENUM_TYPE -> "int" ; dwServiceType : ENUM_SERVICE_TYPE -> "int" ; dwServiceState : ENUM_SERVICE_STATE -> "int" ; lpServices : BYTE* optional, out -> "var" ; cbBufSize : DWORD -> "int" ; pcbBytesNeeded : DWORD* out -> "var" ; lpServicesReturned : DWORD* out -> "var" ; lpResumeHandle : DWORD* optional, in/out -> "var" ; pszGroupName : LPCSTR optional -> "str" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global EnumServicesStatusExA "EnumServicesStatusExA" sptr, int, int, int, sptr, int, sptr, sptr, sptr, str ; res = EnumServicesStatusExA(hSCManager, InfoLevel, dwServiceType, dwServiceState, varptr(lpServices), cbBufSize, varptr(pcbBytesNeeded), varptr(lpServicesReturned), varptr(lpResumeHandle), pszGroupName) ; hSCManager : SC_HANDLE -> "sptr" ; InfoLevel : SC_ENUM_TYPE -> "int" ; dwServiceType : ENUM_SERVICE_TYPE -> "int" ; dwServiceState : ENUM_SERVICE_STATE -> "int" ; lpServices : BYTE* optional, out -> "sptr" ; cbBufSize : DWORD -> "int" ; pcbBytesNeeded : DWORD* out -> "sptr" ; lpServicesReturned : DWORD* out -> "sptr" ; lpResumeHandle : DWORD* optional, in/out -> "sptr" ; pszGroupName : LPCSTR optional -> "str" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL EnumServicesStatusExA(SC_HANDLE hSCManager, SC_ENUM_TYPE InfoLevel, ENUM_SERVICE_TYPE dwServiceType, ENUM_SERVICE_STATE dwServiceState, BYTE* lpServices, DWORD cbBufSize, DWORD* pcbBytesNeeded, DWORD* lpServicesReturned, DWORD* lpResumeHandle, LPCSTR pszGroupName) #uselib "ADVAPI32.dll" #cfunc global EnumServicesStatusExA "EnumServicesStatusExA" intptr, int, int, int, var, int, var, var, var, str ; res = EnumServicesStatusExA(hSCManager, InfoLevel, dwServiceType, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, pszGroupName) ; hSCManager : SC_HANDLE -> "intptr" ; InfoLevel : SC_ENUM_TYPE -> "int" ; dwServiceType : ENUM_SERVICE_TYPE -> "int" ; dwServiceState : ENUM_SERVICE_STATE -> "int" ; lpServices : BYTE* optional, out -> "var" ; cbBufSize : DWORD -> "int" ; pcbBytesNeeded : DWORD* out -> "var" ; lpServicesReturned : DWORD* out -> "var" ; lpResumeHandle : DWORD* optional, in/out -> "var" ; pszGroupName : LPCSTR optional -> "str" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL EnumServicesStatusExA(SC_HANDLE hSCManager, SC_ENUM_TYPE InfoLevel, ENUM_SERVICE_TYPE dwServiceType, ENUM_SERVICE_STATE dwServiceState, BYTE* lpServices, DWORD cbBufSize, DWORD* pcbBytesNeeded, DWORD* lpServicesReturned, DWORD* lpResumeHandle, LPCSTR pszGroupName) #uselib "ADVAPI32.dll" #cfunc global EnumServicesStatusExA "EnumServicesStatusExA" intptr, int, int, int, intptr, int, intptr, intptr, intptr, str ; res = EnumServicesStatusExA(hSCManager, InfoLevel, dwServiceType, dwServiceState, varptr(lpServices), cbBufSize, varptr(pcbBytesNeeded), varptr(lpServicesReturned), varptr(lpResumeHandle), pszGroupName) ; hSCManager : SC_HANDLE -> "intptr" ; InfoLevel : SC_ENUM_TYPE -> "int" ; dwServiceType : ENUM_SERVICE_TYPE -> "int" ; dwServiceState : ENUM_SERVICE_STATE -> "int" ; lpServices : BYTE* optional, out -> "intptr" ; cbBufSize : DWORD -> "int" ; pcbBytesNeeded : DWORD* out -> "intptr" ; lpServicesReturned : DWORD* out -> "intptr" ; lpResumeHandle : DWORD* optional, in/out -> "intptr" ; pszGroupName : LPCSTR optional -> "str" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procEnumServicesStatusExA = advapi32.NewProc("EnumServicesStatusExA")
)
// hSCManager (SC_HANDLE), InfoLevel (SC_ENUM_TYPE), dwServiceType (ENUM_SERVICE_TYPE), dwServiceState (ENUM_SERVICE_STATE), lpServices (BYTE* optional, out), cbBufSize (DWORD), pcbBytesNeeded (DWORD* out), lpServicesReturned (DWORD* out), lpResumeHandle (DWORD* optional, in/out), pszGroupName (LPCSTR optional)
r1, _, err := procEnumServicesStatusExA.Call(
uintptr(hSCManager),
uintptr(InfoLevel),
uintptr(dwServiceType),
uintptr(dwServiceState),
uintptr(lpServices),
uintptr(cbBufSize),
uintptr(pcbBytesNeeded),
uintptr(lpServicesReturned),
uintptr(lpResumeHandle),
uintptr(unsafe.Pointer(windows.BytePtrFromString(pszGroupName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction EnumServicesStatusExA(
hSCManager: THandle; // SC_HANDLE
InfoLevel: Integer; // SC_ENUM_TYPE
dwServiceType: DWORD; // ENUM_SERVICE_TYPE
dwServiceState: DWORD; // ENUM_SERVICE_STATE
lpServices: Pointer; // BYTE* optional, out
cbBufSize: DWORD; // DWORD
pcbBytesNeeded: Pointer; // DWORD* out
lpServicesReturned: Pointer; // DWORD* out
lpResumeHandle: Pointer; // DWORD* optional, in/out
pszGroupName: PAnsiChar // LPCSTR optional
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'EnumServicesStatusExA';result := DllCall("ADVAPI32\EnumServicesStatusExA"
, "Ptr", hSCManager ; SC_HANDLE
, "Int", InfoLevel ; SC_ENUM_TYPE
, "UInt", dwServiceType ; ENUM_SERVICE_TYPE
, "UInt", dwServiceState ; ENUM_SERVICE_STATE
, "Ptr", lpServices ; BYTE* optional, out
, "UInt", cbBufSize ; DWORD
, "Ptr", pcbBytesNeeded ; DWORD* out
, "Ptr", lpServicesReturned ; DWORD* out
, "Ptr", lpResumeHandle ; DWORD* optional, in/out
, "AStr", pszGroupName ; LPCSTR optional
, "Int") ; return: BOOL●EnumServicesStatusExA(hSCManager, InfoLevel, dwServiceType, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, pszGroupName) = DLL("ADVAPI32.dll", "bool EnumServicesStatusExA(void*, int, dword, dword, void*, dword, void*, void*, void*, char*)")
# 呼び出し: EnumServicesStatusExA(hSCManager, InfoLevel, dwServiceType, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, pszGroupName)
# hSCManager : SC_HANDLE -> "void*"
# InfoLevel : SC_ENUM_TYPE -> "int"
# dwServiceType : ENUM_SERVICE_TYPE -> "dword"
# dwServiceState : ENUM_SERVICE_STATE -> "dword"
# lpServices : BYTE* optional, out -> "void*"
# cbBufSize : DWORD -> "dword"
# pcbBytesNeeded : DWORD* out -> "void*"
# lpServicesReturned : DWORD* out -> "void*"
# lpResumeHandle : DWORD* optional, in/out -> "void*"
# pszGroupName : LPCSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "advapi32" fn EnumServicesStatusExA(
hSCManager: ?*anyopaque, // SC_HANDLE
InfoLevel: i32, // SC_ENUM_TYPE
dwServiceType: u32, // ENUM_SERVICE_TYPE
dwServiceState: u32, // ENUM_SERVICE_STATE
lpServices: [*c]u8, // BYTE* optional, out
cbBufSize: u32, // DWORD
pcbBytesNeeded: [*c]u32, // DWORD* out
lpServicesReturned: [*c]u32, // DWORD* out
lpResumeHandle: [*c]u32, // DWORD* optional, in/out
pszGroupName: [*c]const u8 // LPCSTR optional
) callconv(std.os.windows.WINAPI) i32;proc EnumServicesStatusExA(
hSCManager: pointer, # SC_HANDLE
InfoLevel: int32, # SC_ENUM_TYPE
dwServiceType: uint32, # ENUM_SERVICE_TYPE
dwServiceState: uint32, # ENUM_SERVICE_STATE
lpServices: ptr uint8, # BYTE* optional, out
cbBufSize: uint32, # DWORD
pcbBytesNeeded: ptr uint32, # DWORD* out
lpServicesReturned: ptr uint32, # DWORD* out
lpResumeHandle: ptr uint32, # DWORD* optional, in/out
pszGroupName: cstring # LPCSTR optional
): int32 {.importc: "EnumServicesStatusExA", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
int EnumServicesStatusExA(
void* hSCManager, // SC_HANDLE
int InfoLevel, // SC_ENUM_TYPE
uint dwServiceType, // ENUM_SERVICE_TYPE
uint dwServiceState, // ENUM_SERVICE_STATE
ubyte* lpServices, // BYTE* optional, out
uint cbBufSize, // DWORD
uint* pcbBytesNeeded, // DWORD* out
uint* lpServicesReturned, // DWORD* out
uint* lpResumeHandle, // DWORD* optional, in/out
const(char)* pszGroupName // LPCSTR optional
);ccall((:EnumServicesStatusExA, "ADVAPI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32, UInt32, UInt32, Ptr{UInt8}, UInt32, Ptr{UInt32}, Ptr{UInt32}, Ptr{UInt32}, Cstring),
hSCManager, InfoLevel, dwServiceType, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, pszGroupName)
# hSCManager : SC_HANDLE -> Ptr{Cvoid}
# InfoLevel : SC_ENUM_TYPE -> Int32
# dwServiceType : ENUM_SERVICE_TYPE -> UInt32
# dwServiceState : ENUM_SERVICE_STATE -> UInt32
# lpServices : BYTE* optional, out -> Ptr{UInt8}
# cbBufSize : DWORD -> UInt32
# pcbBytesNeeded : DWORD* out -> Ptr{UInt32}
# lpServicesReturned : DWORD* out -> Ptr{UInt32}
# lpResumeHandle : DWORD* optional, in/out -> Ptr{UInt32}
# pszGroupName : LPCSTR optional -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t EnumServicesStatusExA(
void* hSCManager,
int32_t InfoLevel,
uint32_t dwServiceType,
uint32_t dwServiceState,
uint8_t* lpServices,
uint32_t cbBufSize,
uint32_t* pcbBytesNeeded,
uint32_t* lpServicesReturned,
uint32_t* lpResumeHandle,
const char* pszGroupName);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.EnumServicesStatusExA(hSCManager, InfoLevel, dwServiceType, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, pszGroupName)
-- hSCManager : SC_HANDLE
-- InfoLevel : SC_ENUM_TYPE
-- dwServiceType : ENUM_SERVICE_TYPE
-- dwServiceState : ENUM_SERVICE_STATE
-- lpServices : BYTE* optional, out
-- cbBufSize : DWORD
-- pcbBytesNeeded : DWORD* out
-- lpServicesReturned : DWORD* out
-- lpResumeHandle : DWORD* optional, in/out
-- pszGroupName : LPCSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const EnumServicesStatusExA = lib.func('__stdcall', 'EnumServicesStatusExA', 'int32_t', ['void *', 'int32_t', 'uint32_t', 'uint32_t', 'uint8_t *', 'uint32_t', 'uint32_t *', 'uint32_t *', 'uint32_t *', 'str']);
// EnumServicesStatusExA(hSCManager, InfoLevel, dwServiceType, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, pszGroupName)
// hSCManager : SC_HANDLE -> 'void *'
// InfoLevel : SC_ENUM_TYPE -> 'int32_t'
// dwServiceType : ENUM_SERVICE_TYPE -> 'uint32_t'
// dwServiceState : ENUM_SERVICE_STATE -> 'uint32_t'
// lpServices : BYTE* optional, out -> 'uint8_t *'
// cbBufSize : DWORD -> 'uint32_t'
// pcbBytesNeeded : DWORD* out -> 'uint32_t *'
// lpServicesReturned : DWORD* out -> 'uint32_t *'
// lpResumeHandle : DWORD* optional, in/out -> 'uint32_t *'
// pszGroupName : LPCSTR optional -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
EnumServicesStatusExA: { parameters: ["pointer", "i32", "u32", "u32", "pointer", "u32", "pointer", "pointer", "pointer", "buffer"], result: "i32" },
});
// lib.symbols.EnumServicesStatusExA(hSCManager, InfoLevel, dwServiceType, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, pszGroupName)
// hSCManager : SC_HANDLE -> "pointer"
// InfoLevel : SC_ENUM_TYPE -> "i32"
// dwServiceType : ENUM_SERVICE_TYPE -> "u32"
// dwServiceState : ENUM_SERVICE_STATE -> "u32"
// lpServices : BYTE* optional, out -> "pointer"
// cbBufSize : DWORD -> "u32"
// pcbBytesNeeded : DWORD* out -> "pointer"
// lpServicesReturned : DWORD* out -> "pointer"
// lpResumeHandle : DWORD* optional, in/out -> "pointer"
// pszGroupName : LPCSTR optional -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t EnumServicesStatusExA(
void* hSCManager,
int32_t InfoLevel,
uint32_t dwServiceType,
uint32_t dwServiceState,
uint8_t* lpServices,
uint32_t cbBufSize,
uint32_t* pcbBytesNeeded,
uint32_t* lpServicesReturned,
uint32_t* lpResumeHandle,
const char* pszGroupName);
C, "ADVAPI32.dll");
// $ffi->EnumServicesStatusExA(hSCManager, InfoLevel, dwServiceType, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, pszGroupName);
// hSCManager : SC_HANDLE
// InfoLevel : SC_ENUM_TYPE
// dwServiceType : ENUM_SERVICE_TYPE
// dwServiceState : ENUM_SERVICE_STATE
// lpServices : BYTE* optional, out
// cbBufSize : DWORD
// pcbBytesNeeded : DWORD* out
// lpServicesReturned : DWORD* out
// lpResumeHandle : DWORD* optional, in/out
// pszGroupName : LPCSTR optional
// 構造体/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 Advapi32 extends StdCallLibrary {
Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class, W32APIOptions.ASCII_OPTIONS);
boolean EnumServicesStatusExA(
Pointer hSCManager, // SC_HANDLE
int InfoLevel, // SC_ENUM_TYPE
int dwServiceType, // ENUM_SERVICE_TYPE
int dwServiceState, // ENUM_SERVICE_STATE
byte[] lpServices, // BYTE* optional, out
int cbBufSize, // DWORD
IntByReference pcbBytesNeeded, // DWORD* out
IntByReference lpServicesReturned, // DWORD* out
IntByReference lpResumeHandle, // DWORD* optional, in/out
String pszGroupName // LPCSTR optional
);
}@[Link("advapi32")]
lib LibADVAPI32
fun EnumServicesStatusExA = EnumServicesStatusExA(
hSCManager : Void*, # SC_HANDLE
InfoLevel : Int32, # SC_ENUM_TYPE
dwServiceType : UInt32, # ENUM_SERVICE_TYPE
dwServiceState : UInt32, # ENUM_SERVICE_STATE
lpServices : UInt8*, # BYTE* optional, out
cbBufSize : UInt32, # DWORD
pcbBytesNeeded : UInt32*, # DWORD* out
lpServicesReturned : UInt32*, # DWORD* out
lpResumeHandle : UInt32*, # DWORD* optional, in/out
pszGroupName : UInt8* # LPCSTR optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef EnumServicesStatusExANative = Int32 Function(Pointer<Void>, Int32, Uint32, Uint32, Pointer<Uint8>, Uint32, Pointer<Uint32>, Pointer<Uint32>, Pointer<Uint32>, Pointer<Utf8>);
typedef EnumServicesStatusExADart = int Function(Pointer<Void>, int, int, int, Pointer<Uint8>, int, Pointer<Uint32>, Pointer<Uint32>, Pointer<Uint32>, Pointer<Utf8>);
final EnumServicesStatusExA = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<EnumServicesStatusExANative, EnumServicesStatusExADart>('EnumServicesStatusExA');
// hSCManager : SC_HANDLE -> Pointer<Void>
// InfoLevel : SC_ENUM_TYPE -> Int32
// dwServiceType : ENUM_SERVICE_TYPE -> Uint32
// dwServiceState : ENUM_SERVICE_STATE -> Uint32
// lpServices : BYTE* optional, out -> Pointer<Uint8>
// cbBufSize : DWORD -> Uint32
// pcbBytesNeeded : DWORD* out -> Pointer<Uint32>
// lpServicesReturned : DWORD* out -> Pointer<Uint32>
// lpResumeHandle : DWORD* optional, in/out -> Pointer<Uint32>
// pszGroupName : LPCSTR optional -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function EnumServicesStatusExA(
hSCManager: THandle; // SC_HANDLE
InfoLevel: Integer; // SC_ENUM_TYPE
dwServiceType: DWORD; // ENUM_SERVICE_TYPE
dwServiceState: DWORD; // ENUM_SERVICE_STATE
lpServices: Pointer; // BYTE* optional, out
cbBufSize: DWORD; // DWORD
pcbBytesNeeded: Pointer; // DWORD* out
lpServicesReturned: Pointer; // DWORD* out
lpResumeHandle: Pointer; // DWORD* optional, in/out
pszGroupName: PAnsiChar // LPCSTR optional
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'EnumServicesStatusExA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "EnumServicesStatusExA"
c_EnumServicesStatusExA :: Ptr () -> Int32 -> Word32 -> Word32 -> Ptr Word8 -> Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> CString -> IO CInt
-- hSCManager : SC_HANDLE -> Ptr ()
-- InfoLevel : SC_ENUM_TYPE -> Int32
-- dwServiceType : ENUM_SERVICE_TYPE -> Word32
-- dwServiceState : ENUM_SERVICE_STATE -> Word32
-- lpServices : BYTE* optional, out -> Ptr Word8
-- cbBufSize : DWORD -> Word32
-- pcbBytesNeeded : DWORD* out -> Ptr Word32
-- lpServicesReturned : DWORD* out -> Ptr Word32
-- lpResumeHandle : DWORD* optional, in/out -> Ptr Word32
-- pszGroupName : LPCSTR optional -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let enumservicesstatusexa =
foreign "EnumServicesStatusExA"
((ptr void) @-> int32_t @-> uint32_t @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint32_t) @-> (ptr uint32_t) @-> (ptr uint32_t) @-> string @-> returning int32_t)
(* hSCManager : SC_HANDLE -> (ptr void) *)
(* InfoLevel : SC_ENUM_TYPE -> int32_t *)
(* dwServiceType : ENUM_SERVICE_TYPE -> uint32_t *)
(* dwServiceState : ENUM_SERVICE_STATE -> uint32_t *)
(* lpServices : BYTE* optional, out -> (ptr uint8_t) *)
(* cbBufSize : DWORD -> uint32_t *)
(* pcbBytesNeeded : DWORD* out -> (ptr uint32_t) *)
(* lpServicesReturned : DWORD* out -> (ptr uint32_t) *)
(* lpResumeHandle : DWORD* optional, in/out -> (ptr uint32_t) *)
(* pszGroupName : LPCSTR optional -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("EnumServicesStatusExA" enum-services-status-ex-a :convention :stdcall) :int32
(h-scmanager :pointer) ; SC_HANDLE
(info-level :int32) ; SC_ENUM_TYPE
(dw-service-type :uint32) ; ENUM_SERVICE_TYPE
(dw-service-state :uint32) ; ENUM_SERVICE_STATE
(lp-services :pointer) ; BYTE* optional, out
(cb-buf-size :uint32) ; DWORD
(pcb-bytes-needed :pointer) ; DWORD* out
(lp-services-returned :pointer) ; DWORD* out
(lp-resume-handle :pointer) ; DWORD* optional, in/out
(psz-group-name :string)) ; LPCSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $EnumServicesStatusExA = Win32::API::More->new('ADVAPI32',
'BOOL EnumServicesStatusExA(HANDLE hSCManager, int InfoLevel, DWORD dwServiceType, DWORD dwServiceState, LPVOID lpServices, DWORD cbBufSize, LPVOID pcbBytesNeeded, LPVOID lpServicesReturned, LPVOID lpResumeHandle, LPCSTR pszGroupName)');
# my $ret = $EnumServicesStatusExA->Call($hSCManager, $InfoLevel, $dwServiceType, $dwServiceState, $lpServices, $cbBufSize, $pcbBytesNeeded, $lpServicesReturned, $lpResumeHandle, $pszGroupName);
# hSCManager : SC_HANDLE -> HANDLE
# InfoLevel : SC_ENUM_TYPE -> int
# dwServiceType : ENUM_SERVICE_TYPE -> DWORD
# dwServiceState : ENUM_SERVICE_STATE -> DWORD
# lpServices : BYTE* optional, out -> LPVOID
# cbBufSize : DWORD -> DWORD
# pcbBytesNeeded : DWORD* out -> LPVOID
# lpServicesReturned : DWORD* out -> LPVOID
# lpResumeHandle : DWORD* optional, in/out -> LPVOID
# pszGroupName : LPCSTR optional -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f EnumServicesStatusExW (Unicode版) — サービスとその状態を種類や状態で絞って列挙する。
- f EnumServicesStatusA — SCM内のサービスとその状態を列挙する。