#define _WIN32_WINNT 0x501
#include <WINDOWS.H>
#include <STDIO.H>
#include <LMCons.h>
#include<stdio.h>
void GetName();
//功能获取 计算机名 用户名信息
void GetName()
{
DWORD dwComputerNameLen = MAX_COMPUTERNAME_LENGTH + 1;
DWORD dwUserNameLen = UNLEN + 1;
TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
TCHAR szUserName[UNLEN + 1]; // 在LMCons.h中定义
if(!SetComputerName("My_Computer"))
{
printf("Set error %d ",GetLastError());
}
//获得计算机名
GetComputerNameA(szComputerName,&dwComputerNameLen);
printf("计算机名:%s\n",szComputerName);
dwComputerNameLen = MAX_COMPUTERNAME_LENGTH + 1;
//获得DNS名
GetComputerNameEx(
ComputerNameDnsHostname,
szComputerName,
&dwComputerNameLen);
printf("ComputerNameDnsHostname:%s\n",szComputerName);
dwComputerNameLen = MAX_COMPUTERNAME_LENGTH + 1;
//获得NetBIOS名
GetComputerNameEx(ComputerNamePhysicalNetBIOS,
szComputerName,
&dwComputerNameLen);
printf("ComputerNamePhysicalNetBIOS:%s\n",szComputerName);
//获得用户名
GetUserNameA(szUserName,
&dwUserNameLen);
printf("用户名:%s\n",szUserName);
}
int main()
{
GetName();
return 0;
}