Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
Mendapatkan ID model pengguna aplikasi untuk proses yang ditentukan.
Sintaks
LONG GetApplicationUserModelId(
[in] HANDLE hProcess,
[in, out] UINT32 *applicationUserModelIdLength,
[out] PWSTR applicationUserModelId
);
Parameter
[in] hProcess
Handel untuk proses. Handel ini harus memiliki hak akses PROCESS_QUERY_LIMITED_INFORMATION . Untuk informasi selengkapnya, lihat Keamanan Proses dan Hak Akses.
[in, out] applicationUserModelIdLength
Pada input, ukuran buffer applicationUserModelId , dalam karakter yang luas. Jika berhasil, ukuran buffer yang digunakan, termasuk terminator null.
[out] applicationUserModelId
Penunjuk ke buffer yang menerima ID model pengguna aplikasi.
Nilai kembali
Jika fungsi berhasil, fungsi akan mengembalikan ERROR_SUCCESS. Jika tidak, fungsi mengembalikan kode kesalahan. Kode kesalahan yang mungkin mencakup yang berikut ini.
| Menampilkan kode | Deskripsi |
|---|---|
|
Proses ini tidak memiliki identitas aplikasi. |
|
Buffer tidak cukup besar untuk menyimpan data. Ukuran yang diperlukan ditentukan oleh applicationUserModelIdLength. |
Keterangan
Untuk informasi tentang batas ukuran string, lihat Konstanta identitas.
Contoh
#define _UNICODE 1
#define UNICODE 1
#include <Windows.h>
#include <appmodel.h>
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
int ShowUsage();
void ShowProcessApplicationUserModelId(__in const UINT32 pid, __in HANDLE process);
int ShowUsage()
{
wprintf(L"Usage: GetApplicationUserModelId <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
{
ShowProcessApplicationUserModelId(pid, process);
CloseHandle(process);
}
}
}
return 0;
}
void ShowProcessApplicationUserModelId(__in const UINT32 pid, __in HANDLE process)
{
wprintf(L"Process %u (handle=%p)\n", pid, process);
UINT32 length = 0;
LONG rc = GetApplicationUserModelId(process, &length, NULL);
if (rc != ERROR_INSUFFICIENT_BUFFER)
{
if (rc == APPMODEL_ERROR_NO_APPLICATION)
wprintf(L"Desktop application\n");
else
wprintf(L"Error %d in GetApplicationUserModelId\n", rc);
return;
}
PWSTR fullName = (PWSTR) malloc(length * sizeof(*fullName));
if (fullName == NULL)
{
wprintf(L"Error allocating memory\n");
return;
}
rc = GetApplicationUserModelId(process, &length, fullName);
if (rc != ERROR_SUCCESS)
wprintf(L"Error %d retrieving ApplicationUserModelId\n", rc);
else
wprintf(L"%s\n", fullName);
free(fullName);
}
Persyaratan
| Persyaratan | Nilai |
|---|---|
| Target Platform | Windows |
| Header | appmodel.h |
| Pustaka | Kernel32.lib |
| DLL | Kernel32.dll |