ホーム › Devices.BiometricFramework › WinBioRemoveCredential
WinBioRemoveCredential
関数指定IDの指定種別の生体認証資格情報を削除する。
シグネチャ
// winbio.dll
#include <windows.h>
HRESULT WinBioRemoveCredential(
WINBIO_IDENTITY Identity,
WINBIO_CREDENTIAL_TYPE Type
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Identity | WINBIO_IDENTITY | in | ログオン資格情報を削除するユーザー アカウントの SID を格納した WINBIO_IDENTITY 構造体です。 | ||||||
| Type | WINBIO_CREDENTIAL_TYPE | in | 資格情報の種類を指定する WINBIO_CREDENTIAL_TYPE 値です。次のいずれかの値を指定できます。
|
戻り値の型: HRESULT
公式ドキュメント
指定したユーザーの生体認証ログオン資格情報を削除します。Windows 10 ビルド 1607 以降、この関数はモバイル イメージで使用できます。
戻り値
関数が成功した場合は S_OK を返します。失敗した場合は、エラーを示す HRESULT 値を返します。考えられる値には次の表のものが含まれますが、これらに限定されません。一般的なエラー コードの一覧については、Common HRESULT Values を参照してください。
| 戻り値 | 説明 |
|---|---|
| 呼び出し元に、その資格情報を削除する権限がありません。 | |
| 指定された ID が存在しないか、資格情報ストアに関連するレコードがありません。 |
解説(Remarks)
特権が昇格されていないユーザーは、自分自身の資格情報のみを削除できます。昇格されたユーザーは、任意のユーザー アカウントの資格情報を削除できます。資格情報を削除しても、そのユーザーの生体認証の登録には影響しません。また、生体認証の資格情報を削除しても、ユーザーがパスワードを使用してログオンすることは妨げられません。資格情報を削除できるのは、中レベル以上の整合性レベルを持つプロセスのみです。より低い整合性レベルのプロセスが資格情報を削除しようとした場合、この関数は E_ACCESSDENIED を返します。
例
次の関数は、特定のユーザーの資格情報を削除するために WinBioRemoveCredential を呼び出す方法を示しています。ヘルパー関数 GetCurrentUserIdentity も併せて示します。Winbio.lib 静的ライブラリをリンクし、次のヘッダー ファイルをインクルードしてください。
- Windows.h
- Stdio.h
- Conio.h
- Winbio.h
HRESULT RemoveCredential()
{
HRESULT hr = S_OK;
WINBIO_IDENTITY identity;
// Find the identity of the user.
wprintf_s(L"\n Finding user identity.\n");
hr = GetCurrentUserIdentity( &identity );
if (FAILED(hr))
{
wprintf(L"\n User identity not found. hr = 0x%x\n", hr);
goto e_Exit;
}
// Remove the user credentials.
hr = WinBioRemoveCredential(identity, WINBIO_CREDENTIAL_PASSWORD);
if (FAILED(hr))
{
wprintf(L"\n WinBioRemoveCredential failed. hr = 0x%x\n", hr);
goto e_Exit;
}
wprintf_s(L"\n User credentials successfully removed.\n");
e_Exit:
wprintf_s(L"\n Press any key to exit...");
_getch();
return hr;
}
//------------------------------------------------------------------------
// The following function retrieves the identity of the current user.
// This is a helper function and is not part of the Windows Biometric
// Framework API.
//
HRESULT GetCurrentUserIdentity(__inout PWINBIO_IDENTITY Identity)
{
// Declare variables.
HRESULT hr = S_OK;
HANDLE tokenHandle = NULL;
DWORD bytesReturned = 0;
struct{
TOKEN_USER tokenUser;
BYTE buffer[SECURITY_MAX_SID_SIZE];
} tokenInfoBuffer;
// Zero the input identity and specify the type.
ZeroMemory( Identity, sizeof(WINBIO_IDENTITY));
Identity->Type = WINBIO_ID_TYPE_NULL;
// Open the access token associated with the
// current process
if (!OpenProcessToken(
GetCurrentProcess(), // Process handle
TOKEN_READ, // Read access only
&tokenHandle)) // Access token handle
{
DWORD win32Status = GetLastError();
wprintf_s(L"Cannot open token handle: %d\n", win32Status);
hr = HRESULT_FROM_WIN32(win32Status);
goto e_Exit;
}
// Zero the tokenInfoBuffer structure.
ZeroMemory(&tokenInfoBuffer, sizeof(tokenInfoBuffer));
// Retrieve information about the access token. In this case,
// retrieve a SID.
if (!GetTokenInformation(
tokenHandle, // Access token handle
TokenUser, // User for the token
&tokenInfoBuffer.tokenUser, // Buffer to fill
sizeof(tokenInfoBuffer), // Size of the buffer
&bytesReturned)) // Size needed
{
DWORD win32Status = GetLastError();
wprintf_s(L"Cannot query token information: %d\n", win32Status);
hr = HRESULT_FROM_WIN32(win32Status);
goto e_Exit;
}
// Copy the SID from the tokenInfoBuffer structure to the
// WINBIO_IDENTITY structure.
CopySid(
SECURITY_MAX_SID_SIZE,
Identity->Value.AccountSid.Data,
tokenInfoBuffer.tokenUser.User.Sid
);
// Specify the size of the SID and assign WINBIO_ID_TYPE_SID
// to the type member of the WINBIO_IDENTITY structure.
Identity->Value.AccountSid.Size = GetLengthSid(tokenInfoBuffer.tokenUser.User.Sid);
Identity->Type = WINBIO_ID_TYPE_SID;
e_Exit:
if (tokenHandle != NULL)
{
CloseHandle(tokenHandle);
}
return hr;
}
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// winbio.dll
#include <windows.h>
HRESULT WinBioRemoveCredential(
WINBIO_IDENTITY Identity,
WINBIO_CREDENTIAL_TYPE Type
);[DllImport("winbio.dll", ExactSpelling = true)]
static extern int WinBioRemoveCredential(
WINBIO_IDENTITY Identity, // WINBIO_IDENTITY
int Type // WINBIO_CREDENTIAL_TYPE
);<DllImport("winbio.dll", ExactSpelling:=True)>
Public Shared Function WinBioRemoveCredential(
Identity As WINBIO_IDENTITY, ' WINBIO_IDENTITY
Type As Integer ' WINBIO_CREDENTIAL_TYPE
) As Integer
End Function' Identity : WINBIO_IDENTITY
' Type : WINBIO_CREDENTIAL_TYPE
Declare PtrSafe Function WinBioRemoveCredential Lib "winbio" ( _
ByVal Identity As LongPtr, _
ByVal Type As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WinBioRemoveCredential = ctypes.windll.winbio.WinBioRemoveCredential
WinBioRemoveCredential.restype = ctypes.c_int
WinBioRemoveCredential.argtypes = [
WINBIO_IDENTITY, # Identity : WINBIO_IDENTITY
ctypes.c_int, # Type : WINBIO_CREDENTIAL_TYPE
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('winbio.dll')
WinBioRemoveCredential = Fiddle::Function.new(
lib['WinBioRemoveCredential'],
[
Fiddle::TYPE_VOIDP, # Identity : WINBIO_IDENTITY
Fiddle::TYPE_INT, # Type : WINBIO_CREDENTIAL_TYPE
],
Fiddle::TYPE_INT)#[link(name = "winbio")]
extern "system" {
fn WinBioRemoveCredential(
Identity: WINBIO_IDENTITY, // WINBIO_IDENTITY
Type: i32 // WINBIO_CREDENTIAL_TYPE
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("winbio.dll")]
public static extern int WinBioRemoveCredential(WINBIO_IDENTITY Identity, int Type);
"@
$api = Add-Type -MemberDefinition $sig -Name 'winbio_WinBioRemoveCredential' -Namespace Win32 -PassThru
# $api::WinBioRemoveCredential(Identity, Type)#uselib "winbio.dll"
#func global WinBioRemoveCredential "WinBioRemoveCredential" sptr, sptr
; WinBioRemoveCredential Identity, Type ; 戻り値は stat
; Identity : WINBIO_IDENTITY -> "sptr"
; Type : WINBIO_CREDENTIAL_TYPE -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "winbio.dll"
#cfunc global WinBioRemoveCredential "WinBioRemoveCredential" int, int
; res = WinBioRemoveCredential(Identity, Type)
; Identity : WINBIO_IDENTITY -> "int"
; Type : WINBIO_CREDENTIAL_TYPE -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。; HRESULT WinBioRemoveCredential(WINBIO_IDENTITY Identity, WINBIO_CREDENTIAL_TYPE Type)
#uselib "winbio.dll"
#cfunc global WinBioRemoveCredential "WinBioRemoveCredential" int, int
; res = WinBioRemoveCredential(Identity, Type)
; Identity : WINBIO_IDENTITY -> "int"
; Type : WINBIO_CREDENTIAL_TYPE -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winbio = windows.NewLazySystemDLL("winbio.dll")
procWinBioRemoveCredential = winbio.NewProc("WinBioRemoveCredential")
)
// Identity (WINBIO_IDENTITY), Type (WINBIO_CREDENTIAL_TYPE)
r1, _, err := procWinBioRemoveCredential.Call(
uintptr(Identity),
uintptr(Type),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction WinBioRemoveCredential(
Identity: WINBIO_IDENTITY; // WINBIO_IDENTITY
Type: Integer // WINBIO_CREDENTIAL_TYPE
): Integer; stdcall;
external 'winbio.dll' name 'WinBioRemoveCredential';result := DllCall("winbio\WinBioRemoveCredential"
, "Ptr", Identity ; WINBIO_IDENTITY
, "Int", Type ; WINBIO_CREDENTIAL_TYPE
, "Int") ; return: HRESULT●WinBioRemoveCredential(Identity, Type) = DLL("winbio.dll", "int WinBioRemoveCredential(void*, int)")
# 呼び出し: WinBioRemoveCredential(Identity, Type)
# Identity : WINBIO_IDENTITY -> "void*"
# Type : WINBIO_CREDENTIAL_TYPE -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "winbio" fn WinBioRemoveCredential(
Identity: WINBIO_IDENTITY, // WINBIO_IDENTITY
Type: i32 // WINBIO_CREDENTIAL_TYPE
) callconv(std.os.windows.WINAPI) i32;proc WinBioRemoveCredential(
Identity: WINBIO_IDENTITY, # WINBIO_IDENTITY
Type: int32 # WINBIO_CREDENTIAL_TYPE
): int32 {.importc: "WinBioRemoveCredential", stdcall, dynlib: "winbio.dll".}pragma(lib, "winbio");
extern(Windows)
int WinBioRemoveCredential(
WINBIO_IDENTITY Identity, // WINBIO_IDENTITY
int Type // WINBIO_CREDENTIAL_TYPE
);ccall((:WinBioRemoveCredential, "winbio.dll"), stdcall, Int32,
(WINBIO_IDENTITY, Int32),
Identity, Type)
# Identity : WINBIO_IDENTITY -> WINBIO_IDENTITY
# Type : WINBIO_CREDENTIAL_TYPE -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t WinBioRemoveCredential(
WINBIO_IDENTITY Identity,
int32_t Type);
]]
local winbio = ffi.load("winbio")
-- winbio.WinBioRemoveCredential(Identity, Type)
-- Identity : WINBIO_IDENTITY
-- Type : WINBIO_CREDENTIAL_TYPE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('winbio.dll');
const WinBioRemoveCredential = lib.func('__stdcall', 'WinBioRemoveCredential', 'int32_t', ['WINBIO_IDENTITY', 'int32_t']);
// WinBioRemoveCredential(Identity, Type)
// Identity : WINBIO_IDENTITY -> 'WINBIO_IDENTITY'
// Type : WINBIO_CREDENTIAL_TYPE -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("winbio.dll", {
WinBioRemoveCredential: { parameters: ["buffer", "i32"], result: "i32" },
});
// lib.symbols.WinBioRemoveCredential(Identity, Type)
// Identity : WINBIO_IDENTITY -> "buffer"
// Type : WINBIO_CREDENTIAL_TYPE -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t WinBioRemoveCredential(
WINBIO_IDENTITY Identity,
int32_t Type);
C, "winbio.dll");
// $ffi->WinBioRemoveCredential(Identity, Type);
// Identity : WINBIO_IDENTITY
// Type : WINBIO_CREDENTIAL_TYPE
// 構造体/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 Winbio extends StdCallLibrary {
Winbio INSTANCE = Native.load("winbio", Winbio.class);
int WinBioRemoveCredential(
WINBIO_IDENTITY /* extends Structure (by value) */ Identity, // WINBIO_IDENTITY
int Type // WINBIO_CREDENTIAL_TYPE
);
}@[Link("winbio")]
lib Libwinbio
fun WinBioRemoveCredential = WinBioRemoveCredential(
Identity : WINBIO_IDENTITY, # WINBIO_IDENTITY
Type : Int32 # WINBIO_CREDENTIAL_TYPE
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef WinBioRemoveCredentialNative = Int32 Function(WINBIO_IDENTITY, Int32);
typedef WinBioRemoveCredentialDart = int Function(int, int);
final WinBioRemoveCredential = DynamicLibrary.open('winbio.dll')
.lookupFunction<WinBioRemoveCredentialNative, WinBioRemoveCredentialDart>('WinBioRemoveCredential');
// Identity : WINBIO_IDENTITY -> WINBIO_IDENTITY
// Type : WINBIO_CREDENTIAL_TYPE -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function WinBioRemoveCredential(
Identity: WINBIO_IDENTITY; // WINBIO_IDENTITY
Type: Integer // WINBIO_CREDENTIAL_TYPE
): Integer; stdcall;
external 'winbio.dll' name 'WinBioRemoveCredential';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WinBioRemoveCredential"
c_WinBioRemoveCredential :: WINBIO_IDENTITY -> Int32 -> IO Int32
-- Identity : WINBIO_IDENTITY -> WINBIO_IDENTITY
-- Type : WINBIO_CREDENTIAL_TYPE -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
-- ※値渡し構造体は GHC FFI で直接渡せません。Ptr で渡すラッパ(C側)経由にしてください。open Ctypes
open Foreign
let winbioremovecredential =
foreign "WinBioRemoveCredential"
(WINBIO_IDENTITY @-> int32_t @-> returning int32_t)
(* Identity : WINBIO_IDENTITY -> WINBIO_IDENTITY *)
(* Type : WINBIO_CREDENTIAL_TYPE -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library winbio (t "winbio.dll"))
(cffi:use-foreign-library winbio)
(cffi:defcfun ("WinBioRemoveCredential" win-bio-remove-credential :convention :stdcall) :int32
(identity (:struct winbio-identity)) ; WINBIO_IDENTITY
(type :int32)) ; WINBIO_CREDENTIAL_TYPE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WinBioRemoveCredential = Win32::API::More->new('winbio',
'int WinBioRemoveCredential(LPVOID Identity, int Type)');
# my $ret = $WinBioRemoveCredential->Call($Identity, $Type);
# Identity : WINBIO_IDENTITY -> LPVOID
# Type : WINBIO_CREDENTIAL_TYPE -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f WinBioRemoveAllCredentials — 全ての生体認証資格情報を削除する。
- f WinBioRemoveAllDomainCredentials — 全てのドメイン用生体認証資格情報を削除する。
- f WinBioSetCredential — 指定種別の生体認証資格情報を設定する。