Win32API コンピュータ名を取得する GetComputerName
コンピュータ名を取得するには、GetComputerName関数を用いる。
GetComputerNameのプロトタイプ
BOOL GetComputerName( LPTSTR lpBuffer, // コンピュータ名 LPDWORD lpnSize // 名前バッファのサイズ );
使用例
#include <windows.h> #include <stdio.h> int main() { char szComputerName[256] = {'\0'}; DWORD dwSize = sizeof(szComputerName)/sizeof(szComputerName[0]); if (GetComputerName(szComputerName, &dwSize)) { printf("%s\n", szComputerName); } else { puts("GetComputerName failed."); } return 0; }