服務如何獲取當前登入的windows使用者名稱

2021-08-04 05:37:16 字數 918 閱讀 6490

如何獲取當前登入的windows使用者名稱?

在win7裡,可以有多個explorer同時執行,那通過explorer來獲取當前正在使用的使用者名稱就不準確了,getusername()也不行,應為我這個是服務,wtsquerysessioninformation同時也不適用,許多的系統都不支援,各位還有什麼好辦法麼?

------解決方案--------------------

int gethostname(

char* name,

int namelen

);------解決方案--------------------

void get_loguser(char *lpusername,dword nnamelen)

fresult = openprocesstoken(hproc, token_query, &htoken);

if(!fresult) 

dword dwneedlen = 0;

fresult = gettokeninformation(htoken,tokenuser, null, 0, &dwneedlen);

if (dwneedlen > 0)

}else

sid_name_use sn;

tchar szdomainname[max_path];

dword dwdmlen = max_path;

fresult = lookupaccountsid(null, ptokenuser->user.sid, lpusername, &nnamelen,

szdomainname, &dwdmlen, &sn);

}__finally

} ------解決方案--------------------

我的是win7系統 你進cmd 然後輸入 set username 就顯示了..

oracle如何獲取當前登入的使用者名稱

c sqlplus sql plus release 9.2.0.1.0 production on 星期三 5月 30 00 04 26 2007 請輸入使用者名稱 scott 請輸入口令 連線到 oracle9i enterprise edition release 9.2.0.1.0 prod...

獲取當前vue物件 Vue檔案如何獲取當前例項?

1.首先你已經用了vue,那麼你就應該上es6的寫法,2.你的data寫的有問題,data裡面放上了方法怎麼能拿到this,你可以考慮換乙個外掛程式 3.如果你真要這麼做的話 如下實現 export default name calendar data let this this return mo...

PHP 如何獲取url當前的伺服器變數

1,server query string 說明 查詢 query 的字串 2,server request uri 說明 訪問此頁面所需的uri 3,server script name 說明 包含當前指令碼的路徑 4,server php self 說明 當前正在執行指令碼的檔名 例項 1,直接...