简体   繁体   中英

How to find out the name of Windows system profile?

I am writing a Windows Service that would be work with database using a system profile name. For this feature I have a Postgres SQL Server .

I want to create trust authentication for Windows system profile before I run the service.

For this I'll run some console application that would write needed information like authentication method in pg_hba.conf file and create role with system profile name. By the way, it's very cool that Postgres can identifies other language symbols (not sure about all of them though).

The problem is how can I find out translated name of Windows system profile? Cause each Windows on different languages has different system profile name: system , система , sistema etc.

So, problem solved with WinAPI:

#include <windows.h>

<...>

static const DWORD MAX_BUFF_SIZE = 256;
SID_IDENTIFIER_AUTHORITY auth = SECURITY_NT_AUTHORITY;
PSID pSid = NULL;
SID_NAME_USE use;    
wchar_t buffName[MAX_BUFF_SIZE];    // Here would be name
DWORD buffNameSize = MAX_BUFF_SIZE;
wchar_t buffDomain[MAX_BUFF_SIZE];
DWORD buffDomainSize = MAX_BUFF_SIZE;

AllocateAndInitializeSid(&auth, 1, SECURITY_LOCAL_SYSTEM_RID, 0, 0, 0, 0, 0, 0, 0, &pSid);
LookupAccountSid(NULL, pSid, buffName, &buffNameSize, buffDomain, &buffDomainSize, &use);

FreeSid(pSid);

<...>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM