Obtain system information-user name. Computer Name, operating system name

Source: Internet
Author: User
// Obtain the user name
Updatedata ();
Char username [max_path];
Cstring strusername;
DWORD size = max_path;
: GetUserName (username, & size );
Strusername. Format ("% s", username );
M_username = strusername;
Updatedata (false );
//----------------------------------------------------------------
// Obtain the computer name
Updatedata ();
Char computername [max_path];
Cstring strcomputerusername;
DWORD size1 = max_path;
: Getcomputername (computername, & size1 );
Strcomputerusername. Format ("% s", computername );
M_computername = strcomputerusername;
Updatedata (false );
//----------------------------------------------------------------
// Obtain the computer operating system name
Updatedata ();
Hkey;
Lpctstr strkey = "SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion ";
If (error_success ==:: regopenkeyex (HKEY_LOCAL_MACHINE, strkey, null, key_all_access, & hkey ))
{
DWORD dwsize = 225, dwtype = REG_SZ;
Char string [50]; // computer operating system name
Char string1 [20]; // computer OS Version Number
// Char string2 [256]; // name of the computer operating system version
Lpcstr keyValue = "productname"; // computer operating system name
Lpcstr keyvalue1 = "CurrentVersion"; // computer OS Version Number
// Lpcstr keyvalue2 = "currentbuildname"; // name of the computer operating system version
If (error_success =: regqueryvalueex (hkey, keyValue, 0, & dwtype, (byte *) string, & dwsize) & (error_success = :: regqueryvalueex (hkey, keyvalue1, 0, & dwtype, (byte *) string1, & dwsize)/* | (error_success ==:: regqueryvalueex (hkey, keyvalue2, 0, & dwtype, (byte *) string2, & dwsize ))*/)
{
Cstring strdata = string; // computer operating system name
Cstring strdata1 = string1; // computer OS Version Number
// Cstring strdata2 = string2; // name of the computer operating system version
M_winsysname = strdata + "" + strdata1; // + "" + strdata2;
}
: Regclosekey (hkey );
}
Updatedata (false );
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.