VB icon

Get Some PC Info

Email
Submitted on: 8/18/2016 9:59:46 AM
By: Ben  
Level: Beginner
User Rating: Unrated
Compatibility: C++ (general), Microsoft Visual C++
Views: 845
 
     Hi this is a small project I made to return some computer info such as username, computername temp and system folders and more hope you find the code usfull.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Get Some PC Info
// Description:Hi this is a small project I made to return some computer info such as username, computername temp and system folders and more hope you find the code usfull.
// By: Ben
//**************************************

//Get some computer info example by DreamVB
#include <iostream>
#include <Windows.h>
#include <time.h>
using namespace std;
using std::cout;
using std::endl;
string GetDateTimeNow();
enum MyInfo{
	ICOMPUTER = 0,
	IOS = 2,
	IUSER = 3,
	IWINDIR = 4,
	ITEMP = 5,
	ISYSDIR = 6,
	INOW = 7,
	ICPU = 8
};
string GetDateTimeNow(){
	string s0 = "";
	char sNow[80];
	time_t curtime = time(0);
	struct tm *now = localtime(&curtime);
	//Return date and time.
	itoa(now->tm_hour,sNow,10);
	s0 = sNow;
	s0 += ":";
	itoa(now->tm_min,sNow,10);
	s0 += sNow;
	s0 += ":";
	itoa(now->tm_sec,sNow,10);
	s0 += sNow;
	s0 += " ";
	//
	itoa(now->tm_mday,sNow,10);
	s0 += sNow;
	s0 += "/";
	itoa(now->tm_mday,sNow,10);
	s0 += sNow;
	s0 += "/";
	itoa(now->tm_year+1900,sNow,10);
	s0 += sNow;
	//Clear up
	memset(sNow,0,sizeof(sNow));
	return s0;
}
string GetMyInfo(MyInfo option = ICOMPUTER){
	TCHAR Ret[80];
	wstring test = L"";
	DWORD size = sizeof(Ret) / sizeof(Ret[0]);
	switch(option){
		case ICOMPUTER:
			//Get computer name
			GetComputerName(Ret,&size);
			break;
		case IOS:
			return getenv("OS");
		case IUSER:
			//Get username
			GetUserName(Ret,&size);
			break;
		case IWINDIR:
			GetWindowsDirectory(Ret,size);
			break;
		case ITEMP:
			GetTempPath(size,Ret);
			break;
		case ISYSDIR:
			GetSystemDirectory(Ret,size);
			break;
		case INOW:
			return GetDateTimeNow();
		case ICPU:
			return getenv("PROCESSOR_IDENTIFIER");
	}
	//Covert Ret to wide string
	test = wstring(&Ret[0]);
	//clear
	memset(Ret,0,size);
	//Return string from wide string.
	return string(test.begin(),test.end());	
}
int main(){
	cout << "Your Computer Name is : " << GetMyInfo(ICOMPUTER).c_str() << endl;
	cout << "Your Operateing System is : " << GetMyInfo(IOS).c_str() << endl;
	cout << "Your user name is : " << GetMyInfo(IUSER).c_str() << endl;
	cout << "Your Windows folder is : " << GetMyInfo(IWINDIR).c_str() << endl;
	cout << "Your Temp folder is: " << GetMyInfo(ITEMP).c_str() << endl;
	cout << "Your System folder is : " << GetMyInfo(ISYSDIR).c_str() << endl;
	cout << "Time and Date : " << GetMyInfo(INOW).c_str() << endl;
	cout << "Your CPU is: " << GetMyInfo(ICPU).c_str() << endl;
	system("pause");
	return 1;
}


Other 50 submission(s) by this author

 


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.