MCPcopy Create free account
hub / github.com/derceg/explorerplusplus / GetFileOwner

Function GetFileOwner

Explorer++/Helper/Helper.cpp:245–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

243}
244
245BOOL GetFileOwner(const TCHAR *szFile, TCHAR *szOwner, size_t cchMax)
246{
247 BOOL success = FALSE;
248
249 wil::unique_hfile file(CreateFile(szFile, READ_CONTROL, FILE_SHARE_READ,
250 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL));
251
252 if(file)
253 {
254 PSID pSidOwner = NULL;
255 PSECURITY_DESCRIPTOR pSD = NULL;
256 DWORD dwRet = GetSecurityInfo(file.get(), SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION,
257 &pSidOwner, NULL, NULL, NULL, &pSD);
258
259 if(dwRet == ERROR_SUCCESS)
260 {
261 success = FormatUserName(pSidOwner, szOwner, cchMax);
262 LocalFree(pSD);
263 }
264 }
265
266 return success;
267}
268
269BOOL FormatUserName(PSID sid, TCHAR *userName, size_t cchMax)
270{

Callers 2

GetOwnerColumnTextFunction · 0.85

Calls 2

FormatUserNameFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected