VB icon

Half-Life CD-KEY Changer

Email
Submitted on: 1/5/2015 10:19:00 AM
By: Dummy52 (from psc cd)  
Level: Beginner
User Rating: By 3 Users
Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++, UNIX C++
Views: 3540
 
     The purpose of this code is to demonstrate the Windows API registry functions. Using these functions, I put together a short program for fellow Half-Life gamers to easily change their cd-key without editing the registry via regedit.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Half-Life CD-KEY Changer
// Description:The purpose of this code is to demonstrate the Windows API registry functions. Using these functions, I put together a short program for fellow Half-Life gamers to easily change their cd-key without editing the registry via regedit.
// By: Dummy52 (from psc cd)
//
// Inputs:The program paramaters are optional. The paramaters make it faster to change your cdkey, and are used as: <program>.exe <new-cdkey>
//**************************************

/*************************************************
 * Half-Life CD-KEY Changer
 * Author: Devin McLean
 * Contact via IRC: GamesNET #team-de
*************************************************/
#include <stdio.h>
#include <windows.h>
int main(int argc, char *argv[])
{
	HKEY hKey;
	LONG lRet;
	unsigned char dwData[14];
	char newKey[14];
	DWORD dwSize = 14;
	
	memset(newKey,0,14);
	if (argc > 2)
	{
		printf("\nToo many params.\n");
		return 0;
	}
	else if (argc == 2)
	{
		if (strlen(argv[1]) != 13)
		{
			printf("\nInvalid Half-Life CD-KEY!\n");
			return 0;
		}
		strcpy(newKey,argv[1]);
	}
	if ((lRet = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Valve\\Half-Life\\Settings", 0, KEY_ALL_ACCESS, &hKey)) != ERROR_SUCCESS)
	{
		printf("\nCould not find Half-Life installed!\n");
		return 0;
	}
	if ((lRet = RegQueryValueEx(hKey, "Key", NULL, 0, dwData, &dwSize)) != ERROR_SUCCESS)
	{
		RegCloseKey(hKey);
		printf("\nCould not find Half-Life CD-KEY!\n");
		return 0;
	}
	printf("\nCurrent Half-Life CD-KEY: %s\n",dwData);
	if (strlen(newKey) == 0)
	{
		printf("New Half-Life CD-KEY: ");
		scanf("%s",newKey);
		if (strlen(newKey) != 13)
		{
			printf("\nInvalid Half-life CD-KEY!\n");
			RegCloseKey(hKey);
			return 0;
		}
		fflush(stdin);
	}
	if ((lRet = RegSetValueEx(hKey, "Key", 0, REG_SZ, (LPBYTE) newKey, dwSize)) != ERROR_SUCCESS)
	{
		RegCloseKey(hKey);
		printf("\nCould not set Half-Life CD-KEY!\n");
		return 0;
	}
	RegCloseKey(hKey);
	printf("\nHalf-Life CD-KEY successfully changed to: %s\n",newKey);
	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.