ホーム › Storage.Packaging.Appx › GetApplicationUserModelIdFromToken
GetApplicationUserModelIdFromToken
関数トークンからアプリケーションユーザーモデルIDを取得する。
シグネチャ
// api-ms-win-appmodel-runtime-l1-1-1.dll
#include <windows.h>
WIN32_ERROR GetApplicationUserModelIdFromToken(
HANDLE token,
DWORD* applicationUserModelIdLength,
LPWSTR applicationUserModelId // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| token | HANDLE | in | アプリケーション ID を含むトークン。このハンドルには PROCESS_QUERY_LIMITED_INFORMATION アクセス権が必要です。詳細については、Process Security and Access Rights を参照してください。 |
| applicationUserModelIdLength | DWORD* | inout | 入力時は、applicationUserModelId バッファーのサイズ (ワイド文字単位)。成功時は、null 終端文字を含む、使用されたバッファーのサイズ。 |
| applicationUserModelId | LPWSTR | outoptional | アプリケーション ユーザー モデル ID を受け取るバッファーへのポインター。 |
戻り値の型: WIN32_ERROR
公式ドキュメント
指定されたトークンのアプリケーション ユーザー モデル ID を取得します。
戻り値
関数が成功した場合は ERROR_SUCCESS を返します。それ以外の場合は、エラー コードを返します。返される可能性のあるエラー コードには、次のものがあります。
| 戻り値 | 説明 |
|---|---|
| トークンにアプリケーション ID がありません。 | |
| バッファーがデータを格納するのに十分な大きさではありません。必要なサイズは applicationUserModelIdLength に格納されます。 |
解説(Remarks)
文字列のサイズ制限については、Identity constants を参照してください。
例
/***************************************************
* *
* Copyright (C) Microsoft. All rights reserved. *
* *
***************************************************/
#define _UNICODE 1
#define UNICODE 1
#include <Windows.h>
#include <appmodel.h>
#include <appmodelp.h>
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
int ShowUsage();
void ShowProcessApplicationUserModelId(__in const UINT32 pid, __in HANDLE token);
int ShowUsage()
{
wprintf(L"Usage: GetApplicationUserModelIdFromToken <pid> [<pid>...]\n");
return 1;
}
int __cdecl wmain(__in int argc, __in_ecount(argc) WCHAR * argv[])
{
if (argc <= 1)
return ShowUsage();
for (int i=1; i<argc; ++i)
{
UINT32 pid = wcstoul(argv[i], NULL, 10);
if (pid > 0)
{
HANDLE process = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
if (process == NULL)
wprintf(L"Error %d in OpenProcess (pid=%u)\n", GetLastError(), pid);
else
{
HANDLE token;
if (!OpenProcessToken(process, TOKEN_QUERY, &token))
wprintf(L"Error %d in OpenProcessToken (pid=%u)\n", GetLastError(), pid);
else
{
ShowProcessApplicationUserModelId(pid, token);
CloseHandle(token);
}
CloseHandle(process);
}
}
}
return 0;
}
void ShowProcessApplicationUserModelId(__in const UINT32 pid, __in HANDLE token)
{
wprintf(L"Process %u (token=%p)\n", pid, token);
UINT32 length = 0;
LONG rc = GetApplicationUserModelIdFromToken(token, &length, NULL);
if (rc != ERROR_INSUFFICIENT_BUFFER)
{
if (rc == APPMODEL_ERROR_NO_PACKAGE)
wprintf(L"Token has no package identity\n");
else
wprintf(L"Error %d in GetApplicationUserModelIdFromToken\n", rc);
return;
}
PWSTR applicationUserModelId = (PWSTR) malloc(length * sizeof(*applicationUserModelId));
if (applicationUserModelId == NULL)
{
wprintf(L"Error allocating memory\n");
return;
}
rc = GetApplicationUserModelIdFromToken(token, &length, applicationUserModelId);
if (rc != ERROR_SUCCESS)
wprintf(L"Error %d retrieving ApplicationUserModelId\n", rc);
else
wprintf(L"%s\n", applicationUserModelId);
free(applicationUserModelId);
}
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// api-ms-win-appmodel-runtime-l1-1-1.dll
#include <windows.h>
WIN32_ERROR GetApplicationUserModelIdFromToken(
HANDLE token,
DWORD* applicationUserModelIdLength,
LPWSTR applicationUserModelId // optional
);[DllImport("api-ms-win-appmodel-runtime-l1-1-1.dll", ExactSpelling = true)]
static extern uint GetApplicationUserModelIdFromToken(
IntPtr token, // HANDLE
ref uint applicationUserModelIdLength, // DWORD* in/out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder applicationUserModelId // LPWSTR optional, out
);<DllImport("api-ms-win-appmodel-runtime-l1-1-1.dll", ExactSpelling:=True)>
Public Shared Function GetApplicationUserModelIdFromToken(
token As IntPtr, ' HANDLE
ByRef applicationUserModelIdLength As UInteger, ' DWORD* in/out
<MarshalAs(UnmanagedType.LPWStr)> applicationUserModelId As System.Text.StringBuilder ' LPWSTR optional, out
) As UInteger
End Function' token : HANDLE
' applicationUserModelIdLength : DWORD* in/out
' applicationUserModelId : LPWSTR optional, out
Declare PtrSafe Function GetApplicationUserModelIdFromToken Lib "api-ms-win-appmodel-runtime-l1-1-1" ( _
ByVal token As LongPtr, _
ByRef applicationUserModelIdLength As Long, _
ByVal applicationUserModelId As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetApplicationUserModelIdFromToken = ctypes.windll.LoadLibrary("api-ms-win-appmodel-runtime-l1-1-1.dll").GetApplicationUserModelIdFromToken
GetApplicationUserModelIdFromToken.restype = wintypes.DWORD
GetApplicationUserModelIdFromToken.argtypes = [
wintypes.HANDLE, # token : HANDLE
ctypes.POINTER(wintypes.DWORD), # applicationUserModelIdLength : DWORD* in/out
wintypes.LPWSTR, # applicationUserModelId : LPWSTR optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('api-ms-win-appmodel-runtime-l1-1-1.dll')
GetApplicationUserModelIdFromToken = Fiddle::Function.new(
lib['GetApplicationUserModelIdFromToken'],
[
Fiddle::TYPE_VOIDP, # token : HANDLE
Fiddle::TYPE_VOIDP, # applicationUserModelIdLength : DWORD* in/out
Fiddle::TYPE_VOIDP, # applicationUserModelId : LPWSTR optional, out
],
-Fiddle::TYPE_INT)#[link(name = "api-ms-win-appmodel-runtime-l1-1-1")]
extern "system" {
fn GetApplicationUserModelIdFromToken(
token: *mut core::ffi::c_void, // HANDLE
applicationUserModelIdLength: *mut u32, // DWORD* in/out
applicationUserModelId: *mut u16 // LPWSTR optional, out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("api-ms-win-appmodel-runtime-l1-1-1.dll")]
public static extern uint GetApplicationUserModelIdFromToken(IntPtr token, ref uint applicationUserModelIdLength, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder applicationUserModelId);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-appmodel-runtime-l1-1-1_GetApplicationUserModelIdFromToken' -Namespace Win32 -PassThru
# $api::GetApplicationUserModelIdFromToken(token, applicationUserModelIdLength, applicationUserModelId)#uselib "api-ms-win-appmodel-runtime-l1-1-1.dll"
#func global GetApplicationUserModelIdFromToken "GetApplicationUserModelIdFromToken" sptr, sptr, sptr
; GetApplicationUserModelIdFromToken token, varptr(applicationUserModelIdLength), varptr(applicationUserModelId) ; 戻り値は stat
; token : HANDLE -> "sptr"
; applicationUserModelIdLength : DWORD* in/out -> "sptr"
; applicationUserModelId : LPWSTR optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "api-ms-win-appmodel-runtime-l1-1-1.dll" #cfunc global GetApplicationUserModelIdFromToken "GetApplicationUserModelIdFromToken" sptr, var, var ; res = GetApplicationUserModelIdFromToken(token, applicationUserModelIdLength, applicationUserModelId) ; token : HANDLE -> "sptr" ; applicationUserModelIdLength : DWORD* in/out -> "var" ; applicationUserModelId : LPWSTR optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "api-ms-win-appmodel-runtime-l1-1-1.dll" #cfunc global GetApplicationUserModelIdFromToken "GetApplicationUserModelIdFromToken" sptr, sptr, sptr ; res = GetApplicationUserModelIdFromToken(token, varptr(applicationUserModelIdLength), varptr(applicationUserModelId)) ; token : HANDLE -> "sptr" ; applicationUserModelIdLength : DWORD* in/out -> "sptr" ; applicationUserModelId : LPWSTR optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR GetApplicationUserModelIdFromToken(HANDLE token, DWORD* applicationUserModelIdLength, LPWSTR applicationUserModelId) #uselib "api-ms-win-appmodel-runtime-l1-1-1.dll" #cfunc global GetApplicationUserModelIdFromToken "GetApplicationUserModelIdFromToken" intptr, var, var ; res = GetApplicationUserModelIdFromToken(token, applicationUserModelIdLength, applicationUserModelId) ; token : HANDLE -> "intptr" ; applicationUserModelIdLength : DWORD* in/out -> "var" ; applicationUserModelId : LPWSTR optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR GetApplicationUserModelIdFromToken(HANDLE token, DWORD* applicationUserModelIdLength, LPWSTR applicationUserModelId) #uselib "api-ms-win-appmodel-runtime-l1-1-1.dll" #cfunc global GetApplicationUserModelIdFromToken "GetApplicationUserModelIdFromToken" intptr, intptr, intptr ; res = GetApplicationUserModelIdFromToken(token, varptr(applicationUserModelIdLength), varptr(applicationUserModelId)) ; token : HANDLE -> "intptr" ; applicationUserModelIdLength : DWORD* in/out -> "intptr" ; applicationUserModelId : LPWSTR optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
api_ms_win_appmodel_runtime_l1_1_1 = windows.NewLazySystemDLL("api-ms-win-appmodel-runtime-l1-1-1.dll")
procGetApplicationUserModelIdFromToken = api_ms_win_appmodel_runtime_l1_1_1.NewProc("GetApplicationUserModelIdFromToken")
)
// token (HANDLE), applicationUserModelIdLength (DWORD* in/out), applicationUserModelId (LPWSTR optional, out)
r1, _, err := procGetApplicationUserModelIdFromToken.Call(
uintptr(token),
uintptr(applicationUserModelIdLength),
uintptr(applicationUserModelId),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction GetApplicationUserModelIdFromToken(
token: THandle; // HANDLE
applicationUserModelIdLength: Pointer; // DWORD* in/out
applicationUserModelId: PWideChar // LPWSTR optional, out
): DWORD; stdcall;
external 'api-ms-win-appmodel-runtime-l1-1-1.dll' name 'GetApplicationUserModelIdFromToken';result := DllCall("api-ms-win-appmodel-runtime-l1-1-1\GetApplicationUserModelIdFromToken"
, "Ptr", token ; HANDLE
, "Ptr", applicationUserModelIdLength ; DWORD* in/out
, "Ptr", applicationUserModelId ; LPWSTR optional, out
, "UInt") ; return: WIN32_ERROR●GetApplicationUserModelIdFromToken(token, applicationUserModelIdLength, applicationUserModelId) = DLL("api-ms-win-appmodel-runtime-l1-1-1.dll", "dword GetApplicationUserModelIdFromToken(void*, void*, char*)")
# 呼び出し: GetApplicationUserModelIdFromToken(token, applicationUserModelIdLength, applicationUserModelId)
# token : HANDLE -> "void*"
# applicationUserModelIdLength : DWORD* in/out -> "void*"
# applicationUserModelId : LPWSTR optional, out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "api-ms-win-appmodel-runtime-l1-1-1" fn GetApplicationUserModelIdFromToken(
token: ?*anyopaque, // HANDLE
applicationUserModelIdLength: [*c]u32, // DWORD* in/out
applicationUserModelId: [*c]u16 // LPWSTR optional, out
) callconv(std.os.windows.WINAPI) u32;proc GetApplicationUserModelIdFromToken(
token: pointer, # HANDLE
applicationUserModelIdLength: ptr uint32, # DWORD* in/out
applicationUserModelId: ptr uint16 # LPWSTR optional, out
): uint32 {.importc: "GetApplicationUserModelIdFromToken", stdcall, dynlib: "api-ms-win-appmodel-runtime-l1-1-1.dll".}pragma(lib, "api-ms-win-appmodel-runtime-l1-1-1");
extern(Windows)
uint GetApplicationUserModelIdFromToken(
void* token, // HANDLE
uint* applicationUserModelIdLength, // DWORD* in/out
wchar* applicationUserModelId // LPWSTR optional, out
);ccall((:GetApplicationUserModelIdFromToken, "api-ms-win-appmodel-runtime-l1-1-1.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Ptr{UInt32}, Ptr{UInt16}),
token, applicationUserModelIdLength, applicationUserModelId)
# token : HANDLE -> Ptr{Cvoid}
# applicationUserModelIdLength : DWORD* in/out -> Ptr{UInt32}
# applicationUserModelId : LPWSTR optional, out -> Ptr{UInt16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t GetApplicationUserModelIdFromToken(
void* token,
uint32_t* applicationUserModelIdLength,
uint16_t* applicationUserModelId);
]]
local api-ms-win-appmodel-runtime-l1-1-1 = ffi.load("api-ms-win-appmodel-runtime-l1-1-1")
-- api-ms-win-appmodel-runtime-l1-1-1.GetApplicationUserModelIdFromToken(token, applicationUserModelIdLength, applicationUserModelId)
-- token : HANDLE
-- applicationUserModelIdLength : DWORD* in/out
-- applicationUserModelId : LPWSTR optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('api-ms-win-appmodel-runtime-l1-1-1.dll');
const GetApplicationUserModelIdFromToken = lib.func('__stdcall', 'GetApplicationUserModelIdFromToken', 'uint32_t', ['void *', 'uint32_t *', 'uint16_t *']);
// GetApplicationUserModelIdFromToken(token, applicationUserModelIdLength, applicationUserModelId)
// token : HANDLE -> 'void *'
// applicationUserModelIdLength : DWORD* in/out -> 'uint32_t *'
// applicationUserModelId : LPWSTR optional, out -> 'uint16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("api-ms-win-appmodel-runtime-l1-1-1.dll", {
GetApplicationUserModelIdFromToken: { parameters: ["pointer", "pointer", "buffer"], result: "u32" },
});
// lib.symbols.GetApplicationUserModelIdFromToken(token, applicationUserModelIdLength, applicationUserModelId)
// token : HANDLE -> "pointer"
// applicationUserModelIdLength : DWORD* in/out -> "pointer"
// applicationUserModelId : LPWSTR optional, out -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t GetApplicationUserModelIdFromToken(
void* token,
uint32_t* applicationUserModelIdLength,
uint16_t* applicationUserModelId);
C, "api-ms-win-appmodel-runtime-l1-1-1.dll");
// $ffi->GetApplicationUserModelIdFromToken(token, applicationUserModelIdLength, applicationUserModelId);
// token : HANDLE
// applicationUserModelIdLength : DWORD* in/out
// applicationUserModelId : LPWSTR optional, 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 Api-ms-win-appmodel-runtime-l1-1-1 extends StdCallLibrary {
Api-ms-win-appmodel-runtime-l1-1-1 INSTANCE = Native.load("api-ms-win-appmodel-runtime-l1-1-1", Api-ms-win-appmodel-runtime-l1-1-1.class);
int GetApplicationUserModelIdFromToken(
Pointer token, // HANDLE
IntByReference applicationUserModelIdLength, // DWORD* in/out
char[] applicationUserModelId // LPWSTR optional, out
);
}@[Link("api-ms-win-appmodel-runtime-l1-1-1")]
lib Libapi-ms-win-appmodel-runtime-l1-1-1
fun GetApplicationUserModelIdFromToken = GetApplicationUserModelIdFromToken(
token : Void*, # HANDLE
applicationUserModelIdLength : UInt32*, # DWORD* in/out
applicationUserModelId : UInt16* # LPWSTR optional, out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetApplicationUserModelIdFromTokenNative = Uint32 Function(Pointer<Void>, Pointer<Uint32>, Pointer<Utf16>);
typedef GetApplicationUserModelIdFromTokenDart = int Function(Pointer<Void>, Pointer<Uint32>, Pointer<Utf16>);
final GetApplicationUserModelIdFromToken = DynamicLibrary.open('api-ms-win-appmodel-runtime-l1-1-1.dll')
.lookupFunction<GetApplicationUserModelIdFromTokenNative, GetApplicationUserModelIdFromTokenDart>('GetApplicationUserModelIdFromToken');
// token : HANDLE -> Pointer<Void>
// applicationUserModelIdLength : DWORD* in/out -> Pointer<Uint32>
// applicationUserModelId : LPWSTR optional, out -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetApplicationUserModelIdFromToken(
token: THandle; // HANDLE
applicationUserModelIdLength: Pointer; // DWORD* in/out
applicationUserModelId: PWideChar // LPWSTR optional, out
): DWORD; stdcall;
external 'api-ms-win-appmodel-runtime-l1-1-1.dll' name 'GetApplicationUserModelIdFromToken';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetApplicationUserModelIdFromToken"
c_GetApplicationUserModelIdFromToken :: Ptr () -> Ptr Word32 -> CWString -> IO Word32
-- token : HANDLE -> Ptr ()
-- applicationUserModelIdLength : DWORD* in/out -> Ptr Word32
-- applicationUserModelId : LPWSTR optional, out -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getapplicationusermodelidfromtoken =
foreign "GetApplicationUserModelIdFromToken"
((ptr void) @-> (ptr uint32_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* token : HANDLE -> (ptr void) *)
(* applicationUserModelIdLength : DWORD* in/out -> (ptr uint32_t) *)
(* applicationUserModelId : LPWSTR optional, out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library api-ms-win-appmodel-runtime-l1-1-1 (t "api-ms-win-appmodel-runtime-l1-1-1.dll"))
(cffi:use-foreign-library api-ms-win-appmodel-runtime-l1-1-1)
(cffi:defcfun ("GetApplicationUserModelIdFromToken" get-application-user-model-id-from-token :convention :stdcall) :uint32
(token :pointer) ; HANDLE
(application-user-model-id-length :pointer) ; DWORD* in/out
(application-user-model-id :pointer)) ; LPWSTR optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetApplicationUserModelIdFromToken = Win32::API::More->new('api-ms-win-appmodel-runtime-l1-1-1',
'DWORD GetApplicationUserModelIdFromToken(HANDLE token, LPVOID applicationUserModelIdLength, LPWSTR applicationUserModelId)');
# my $ret = $GetApplicationUserModelIdFromToken->Call($token, $applicationUserModelIdLength, $applicationUserModelId);
# token : HANDLE -> HANDLE
# applicationUserModelIdLength : DWORD* in/out -> LPVOID
# applicationUserModelId : LPWSTR optional, out -> LPWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型