PLSQL8.0自動載入器原始碼

cbcgorilla發表於2009-10-14

// PLSQLConsoleLoader.cpp : PLSQL8.0自動載入器

//主要功能:保持PLSQL的試用期為30天不變.
//
// Author: Michael 2009-10-14
////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include
#include
using namespace std;

DWORD DeleteTree(HKEY RootKey, const char *pSubKey)
{

HKEY hKey;
DWORD nRet;
DWORD NameCnt,NameMaxLen;
DWORD KeyCnt,KeyMaxLen,MaxDateLen;
static char sFormat[256] = "";
strcat(sFormat, "----");

static int dwDeep = -1;
dwDeep++;

nRet=RegOpenKeyEx(RootKey,pSubKey,0,KEY_ALL_ACCESS,&hKey);
if(nRet!=ERROR_SUCCESS)
{
cout< return 0;
}

nRet = RegQueryInfoKey(hKey,NULL,NULL,NULL,&KeyCnt,&KeyMaxLen,NULL,&NameCnt,
&NameMaxLen,&MaxDateLen,NULL,NULL);
if(nRet == ERROR_SUCCESS)
{
for(int dwIndex = KeyCnt - 1; dwIndex >= 0; dwIndex--) //列舉鍵值
{
char sKeyName[256] = "";
RegEnumKey(hKey, dwIndex, sKeyName, sizeof(sKeyName));

HKEY hKeySub;
DWORD KeyCntSub;
char pSubKeyTemp[256] = "";
strcpy(pSubKeyTemp, pSubKey);
strcat(pSubKeyTemp, "");
strcat(pSubKeyTemp, sKeyName);

nRet = RegOpenKeyEx(RootKey,pSubKeyTemp,0,KEY_ALL_ACCESS,&hKeySub);
if(nRet == ERROR_SUCCESS)
{
nRet = RegQueryInfoKey(hKeySub,NULL,NULL,NULL,&KeyCntSub,&KeyMaxLen,NULL,&NameCnt,
&NameMaxLen,&MaxDateLen,NULL,NULL);
if(nRet == ERROR_SUCCESS)
{
if (KeyCntSub != 0)
{
DeleteTree(RootKey, pSubKeyTemp);
}
RegCloseKey(hKeySub);
}
}

// cout << sFormat << sKeyName << endl;

RegDeleteKey(RootKey ,pSubKeyTemp);
}

RegCloseKey(hKey);
}

// sFormat[strlen(sFormat) - 4] = 0;

if (dwDeep == 0)
{
RegDeleteKey(RootKey ,pSubKey);
}

return 0;
}

int main(int argc, char* argv[])
{
DeleteTree(HKEY_CURRENT_USER, "SoftwareAllround Automations");
DeleteTree(HKEY_CURRENT_USER, "SoftwareMicrosoftSecurity");

char chPath[301];
::GetCurrentDirectory(300,(LPTSTR)chPath);//得到當前目錄
char path[200]= "plsqldev.exe";
strcat(chPath,path);
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &pi, sizeof(pi) );
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);

// Start the child process
if(CreateProcess(chPath, "", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
{
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
else
{
cout< HANDLE hProcess = GetCurrentProcess();//get current process
TerminateProcess(hProcess,0); //close process
}

system("pause");
return 0;
}

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8700374/viewspace-1027839/,如需轉載,請註明出處,否則將追究法律責任。

相關文章