阅读:2078回复:9
如何在内核下获得操作系统当前登录用户名
如题
|
|
沙发#
发布于:2007-05-11 11:39
驱动程序单干的时候,简单的事情也干不了
![]() |
|
|
板凳#
发布于:2007-05-11 12:19
获取 explorer.exe 进程的token,然后sid , 然后用户名
相关的api: ZwOpenProcess ZwOpenProcessToken ZwQueryInformationToken SeLookupAccountSid 最后一个函数貌似win2000下没有 |
|
|
地板#
发布于:2007-05-11 12:33
可以通过访问Winlogon的内存读取
这个非正路请勿学习和研究~ |
|
|
地下室#
发布于:2007-05-11 12:38
不同进程可以在不同的账户下运行。
切换到该进程搜索peb->ProcessParameters->Environment中的USERNAME环境变量。。。 |
|
5楼#
发布于:2007-05-11 12:47
引用第4楼Odyssey于2007-05-11 12:38发表的“”: 主意不错! |
|
|
6楼#
发布于:2007-05-11 13:33
用 token 取时,要注意多用户登录
|
|
7楼#
发布于:2007-05-14 13:23
搜了下网页,有这个方法
BOOLEAN GetUserName(PSECURITY_SUBJECT_CONTEXT securitySubjectContext, PUNICODE_STRING userName) { PACCESS_TOKEN token; LUID luid; PSecurityUserData userInformation = NULL; NTSTATUS status; //初始化userName userName->Length = 0; userName->MaximumLength = 0; userName->Buffer = NULL; //取token token = SeQuerySubjectContextToken(securitySubjectContext); //根据token查询用户的LUID status = SeQueryAuthenticationIdToken(token, &luid); if (!NT_SUCCESS(status)) { KdPrint(("GetUserName(): SeQueryAuthenticationIdToken fail\n")); return FALSE; } //特殊情况,SYSTEM用户 if(luid.LowPart==SYSTEMACCOUNT_LOW && luid.HighPart==SYSTEMACCOUNT_HIGH) { userName->Length = 12; userName->MaximumLength = 12; userName->Buffer = ExAllocatePool(NonPagedPool, userName->MaximumLength); if (userName->Buffer==NULL) { KdPrint(("GetUserName(): ExAllocatePool fail\n")); return FALSE; } RtlCopyMemory(userName->Buffer, SYSTEMUSER, userName->MaximumLength); return TRUE; } //根据用户的luid取用户名 status = GetSecurityUserInfo(&luid, UNDERSTANDS_LONG_NAMES, &userInformation); if (!NT_SUCCESS(status)) { KdPrint(("GetUserName(): GetSecurityUserInfo fail\n")); return FALSE; } userName->Length = 0; userName->MaximumLength = userInformation->UserName.Length; userName->Buffer = ExAllocatePool(NonPagedPool, userName->MaximumLength); if (userName->Buffer==NULL) { KdPrint(("GetUserName(): ExAllocatePool fail\n")); return FALSE; } RtlCopyUnicodeString(userName, &userInformation->UserName); LsaFreeReturnBuffer(userInformation); return TRUE; } 试了下,死机!! :( xp sp2 |
|
8楼#
发布于:2007-07-25 17:27
有更好的 办法没
|
|
9楼#
发布于:2007-09-29 09:46
有,但是没人说
|
|