Windows Programming/Windows API

윈도우 시스템 이름 얻어오기 (GetHostName API)

Privat3 2021. 8. 6. 14:17

GetHostName API MSDN 주소

- https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcomputernamea

 

GetComputerNameA function (winbase.h) - Win32 apps

Retrieves the NetBIOS name of the local computer. This name is established at system startup, when the system reads it from the registry.

docs.microsoft.com

 

 

#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>

#define MAX_LEN 1024

int main(void)
{
	DWORD dwSize = MAX_LEN;
	CHAR strHostName[MAX_LEN] = { 0, };
	INT	nError = GetComputerName(strHostName, &dwSize);

	if (nError == 0)
	{
		printf("GetComputerNameW() Error Code : %d\n",GetLastError());
		return 0;
	}
	
	printf("HostName : %s\n", strHostName);

	return 0;
}