Registry control software usage

Source: Internet
Author: User

HKEY key;
CString sKeyPath;
SKeyPath = "Software // SoftTryTimeTest ";

If (RegOpenKey (HKEY_CURRENT_USER, sKeyPath, & key )! = 0
& RegOpenKey (HKEY_CURRENT_USER, sKeyPath, & key )! = ERROR_SUCCESS
) // Used for the first time
{
// Record the number of times used in the Registry
: RegCreateKey (HKEY_CURRENT_USER, sKeyPath, & key );
: RegSetValueEx (key, "Try time", 0, REG_SZ, (unsigned char *) "5", 2 );
: RegCloseKey (key );
MessageBox ("You can only use five times", "system prompt", MB_ OK | MB_ICONEXCLAMATION );
}
Else // registry information already exists
{
CString sTryTime;
Int nTryTime;
LPBYTE Data = new BYTE [80];
Dword type = REG_SZ;
DWORD cbData = 80;

// Retrieve the number of times used
: RegQueryValueEx (key, "Try time", 0, & TYPE, Data, & cbData );
STryTime. Format ("% s", Data );
NTryTime = atoi (sTryTime );
If (nTryTime <1)
{
MessageBox ("the maximum number of trials has passed", "system prompt", MB_ OK | MB_ICONSTOP );

Return false;
}
NTryTime --;
STryTime. Format ("% d", nTryTime );
: RegSetValueEx (key, "Try time"
, 0, REG_SZ
, (Unsigned char *) sTryTime. GetBuffer (sTryTime. GetLength ())
, 2 );
: RegCloseKey (key );
MessageBox ("You can try again" + sTryTime + "times! "," System prompt ", MB_ OK | MB_ICONEXCLAMATION );
}

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.