c - 如何使用 C 检索当前 Windows 用户登录?

标签 c windows winapi

我是 C 的新手。如何使用 C 检索登录到 Windows 的当前用户?

我知道您可以在 C++ 中通过 Environment::UserName 执行此操作,但不知道如何在 C 中执行此操作。

谢谢:)

最佳答案

您可以使用 GetUserName :

#include <windows.h>
#include <Lmcons.h>

TCHAR username[UNLEN+1];
DWORD len = UNLEN+1;
if (GetUserName(username, &len))
{
    //do something with username
}

关于c - 如何使用 C 检索当前 Windows 用户登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7954959/

相关文章:

c - 用 C 编写一个安全的标记 union

java - 在 Windows 7 上从 Java 启动 CYGWIN 构建的可执行文件失败并显示 "error while loading shared libraries: ?: No such file or directory"

windows - 寻找一种有效的方法来使用 SAN 上的文件检查 Windows 上的文件是否存在

php - HBitmap字节数组到php

c++ - 替换 sleep 直到桌面上的窗口打开

windows - assembly :将某些东西打印到屏幕(到命令行)的最佳方法是什么

c - 尝试在 MacOS 10.7.2 上构建 PROJ.4 库(& rgdal)时出现 "C compiler cannot create executables"

c - printf 不在 eclipse c 的控制台中打印

C:令人惊讶的数组结果

python - 如何制作当前鼠标指针的位图?