C++ GetComputerName()

时间:2023-03-09 06:51:32
C++ GetComputerName()

关于函数“GetComputerName()”,参考:https://msdn.microsoft.com/en-us/library/windows/desktop/ms724295(v=vs.85).aspx

关于“Computer Names”,参考:https://msdn.microsoft.com/en-us/library/windows/desktop/ms724220(v=vs.85).aspx

代码摘自“Getting System Information”,参考:https://msdn.microsoft.com/en-us/library/windows/desktop/ms724426(v=vs.85).aspx

关于“Windows Data Types”,参考:https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx

IDE: Code::Blocks

操作系统:Windows 7 x64

 #include <stdio.h>
#include <tchar.h>
#include <windows.h> #define INFO_BUFFER_SIZE (MAX_COMPUTERNAME_LENGTH + 1) int main()
{
CHAR infoBuf[INFO_BUFFER_SIZE];
DWORD bufCharCount = INFO_BUFFER_SIZE; // Get and display the name of the computer.
if( GetComputerName( infoBuf, &bufCharCount ) ) {
_tprintf( "The NetBIOS name of the local computer is %s \n", infoBuf );
}
else {
_tprintf( "Get NetBIOS name of the local computer failed with error %lu \n", GetLastError() );
} return ;
}