#include <windows.h>
#include <stdio.h>
#define BUFSIZE 1024
void main()
{
LPTSTR lpszSystemInfo; // pointer to system information string
DWORD cchBuff = BUFSIZE; // size of computer or user name
TCHAR tchBuffer[BUFSIZE]; // buffer for string
DWORD dwResult; // function return value
lpszSystemInfo = tchBuffer;
// Get and display the name of the computer.
if( GetComputerName(lpszSystemInfo, &cchBuff) )
printf("Computer name: %s/n", lpszSystemInfo);
// Get and display the user name.
cchBuff = BUFSIZE;
if( GetUserName(lpszSystemInfo, &cchBuff) )
printf("User name: %s/n/n", lpszSystemInfo);
// Get and display the system directory.
if( GetSystemDirectory(lpszSystemInfo, MAX_PATH+1) )
printf("System directory: %s/n", lpszSystemInfo);
// Get and display the Windows directory.
if( GetWindowsDirectory(lpszSystemInfo, MAX_PATH+1) )
printf("Windows directory: %s/n/n", lpszSystemInfo);
// Display the "environment variables" header.
printf("Environment variables (partial list): /n");
// Expand the OS environment variable.
dwResult = ExpandEnvironmentStrings(
"OS=%OS%",
lpszSystemInfo,
BUFSIZE);
if( dwResult <= BUFSIZE )
printf(" %s/n", lpszSystemInfo);
// Expand the PATH environment variable.
dwResult = ExpandEnvironmentStrings(
"PATH=%PATH%",
lpszSystemInfo,
BUFSIZE);
if( dwResult <= BUFSIZE )
printf(" %s/n", lpszSystemInfo);
// Expand the TMP environment variable.
dwResult = ExpandEnvironmentStrings(
"TEMP=%TEMP%",
lpszSystemInfo,
BUFSIZE);
if( dwResult <= BUFSIZE )
printf(" %s/n", lpszSystemInfo);
}