LookupPrivilegeValueW
関数特権名からローカル一意識別子LUIDを取得する(Unicode版)。
シグネチャ
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
BOOL LookupPrivilegeValueW(
LPCWSTR lpSystemName, // optional
LPCWSTR lpName,
LUID* lpLuid
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpSystemName | LPCWSTR | inoptional |
| lpName | LPCWSTR | in |
| lpLuid | LUID* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
BOOL LookupPrivilegeValueW(
LPCWSTR lpSystemName, // optional
LPCWSTR lpName,
LUID* lpLuid
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool LookupPrivilegeValueW(
[MarshalAs(UnmanagedType.LPWStr)] string lpSystemName, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string lpName, // LPCWSTR
IntPtr lpLuid // LUID* out
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function LookupPrivilegeValueW(
<MarshalAs(UnmanagedType.LPWStr)> lpSystemName As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> lpName As String, ' LPCWSTR
lpLuid As IntPtr ' LUID* out
) As Boolean
End Function' lpSystemName : LPCWSTR optional
' lpName : LPCWSTR
' lpLuid : LUID* out
Declare PtrSafe Function LookupPrivilegeValueW Lib "advapi32" ( _
ByVal lpSystemName As LongPtr, _
ByVal lpName As LongPtr, _
ByVal lpLuid As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
LookupPrivilegeValueW = ctypes.windll.advapi32.LookupPrivilegeValueW
LookupPrivilegeValueW.restype = wintypes.BOOL
LookupPrivilegeValueW.argtypes = [
wintypes.LPCWSTR, # lpSystemName : LPCWSTR optional
wintypes.LPCWSTR, # lpName : LPCWSTR
ctypes.c_void_p, # lpLuid : LUID* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
LookupPrivilegeValueW = Fiddle::Function.new(
lib['LookupPrivilegeValueW'],
[
Fiddle::TYPE_VOIDP, # lpSystemName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # lpName : LPCWSTR
Fiddle::TYPE_VOIDP, # lpLuid : LUID* out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "advapi32")]
extern "system" {
fn LookupPrivilegeValueW(
lpSystemName: *const u16, // LPCWSTR optional
lpName: *const u16, // LPCWSTR
lpLuid: *mut LUID // LUID* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool LookupPrivilegeValueW([MarshalAs(UnmanagedType.LPWStr)] string lpSystemName, [MarshalAs(UnmanagedType.LPWStr)] string lpName, IntPtr lpLuid);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_LookupPrivilegeValueW' -Namespace Win32 -PassThru
# $api::LookupPrivilegeValueW(lpSystemName, lpName, lpLuid)#uselib "ADVAPI32.dll"
#func global LookupPrivilegeValueW "LookupPrivilegeValueW" wptr, wptr, wptr
; LookupPrivilegeValueW lpSystemName, lpName, varptr(lpLuid) ; 戻り値は stat
; lpSystemName : LPCWSTR optional -> "wptr"
; lpName : LPCWSTR -> "wptr"
; lpLuid : LUID* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ADVAPI32.dll" #cfunc global LookupPrivilegeValueW "LookupPrivilegeValueW" wstr, wstr, var ; res = LookupPrivilegeValueW(lpSystemName, lpName, lpLuid) ; lpSystemName : LPCWSTR optional -> "wstr" ; lpName : LPCWSTR -> "wstr" ; lpLuid : LUID* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global LookupPrivilegeValueW "LookupPrivilegeValueW" wstr, wstr, sptr ; res = LookupPrivilegeValueW(lpSystemName, lpName, varptr(lpLuid)) ; lpSystemName : LPCWSTR optional -> "wstr" ; lpName : LPCWSTR -> "wstr" ; lpLuid : LUID* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpName, LUID* lpLuid) #uselib "ADVAPI32.dll" #cfunc global LookupPrivilegeValueW "LookupPrivilegeValueW" wstr, wstr, var ; res = LookupPrivilegeValueW(lpSystemName, lpName, lpLuid) ; lpSystemName : LPCWSTR optional -> "wstr" ; lpName : LPCWSTR -> "wstr" ; lpLuid : LUID* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpName, LUID* lpLuid) #uselib "ADVAPI32.dll" #cfunc global LookupPrivilegeValueW "LookupPrivilegeValueW" wstr, wstr, intptr ; res = LookupPrivilegeValueW(lpSystemName, lpName, varptr(lpLuid)) ; lpSystemName : LPCWSTR optional -> "wstr" ; lpName : LPCWSTR -> "wstr" ; lpLuid : LUID* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procLookupPrivilegeValueW = advapi32.NewProc("LookupPrivilegeValueW")
)
// lpSystemName (LPCWSTR optional), lpName (LPCWSTR), lpLuid (LUID* out)
r1, _, err := procLookupPrivilegeValueW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpSystemName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpName))),
uintptr(lpLuid),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction LookupPrivilegeValueW(
lpSystemName: PWideChar; // LPCWSTR optional
lpName: PWideChar; // LPCWSTR
lpLuid: Pointer // LUID* out
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'LookupPrivilegeValueW';result := DllCall("ADVAPI32\LookupPrivilegeValueW"
, "WStr", lpSystemName ; LPCWSTR optional
, "WStr", lpName ; LPCWSTR
, "Ptr", lpLuid ; LUID* out
, "Int") ; return: BOOL●LookupPrivilegeValueW(lpSystemName, lpName, lpLuid) = DLL("ADVAPI32.dll", "bool LookupPrivilegeValueW(char*, char*, void*)")
# 呼び出し: LookupPrivilegeValueW(lpSystemName, lpName, lpLuid)
# lpSystemName : LPCWSTR optional -> "char*"
# lpName : LPCWSTR -> "char*"
# lpLuid : LUID* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。