ホーム › System.Services › QueryServiceObjectSecurity
QueryServiceObjectSecurity
関数サービスのセキュリティ記述子を取得する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
BOOL QueryServiceObjectSecurity(
SC_HANDLE hService,
DWORD dwSecurityInformation,
PSECURITY_DESCRIPTOR lpSecurityDescriptor, // optional
DWORD cbBufSize,
DWORD* pcbBytesNeeded
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hService | SC_HANDLE | in |
| dwSecurityInformation | DWORD | in |
| lpSecurityDescriptor | PSECURITY_DESCRIPTOR | outoptional |
| cbBufSize | DWORD | in |
| pcbBytesNeeded | DWORD* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// ADVAPI32.dll
#include <windows.h>
BOOL QueryServiceObjectSecurity(
SC_HANDLE hService,
DWORD dwSecurityInformation,
PSECURITY_DESCRIPTOR lpSecurityDescriptor, // optional
DWORD cbBufSize,
DWORD* pcbBytesNeeded
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool QueryServiceObjectSecurity(
IntPtr hService, // SC_HANDLE
uint dwSecurityInformation, // DWORD
IntPtr lpSecurityDescriptor, // PSECURITY_DESCRIPTOR optional, out
uint cbBufSize, // DWORD
out uint pcbBytesNeeded // DWORD* out
);<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function QueryServiceObjectSecurity(
hService As IntPtr, ' SC_HANDLE
dwSecurityInformation As UInteger, ' DWORD
lpSecurityDescriptor As IntPtr, ' PSECURITY_DESCRIPTOR optional, out
cbBufSize As UInteger, ' DWORD
<Out> ByRef pcbBytesNeeded As UInteger ' DWORD* out
) As Boolean
End Function' hService : SC_HANDLE
' dwSecurityInformation : DWORD
' lpSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out
' cbBufSize : DWORD
' pcbBytesNeeded : DWORD* out
Declare PtrSafe Function QueryServiceObjectSecurity Lib "advapi32" ( _
ByVal hService As LongPtr, _
ByVal dwSecurityInformation As Long, _
ByVal lpSecurityDescriptor As LongPtr, _
ByVal cbBufSize As Long, _
ByRef pcbBytesNeeded As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
QueryServiceObjectSecurity = ctypes.windll.advapi32.QueryServiceObjectSecurity
QueryServiceObjectSecurity.restype = wintypes.BOOL
QueryServiceObjectSecurity.argtypes = [
wintypes.HANDLE, # hService : SC_HANDLE
wintypes.DWORD, # dwSecurityInformation : DWORD
wintypes.HANDLE, # lpSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out
wintypes.DWORD, # cbBufSize : DWORD
ctypes.POINTER(wintypes.DWORD), # pcbBytesNeeded : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
QueryServiceObjectSecurity = Fiddle::Function.new(
lib['QueryServiceObjectSecurity'],
[
Fiddle::TYPE_VOIDP, # hService : SC_HANDLE
-Fiddle::TYPE_INT, # dwSecurityInformation : DWORD
Fiddle::TYPE_VOIDP, # lpSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out
-Fiddle::TYPE_INT, # cbBufSize : DWORD
Fiddle::TYPE_VOIDP, # pcbBytesNeeded : DWORD* out
],
Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn QueryServiceObjectSecurity(
hService: *mut core::ffi::c_void, // SC_HANDLE
dwSecurityInformation: u32, // DWORD
lpSecurityDescriptor: *mut core::ffi::c_void, // PSECURITY_DESCRIPTOR optional, out
cbBufSize: u32, // DWORD
pcbBytesNeeded: *mut u32 // DWORD* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true)]
public static extern bool QueryServiceObjectSecurity(IntPtr hService, uint dwSecurityInformation, IntPtr lpSecurityDescriptor, uint cbBufSize, out uint pcbBytesNeeded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_QueryServiceObjectSecurity' -Namespace Win32 -PassThru
# $api::QueryServiceObjectSecurity(hService, dwSecurityInformation, lpSecurityDescriptor, cbBufSize, pcbBytesNeeded)#uselib "ADVAPI32.dll"
#func global QueryServiceObjectSecurity "QueryServiceObjectSecurity" sptr, sptr, sptr, sptr, sptr
; QueryServiceObjectSecurity hService, dwSecurityInformation, lpSecurityDescriptor, cbBufSize, varptr(pcbBytesNeeded) ; 戻り値は stat
; hService : SC_HANDLE -> "sptr"
; dwSecurityInformation : DWORD -> "sptr"
; lpSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "sptr"
; cbBufSize : DWORD -> "sptr"
; pcbBytesNeeded : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ADVAPI32.dll" #cfunc global QueryServiceObjectSecurity "QueryServiceObjectSecurity" sptr, int, sptr, int, var ; res = QueryServiceObjectSecurity(hService, dwSecurityInformation, lpSecurityDescriptor, cbBufSize, pcbBytesNeeded) ; hService : SC_HANDLE -> "sptr" ; dwSecurityInformation : DWORD -> "int" ; lpSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "sptr" ; cbBufSize : DWORD -> "int" ; pcbBytesNeeded : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global QueryServiceObjectSecurity "QueryServiceObjectSecurity" sptr, int, sptr, int, sptr ; res = QueryServiceObjectSecurity(hService, dwSecurityInformation, lpSecurityDescriptor, cbBufSize, varptr(pcbBytesNeeded)) ; hService : SC_HANDLE -> "sptr" ; dwSecurityInformation : DWORD -> "int" ; lpSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "sptr" ; cbBufSize : DWORD -> "int" ; pcbBytesNeeded : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL QueryServiceObjectSecurity(SC_HANDLE hService, DWORD dwSecurityInformation, PSECURITY_DESCRIPTOR lpSecurityDescriptor, DWORD cbBufSize, DWORD* pcbBytesNeeded) #uselib "ADVAPI32.dll" #cfunc global QueryServiceObjectSecurity "QueryServiceObjectSecurity" intptr, int, intptr, int, var ; res = QueryServiceObjectSecurity(hService, dwSecurityInformation, lpSecurityDescriptor, cbBufSize, pcbBytesNeeded) ; hService : SC_HANDLE -> "intptr" ; dwSecurityInformation : DWORD -> "int" ; lpSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "intptr" ; cbBufSize : DWORD -> "int" ; pcbBytesNeeded : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL QueryServiceObjectSecurity(SC_HANDLE hService, DWORD dwSecurityInformation, PSECURITY_DESCRIPTOR lpSecurityDescriptor, DWORD cbBufSize, DWORD* pcbBytesNeeded) #uselib "ADVAPI32.dll" #cfunc global QueryServiceObjectSecurity "QueryServiceObjectSecurity" intptr, int, intptr, int, intptr ; res = QueryServiceObjectSecurity(hService, dwSecurityInformation, lpSecurityDescriptor, cbBufSize, varptr(pcbBytesNeeded)) ; hService : SC_HANDLE -> "intptr" ; dwSecurityInformation : DWORD -> "int" ; lpSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "intptr" ; cbBufSize : DWORD -> "int" ; pcbBytesNeeded : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procQueryServiceObjectSecurity = advapi32.NewProc("QueryServiceObjectSecurity")
)
// hService (SC_HANDLE), dwSecurityInformation (DWORD), lpSecurityDescriptor (PSECURITY_DESCRIPTOR optional, out), cbBufSize (DWORD), pcbBytesNeeded (DWORD* out)
r1, _, err := procQueryServiceObjectSecurity.Call(
uintptr(hService),
uintptr(dwSecurityInformation),
uintptr(lpSecurityDescriptor),
uintptr(cbBufSize),
uintptr(pcbBytesNeeded),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction QueryServiceObjectSecurity(
hService: THandle; // SC_HANDLE
dwSecurityInformation: DWORD; // DWORD
lpSecurityDescriptor: THandle; // PSECURITY_DESCRIPTOR optional, out
cbBufSize: DWORD; // DWORD
pcbBytesNeeded: Pointer // DWORD* out
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'QueryServiceObjectSecurity';result := DllCall("ADVAPI32\QueryServiceObjectSecurity"
, "Ptr", hService ; SC_HANDLE
, "UInt", dwSecurityInformation ; DWORD
, "Ptr", lpSecurityDescriptor ; PSECURITY_DESCRIPTOR optional, out
, "UInt", cbBufSize ; DWORD
, "Ptr", pcbBytesNeeded ; DWORD* out
, "Int") ; return: BOOL●QueryServiceObjectSecurity(hService, dwSecurityInformation, lpSecurityDescriptor, cbBufSize, pcbBytesNeeded) = DLL("ADVAPI32.dll", "bool QueryServiceObjectSecurity(void*, dword, void*, dword, void*)")
# 呼び出し: QueryServiceObjectSecurity(hService, dwSecurityInformation, lpSecurityDescriptor, cbBufSize, pcbBytesNeeded)
# hService : SC_HANDLE -> "void*"
# dwSecurityInformation : DWORD -> "dword"
# lpSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "void*"
# cbBufSize : DWORD -> "dword"
# pcbBytesNeeded : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。