ホーム › Security.Authorization › ConvertStringSidToSidW
ConvertStringSidToSidW
関数文字列形式のSIDをバイナリのSIDに変換する。
シグネチャ
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
BOOL ConvertStringSidToSidW(
LPCWSTR StringSid,
PSID* Sid
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| StringSid | LPCWSTR | in | 変換対象の文字列形式 SID を格納した、null で終わる文字列へのポインターです。 SID 文字列には、標準の S-R-I-S-S… 形式の SID 文字列、または組み込み Administrators を表す "BA" のような SID 文字列定数形式のいずれかを使用できます。SID 文字列の表記法の詳細については、 SID Components を参照してください。 |
| Sid | PSID* | out | 変換後の SID へのポインターを受け取る変数へのポインターです。返されたバッファーを解放するには、 LocalFree 関数を呼び出します。 |
戻り値の型: BOOL
公式ドキュメント
文字列形式のセキュリティ識別子 (SID) を、有効で機能する SID に変換します。この関数は、ConvertSidToStringSid 関数で文字列形式に変換した SID を取得するために使用できます。(Unicode)
戻り値
関数が成功すると、戻り値は 0 以外になります。
関数が失敗すると、戻り値は 0 になります。拡張エラー情報を取得するには、 GetLastError を呼び出します。GetLastError 関数は、次のいずれかのエラーコードを返すことがあります。
| 戻り値 | 説明 |
|---|---|
| パラメーターが無効です。 | |
| SID が無効です。 |
解説(Remarks)
メモ
sddl.h ヘッダーは、ConvertStringSidToSid を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在して使用すると、不一致が生じてコンパイルエラーや実行時エラーの原因となることがあります。詳細については、Conventions for Function Prototypes を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
BOOL ConvertStringSidToSidW(
LPCWSTR StringSid,
PSID* Sid
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool ConvertStringSidToSidW(
[MarshalAs(UnmanagedType.LPWStr)] string StringSid, // LPCWSTR
IntPtr Sid // PSID* out
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ConvertStringSidToSidW(
<MarshalAs(UnmanagedType.LPWStr)> StringSid As String, ' LPCWSTR
Sid As IntPtr ' PSID* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' StringSid : LPCWSTR
' Sid : PSID* out
Declare PtrSafe Function ConvertStringSidToSidW Lib "advapi32" ( _
ByVal StringSid As LongPtr, _
ByVal Sid 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
ConvertStringSidToSidW = ctypes.windll.advapi32.ConvertStringSidToSidW
ConvertStringSidToSidW.restype = wintypes.BOOL
ConvertStringSidToSidW.argtypes = [
wintypes.LPCWSTR, # StringSid : LPCWSTR
ctypes.c_void_p, # Sid : PSID* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
ConvertStringSidToSidW = Fiddle::Function.new(
lib['ConvertStringSidToSidW'],
[
Fiddle::TYPE_VOIDP, # StringSid : LPCWSTR
Fiddle::TYPE_VOIDP, # Sid : PSID* out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "advapi32")]
extern "system" {
fn ConvertStringSidToSidW(
StringSid: *const u16, // LPCWSTR
Sid: *mut *mut core::ffi::c_void // PSID* 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 ConvertStringSidToSidW([MarshalAs(UnmanagedType.LPWStr)] string StringSid, IntPtr Sid);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_ConvertStringSidToSidW' -Namespace Win32 -PassThru
# $api::ConvertStringSidToSidW(StringSid, Sid)#uselib "ADVAPI32.dll"
#func global ConvertStringSidToSidW "ConvertStringSidToSidW" wptr, wptr
; ConvertStringSidToSidW StringSid, Sid ; 戻り値は stat
; StringSid : LPCWSTR -> "wptr"
; Sid : PSID* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll"
#cfunc global ConvertStringSidToSidW "ConvertStringSidToSidW" wstr, sptr
; res = ConvertStringSidToSidW(StringSid, Sid)
; StringSid : LPCWSTR -> "wstr"
; Sid : PSID* out -> "sptr"; BOOL ConvertStringSidToSidW(LPCWSTR StringSid, PSID* Sid)
#uselib "ADVAPI32.dll"
#cfunc global ConvertStringSidToSidW "ConvertStringSidToSidW" wstr, intptr
; res = ConvertStringSidToSidW(StringSid, Sid)
; StringSid : LPCWSTR -> "wstr"
; Sid : PSID* out -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procConvertStringSidToSidW = advapi32.NewProc("ConvertStringSidToSidW")
)
// StringSid (LPCWSTR), Sid (PSID* out)
r1, _, err := procConvertStringSidToSidW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(StringSid))),
uintptr(Sid),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction ConvertStringSidToSidW(
StringSid: PWideChar; // LPCWSTR
Sid: Pointer // PSID* out
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'ConvertStringSidToSidW';result := DllCall("ADVAPI32\ConvertStringSidToSidW"
, "WStr", StringSid ; LPCWSTR
, "Ptr", Sid ; PSID* out
, "Int") ; return: BOOL●ConvertStringSidToSidW(StringSid, Sid) = DLL("ADVAPI32.dll", "bool ConvertStringSidToSidW(char*, void*)")
# 呼び出し: ConvertStringSidToSidW(StringSid, Sid)
# StringSid : LPCWSTR -> "char*"
# Sid : PSID* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "advapi32" fn ConvertStringSidToSidW(
StringSid: [*c]const u16, // LPCWSTR
Sid: ?*anyopaque // PSID* out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc ConvertStringSidToSidW(
StringSid: WideCString, # LPCWSTR
Sid: pointer # PSID* out
): int32 {.importc: "ConvertStringSidToSidW", stdcall, dynlib: "ADVAPI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "advapi32");
extern(Windows)
int ConvertStringSidToSidW(
const(wchar)* StringSid, // LPCWSTR
void* Sid // PSID* out
);ccall((:ConvertStringSidToSidW, "ADVAPI32.dll"), stdcall, Int32,
(Cwstring, Ptr{Cvoid}),
StringSid, Sid)
# StringSid : LPCWSTR -> Cwstring
# Sid : PSID* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t ConvertStringSidToSidW(
const uint16_t* StringSid,
void* Sid);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.ConvertStringSidToSidW(StringSid, Sid)
-- StringSid : LPCWSTR
-- Sid : PSID* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const ConvertStringSidToSidW = lib.func('__stdcall', 'ConvertStringSidToSidW', 'int32_t', ['str16', 'void *']);
// ConvertStringSidToSidW(StringSid, Sid)
// StringSid : LPCWSTR -> 'str16'
// Sid : PSID* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
ConvertStringSidToSidW: { parameters: ["buffer", "pointer"], result: "i32" },
});
// lib.symbols.ConvertStringSidToSidW(StringSid, Sid)
// StringSid : LPCWSTR -> "buffer"
// Sid : PSID* out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ConvertStringSidToSidW(
const uint16_t* StringSid,
void* Sid);
C, "ADVAPI32.dll");
// $ffi->ConvertStringSidToSidW(StringSid, Sid);
// StringSid : LPCWSTR
// Sid : PSID* 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 Advapi32 extends StdCallLibrary {
Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class, W32APIOptions.UNICODE_OPTIONS);
boolean ConvertStringSidToSidW(
WString StringSid, // LPCWSTR
Pointer Sid // PSID* out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("advapi32")]
lib LibADVAPI32
fun ConvertStringSidToSidW = ConvertStringSidToSidW(
StringSid : UInt16*, # LPCWSTR
Sid : Void* # PSID* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ConvertStringSidToSidWNative = Int32 Function(Pointer<Utf16>, Pointer<Void>);
typedef ConvertStringSidToSidWDart = int Function(Pointer<Utf16>, Pointer<Void>);
final ConvertStringSidToSidW = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<ConvertStringSidToSidWNative, ConvertStringSidToSidWDart>('ConvertStringSidToSidW');
// StringSid : LPCWSTR -> Pointer<Utf16>
// Sid : PSID* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ConvertStringSidToSidW(
StringSid: PWideChar; // LPCWSTR
Sid: Pointer // PSID* out
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'ConvertStringSidToSidW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ConvertStringSidToSidW"
c_ConvertStringSidToSidW :: CWString -> Ptr () -> IO CInt
-- StringSid : LPCWSTR -> CWString
-- Sid : PSID* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let convertstringsidtosidw =
foreign "ConvertStringSidToSidW"
((ptr uint16_t) @-> (ptr void) @-> returning int32_t)
(* StringSid : LPCWSTR -> (ptr uint16_t) *)
(* Sid : PSID* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("ConvertStringSidToSidW" convert-string-sid-to-sid-w :convention :stdcall) :int32
(string-sid (:string :encoding :utf-16le)) ; LPCWSTR
(sid :pointer)) ; PSID* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ConvertStringSidToSidW = Win32::API::More->new('ADVAPI32',
'BOOL ConvertStringSidToSidW(LPCWSTR StringSid, HANDLE Sid)');
# my $ret = $ConvertStringSidToSidW->Call($StringSid, $Sid);
# StringSid : LPCWSTR -> LPCWSTR
# Sid : PSID* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f ConvertStringSidToSidA (ANSI版) — 文字列形式のSIDをバイナリのSIDに変換する。
公式の関連項目
- f ConvertSecurityDescriptorToStringSecurityDescriptorW — セキュリティ記述子をSDDL文字列に変換する。
- f ConvertSidToStringSidW — SIDを文字列形式のSIDに変換する。
- f ConvertStringSecurityDescriptorToSecurityDescriptorW — SDDL文字列をセキュリティ記述子に変換する。
- s SID