visual studio - Get Process Username c++ -
i making taskmanager app. windows,i can system processes,now want process's username.i got code net.
void enabledebugprivileges() { handle hcurrent=getcurrentprocess(); handle htoken; bool bret=openprocesstoken(hcurrent,40,&htoken); luid luid; bret=lookupprivilegevalue(null,se_load_driver_name, &luid); token_privileges newstate,previousstate; dword returnlength; newstate.privilegecount =1; newstate.privileges[0].luid =luid; newstate.privileges[0].attributes=2; adjusttokenprivileges(htoken,false,&newstate,28,&previousstate,&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 null process handle of //process. hprocess = phprocess?*phprocess:getcurrentprocess(); //open processes token if (!openprocesstoken(hprocess,token_query,&tok)) goto ert; //get sid of token ptu = (token_user*)tubuf; if (!gettokeninformation(tok,(token_information_class)1,ptu,300,&nlen)) goto ert; //get account/domain name of sid dlen = 300; nlen = 300; if (!lookupaccountsida(0, ptu->user.sid, name, &nlen, dom, &dlen, (psid_name_use)&iuse)) goto ert; //copy info our static buffer if (dlen && 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(&hprocess_i,0)); }
its working system , curr. user processes not network service , local services , got null string.please tell how can usernames of these processes too. thanks.
iirc there's separate pseudo account called localservice, not in normal security system (hence null string). there's networkservice account.
Comments
Post a Comment