www.gusucode.com > 一些VC++加密算法+实例源码源码程序 > 一些VC++加密算法+实例源码/优化后的加密注册模块/优化后的加密注册模块/ArkoReg(optimized)/Register.cpp

    //Register.cpp
// Download by http://www.codesc.net
#include "StdAfx.h"
#include "Register.h"


//******************************************************************************
int QuerySerial(char * SerialNumber)
{
	HKEY hSearchKey = HKEY_LOCAL_MACHINE;
	char lpSubKey[256] = "SOFTWARE\\Microsoft\\Saini";	//this subkey is established when installed
	long lCode;
	DWORD dw=30;
	char str[30];	//save the serial number


	lCode = RegOpenKey(hSearchKey, lpSubKey, &hSearchKey);	//open the key
	if(lCode != ERROR_SUCCESS)
		return 1;
	else
	{
		lCode = RegQueryValueEx(hSearchKey, "Saini", 0,
							    NULL, (unsigned char *)str, &dw);		//query the SerialNumber
		if(lCode != ERROR_SUCCESS)
			return 1;
	}

	lstrcpy(SerialNumber, str);

	return 0;
}


//******************************************************************************
int WINAPI GetProductId(char * ProdID/*BSTR *ProdID*/)
{
	HKEY hSearchKey = HKEY_LOCAL_MACHINE;
	char lpSubKey[256] = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";	//the subkey that has ProductId
	long lCode;
	char str[30];	//save the product id
	DWORD dw=30;

	CRegKey reg;
	lCode = reg.Open(hSearchKey, lpSubKey, KEY_ALL_ACCESS);	//open the key
	if(lCode!=ERROR_SUCCESS)
		return 1;
	else
	{
		lCode = reg.QueryValue((LPTSTR)str, "ProductId", &dw);	//query the ProductId
		if(lCode!=ERROR_SUCCESS)
			return 1;
	}
//	memcpy(ProdID, str, sizeof(str));
	strcpy(ProdID, str);

	return 0;
}


//******************************************************************************
int WINAPI ConnectWeb()
{
	char prod[30], serial[20], url[256];

	if( GetProductId(prod) )		//get ProductId
		return ERROR_PROID;

	if( QuerySerial(serial) )		//get SerialNumber
		return ERROR_SERNO;

	sprintf((char *)url, "http://192.100.1.210/Welcome.asp?ProdID=%s&SerialNO=%s", prod, serial);

	HWND hWnd=GetDesktopWindow();	//get window handle
	if(hWnd==INVALID_HANDLE_VALUE)
		return ERROR_HANDLE;

	ShellExecute(hWnd, "open", url, NULL, NULL, SW_SHOWNORMAL);		//make IE active

	return 0;
}


//******************************************************************************
int WINAPI FinishReg(char *Code)
{
	if(lstrcmp(Code,"")==0)
		return INVALID_CODE;
	char RegCode[129];
	lstrcpy((char *)RegCode, Code);

	HKEY hKey = HKEY_LOCAL_MACHINE;
	char lpSubKey[256] = "SOFTWARE\\Microsoft";
	long lReg;

	lReg = RegOpenKeyEx(hKey, lpSubKey, 0,
						KEY_ALL_ACCESS, &hKey);
	if(lReg != ERROR_SUCCESS)
		return INVALID_REGKEY;
	else
	{
		DWORD Disposition;
		lReg = RegCreateKeyEx(hKey, "Regca", 0,
							  NULL, REG_OPTION_NON_VOLATILE,
							  KEY_ALL_ACCESS, NULL,
							  &hKey, &Disposition);		//create a subkey to save the code
		if(lReg != ERROR_SUCCESS)
			return INVALID_NEWKEY;
		else
		{
			lReg = RegSetValueEx(hKey, "Regca", 0,
								 REG_BINARY, (CONST BYTE *)RegCode, sizeof(RegCode));	//save the code
			if(lReg != ERROR_SUCCESS)
				return INVALID_SETKEY;
		}
	}
	
	return FINISH_REG;
}