Windows API一日一练(72)GetUserName函数
来源:互联网 发布:mac安装vmware fusion 编辑:程序博客网 时间:2024/05/17 08:17
随着系统安全性的加强,每个系统里越来越多不同的帐号登录。假如你正在开发一个上网安全软件,让不同的用户有不同的上网权限,这样就需要识别当前的用户是什么帐号登录了,然后再作出权限分配。还有出错时,也需要对当前帐号进行记录下来,因为不同的帐号有不同的权限,有些磁盘是不允许操作的。面对这些需求,就需要使用函数GetUserName。
函数GetUserName声明如下:
WINADVAPI
BOOL
WINAPI
GetUserNameA (
__out_ecount_part(*pcbBuffer, *pcbBuffer) LPSTR lpBuffer,
__inout LPDWORD pcbBuffer
);
WINADVAPI
BOOL
WINAPI
GetUserNameW (
__out_ecount_part(*pcbBuffer, *pcbBuffer) LPWSTR lpBuffer,
__inout LPDWORD pcbBuffer
);
#ifdef UNICODE
#define GetUserName GetUserNameW
#else
#define GetUserName GetUserNameA
#endif // !UNICODE
lpBuffer是获取名称缓冲区。
pcbBuffer是缓冲区的大小和返回帐号的大小。
调用函数的例子如下:
#001 //
#002 //获取当前登录用户的名称。
#003 //蔡军生 2007/11/13 QQ:9073204 深圳
#004 void GetUserName(void)
#005 {
#006 //
#007 const int nBufSize = UNLEN + 1;
#008 TCHAR chBuf[nBufSize];
#009 ZeroMemory(chBuf,nBufSize);
#010
#011 //获取当前登录用户的名称
#012 DWORD dwRet = nBufSize;
#013 if (::GetUserName(chBuf,&dwRet))
#014 {
#015 //
#016 OutputDebugString(chBuf);
#017 }
#018 else
#019 {
#020 OutputDebugString(_T("获取登录用户名称出错!"));
#021 }
#022
#023 OutputDebugString(_T("/r/n"));
#024
#025 }
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(78)HeapAlloc函数
- Windows API一日一练(73)GetVersionEx函数
- socket异步处理问题
- (五)Java游戏部署在Windows Mobile平台仿真器(Microsoft)
- Windows API一日一练(77)VirtualAlloc函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(76)GlobalAlloc函数
- 从历史学习的 8 堂架构课
- 经典手机短信笑话
- (四)Java游戏部署在BlackBerry仿真器上(RIM)
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(75)SystemParametersInfo函数
- .Net Remoting中Remote Server的Port占用/释放问题
- (三)Java游戏部署在Symbian平台仿真器上(Nokia)