Get system information

zhaozj2021-02-16  103

// Display system information #include #include

#define buffsize 1024

void main () {LPTSTR lpszSystemInfo; // pointer to system information string // DWORD is a 32bit unsigned integer // It is very useful in windows programming DWORD cchBuff = BUFSIZE; // size of computer or user name TCHAR tchBuffer [BUFSIZE] ;

DWORD DWRESULT;

Lpszsysteminfo = tchbuffer; / * getComputername and getUsername prototypes are (LPSTR SZBUFF, DWORD * DWSIZE); the first parameter is a character buffer, the second parameter is a DWORD pointer, indicating the number of bytes of SZBuff When the function exits, DWSIZE is the number of bytes of SZBuff, therefore, after the first calling getUserName, cchbuff is the number of characters of ComputerName. If this length is less than username, the second getUserName will call unsuccessful, so the CCHBUFF reset * / if (GetComputerName (lpszSystemInfo, & cchBuff)) printf ( "Computer name:% s / n", lpszSystemInfo); cchBuff = BUFSIZE; if (GetUserName (lpszSystemInfo, & cchBuff)) printf ( "User name:% s / n", Lpszsysteminfo;

IF (GetSystemDirectory (LpszsystemInfo, Max_Path 1)) Printf ("System Directory:% S / N", LpszsystemInfo;

if (GetWindowsDirectory (lpszSystemInfo, MAX_PATH 1)) printf ( "Windows directory:% s / n", lpszSystemInfo); // display the environment variabless printf ( "Environment variables / n"); // expand os environment variable dwResult = ExpandenvironmentStrings ("OS =% OS%", LPSZSYSTEMINFO, BUFSIZE); if (DWRESULT <= BUFSIZE) Printf ("% S / N", LPSZSYSTEMINFO);

DWRESULT = ExpandenvironmentStrings ("Path =% Path%", LPSZSYSTEMINFO, BUFSIZE); if (dwresult <= bufsize) Printf ("% s / n", lpszsysteminfo);

转载请注明原文地址:https://www.9cbs.com/read-11173.html

New Post(0)