#include #include int main() { WCHAR computerName[MAX_COMPUTERNAME_LENGTH + 1]; DWORD computerNameLen = MAX_COMPUTERNAME_LENGTH + 1; if (!GetComputerNameEx(ComputerNameDnsHostname, computerName, &computerNameLen)) { printf("Failed to get computer name, error code %d", GetLastError()); return 1; } char computerNameA[MAX_COMPUTERNAME_LENGTH + 1]; int length = WideCharToMultiByte(CP_UTF8, 0, computerName, -1, computerNameA, sizeof(computerNameA), NULL, NULL); if (length == 0) { printf("Failed to convert computer name to char, error code %d", GetLastError()); return 1; } printf("Computer name: %s\n", computerNameA); return 0; }