VB icon

GetComputerInfo

Email
Submitted on: 1/3/2015 1:38:00 AM
By: Merlin Corey (from psc cd)  
Level: Beginner
User Rating: By 6 Users
Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++
Views: 1987
 
     This code allows you to get windows version information, current windows User Name, and Computer Name (utilizing the windows API)... {For people searching: USERNAME COMPUTERNAME WINDOWSVERSION GETVERSION GETVERSIONEX GETUSERNAME GETCOMPUTERNAME} Note: Updated this old code to be actual Win32 code and added the OS version stuff.
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :GetComputerInfo
//**************************************
windows.h
lmcons.h
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: GetComputerInfo
// Description:This code allows you to get windows version information, current windows User Name, and Computer Name (utilizing the windows API)... {For people searching: USERNAME COMPUTERNAME WINDOWSVERSION GETVERSION GETVERSIONEX GETUSERNAME GETCOMPUTERNAME}
Note: Updated this old code to be actual Win32 code and added the OS version stuff.
// By: Merlin Corey (from psc cd)
//
// Assumes:This must be compiled as a windows project; if you're using MSVC++, check the project settings, link section, and change subsystem to "windows".
//**************************************

// Header for windows API
#include <windows.h>
// Header for various defines
#include <lmcons.h>
// Entry function for windows projects
int WINAPI WinMain(HINSTANCE hCur, HINSTANCE hPrev, LPSTR sCmd, int nShow)
{
	// Variable for output buffer
	TCHAR sMsg[1024];
	// Variable for username string
	TCHAR sUserName[UNLEN + 1];
	// Variable to computername string
	TCHAR sCompName[MAX_COMPUTERNAME_LENGTH + 1];
	// Variable for username length
DWORD dwUserName = sizeof(sUserName);
// Variable for compname length
DWORD dwCompName = sizeof(sCompName);
	// Variable for os version structure
	OSVERSIONINFO osver;
	osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
 
	// Get OS Version info
	GetVersionEx(&osver);
	// Get User Name
GetUserName(sUserName, &dwUserName);
// Get Computer Name
GetComputerName(sCompName, &dwCompName);
	// Copy to message buffer
	wsprintf(sMsg, "User %s is currently logged onto computer %s running Windows version %d.%d build %d %s",
		sUserName,
		sCompName, 
		osver.dwMajorVersion, 
		osver.dwMinorVersion, 
		osver.dwBuildNumber,
		osver.szCSDVersion
		);
	// Display information
	MessageBox(NULL, sMsg, "Computer Information", MB_OK | MB_ICONINFORMATION);
// End instance
return (0);
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.