mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-08 14:10:11 +01:00
Users: add support for Windows
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FF_INCLUDED_detection_users_users
|
||||
#define FF_INCLUDED_detection_users_users
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
void ffDetectUsers(FFlist* users /* List of FFstrbuf */, FFstrbuf* error);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
#include "fastfetch.h"
|
||||
#include "users.h"
|
||||
|
||||
#if FF_HAVE_UTMPX_H
|
||||
#include <utmpx.h>
|
||||
#else
|
||||
//for Android compatibility
|
||||
#include <utmp.h>
|
||||
#define utmpx utmp
|
||||
#define setutxent setutent
|
||||
#define getutxent getutent
|
||||
#endif
|
||||
|
||||
void ffDetectUsers(FFlist* users, FFstrbuf* error)
|
||||
{
|
||||
struct utmpx* n = NULL;
|
||||
setutxent();
|
||||
|
||||
next:
|
||||
while((n = getutxent()))
|
||||
{
|
||||
if(n->ut_type != USER_PROCESS)
|
||||
continue;
|
||||
|
||||
for(uint32_t i = 0; i < users->length; ++i)
|
||||
{
|
||||
if(ffStrbufCompS((FFstrbuf*)ffListGet(users, i), n->ut_user) == 0)
|
||||
goto next;
|
||||
}
|
||||
|
||||
ffStrbufInitS((FFstrbuf*)ffListAdd(users), n->ut_user);
|
||||
}
|
||||
|
||||
if(users->length == 0)
|
||||
ffStrbufAppendS(error, "Unable to detect users");
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
extern "C" {
|
||||
#include "users.h"
|
||||
}
|
||||
#include "util/windows/wmi.hpp"
|
||||
|
||||
void ffDetectUsers(FFlist* users, FFstrbuf* error)
|
||||
{
|
||||
IEnumWbemClassObject* pEnumerator = ffQueryWmi(L"SELECT Antecedent FROM Win32_LoggedOnUser", error);
|
||||
|
||||
if(!pEnumerator)
|
||||
return;
|
||||
|
||||
IWbemClassObject *pclsObj = NULL;
|
||||
ULONG uReturn = 0;
|
||||
|
||||
next:
|
||||
while(SUCCEEDED(pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn)) && uReturn != 0)
|
||||
{
|
||||
FFstrbuf antecedent;
|
||||
ffStrbufInit(&antecedent);
|
||||
ffGetWmiObjValue(pclsObj, L"Antecedent", &antecedent); // \\.\root\cimv2:Win32_Account.Domain="DOMAIN",Name="NAME"
|
||||
ffStrbufTrimRight(&antecedent, '"'); // \\.\root\cimv2:Win32_Account.Domain="DOMAIN",Name="NAME
|
||||
ffStrbufSubstrAfterFirstC(&antecedent, '"'); // DOMAIN",Name="NAME
|
||||
uint32_t index = ffStrbufFirstIndexC(&antecedent, '"');
|
||||
ffStrbufRemoveSubstr(&antecedent, index, ffStrbufLastIndexC(&antecedent, '"')); // DOMAIN"NAME
|
||||
antecedent.chars[index] = '\\';
|
||||
|
||||
for(uint32_t i = 0; i < users->length; ++i)
|
||||
{
|
||||
if(ffStrbufComp((FFstrbuf*)ffListGet(users, i), &antecedent) == 0)
|
||||
goto next;
|
||||
}
|
||||
|
||||
*(FFstrbuf*)ffListAdd(users) = antecedent;
|
||||
}
|
||||
|
||||
if(users->length == 0)
|
||||
ffStrbufAppendS(error, "Unable to detect users");
|
||||
|
||||
pclsObj->Release();
|
||||
pEnumerator->Release();
|
||||
}
|
||||
Reference in New Issue
Block a user