Note that there are some explanatory texts on larger screens.

plurals
  1. POGet Process Username c++
    primarykey
    data
    text
    <p>i am making a taskmanager like app. for windows,i can get all the system processes,now i want to get process's username.I got the code from net.</p> <pre><code>void enableDebugPrivileges() { HANDLE hcurrent=GetCurrentProcess(); HANDLE hToken; BOOL bret=OpenProcessToken(hcurrent,40,&amp;hToken); LUID luid; bret=LookupPrivilegeValue(NULL,SE_LOAD_DRIVER_NAME, &amp;luid); TOKEN_PRIVILEGES NewState,PreviousState; DWORD ReturnLength; NewState.PrivilegeCount =1; NewState.Privileges[0].Luid =luid; NewState.Privileges[0].Attributes=2; AdjustTokenPrivileges(hToken,FALSE,&amp;NewState,28,&amp;PreviousState,&amp;ReturnLength); } char *GetProcessUsername(HANDLE *phProcess, BOOL bIncDomain) { static char sname[300]; HANDLE tok = 0; HANDLE hProcess; TOKEN_USER *ptu; DWORD nlen, dlen; char name[300], dom[300], tubuf[300], *pret = 0; int iUse; //if phProcess is NULL we get process handle of this //process. hProcess = phProcess?*phProcess:GetCurrentProcess(); //open the processes token if (!OpenProcessToken(hProcess,TOKEN_QUERY,&amp;tok)) goto ert; //get the SID of the token ptu = (TOKEN_USER*)tubuf; if (!GetTokenInformation(tok,(TOKEN_INFORMATION_CLASS)1,ptu,300,&amp;nlen)) goto ert; //get the account/domain name of the SID dlen = 300; nlen = 300; if (!LookupAccountSidA(0, ptu-&gt;User.Sid, name, &amp;nlen, dom, &amp;dlen, (PSID_NAME_USE)&amp;iUse)) goto ert; //copy info to our static buffer if (dlen &amp;&amp; bIncDomain) { strcpy(sname,dom); strcat(sname,""); strcat(sname,name); } else { strcpy(sname,name); } //set our return variable pret = sname; ert: if (tok) CloseHandle(tok); return pret; } int main(){ enableDebugPrivileges(); DWORD dwPID=3436; HANDLE hProcess_i = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwPID); printf("%s",GetProcessUsername(&amp;hProcess_i,0)); } </code></pre> <p>Its working well for system and curr. user processes but not for NETWORK SERVICE and LOCAL SERVICES and i got null string.please tell how can i get usernames of these processes too. thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload