程序控

IPPP (Institute of Penniless Peasent-Programmer) Fellow

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: :: 管理 ::

可能不少在沙盘(Sandboxie)里运行QQ的同学都会遇到这样的问题:

先把QQ装在沙盘里,然后把QQ的安装文件夹复制到另一个地方,清空沙盘,再从沙盘中启动QQ:

QQ出错

经过排除法查找,确定这个问题是由于两个安全组件(COM)没有注册引起的。这两个组件的动态链接库文件分别是安装在以下目录的SSOCommon.dll和SSOPlatform.dll

c:\program files\common\tencent\TXSSO\版本号\bin\

为了解决这个问题,写了一个简单的QQ启动器,把它放在QQ的bin目录下,在沙盘里运行它就可以自动注册这两个组件,并自动启动QQ了。是代码附在下面仅供参考,编译需要项目文件支持。

点击这里下载配置好的项目文件包(VS2008)

点击这里下载编译好的程序

注意,我当前版本的TXSSO是1.2.1.38。如果你的QQ不是这个版本,请将项目里的两个dll替换成你的QQ里附带的版本,并重新编译。

#include <tchar.h>
#include <windows.h>
#include <atlstr.h>
#include <shlobj.h>
#include "resource.h"

HKEY CreateKey(LPCTSTR lpKey)
{
	HKEY hKey;
	DWORD dwDisp;
	RegCreateKeyEx(HKEY_LOCAL_MACHINE, lpKey, 0, NULL,
		REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp);
	return hKey;
}

void SetValue(HKEY hKey, LPCTSTR lpName, LPCTSTR lpValue)
{
	CString strValue(lpValue);
	if (lpName)
	{
		RegSetValueEx(hKey, lpName, 0, REG_SZ, (LPBYTE)(LPCTSTR)strValue,
			strValue.GetLength() * sizeof(TCHAR));
	}
	else
	{
		RegSetValue(hKey, NULL, REG_SZ, strValue, strValue.GetLength());
	}
}

void SaveResourceFile(LPCTSTR lpType, DWORD dwResId, LPCTSTR lpFileName)
{
	DWORD dwRet;
	HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(dwResId), lpType);
	HGLOBAL hResMem = LoadResource(NULL, hResInfo);
	DWORD dwSize = SizeofResource(NULL, hResInfo);
	LPVOID lpData = LockResource(hResMem);
	HANDLE hDllFile = CreateFile(lpFileName, GENERIC_WRITE, 0, NULL,
		CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	WriteFile(hDllFile, lpData, dwSize, &dwRet, NULL);
	CloseHandle(hDllFile);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine, int nCmdShow)
{
	CString strRoot, strSubPath, strFile;
	SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES_COMMON,
		NULL, SHGFP_TYPE_CURRENT, strRoot.GetBuffer(MAX_PATH));
	strRoot.ReleaseBuffer();
	strRoot += _T("\\Tencent\\");
	CreateDirectory(strRoot, NULL);
	strRoot += _T("TXSSO\\");
	CreateDirectory(strRoot, NULL);
	strRoot += _T("1.2.1.38\\");
	CreateDirectory(strRoot, NULL);
	strRoot += _T("Bin\\");
	CreateDirectory(strRoot, NULL);


	SaveResourceFile(_T("DLLFILE"), IDR_DLL_SSOCOMMON,
		strRoot + _T("SSOCommon.dll"));
	SaveResourceFile(_T("DLLFILE"), IDR_DLL_SSOPLATFORM,
		strRoot + _T("SSOPlatform.dll"));

	HKEY hKey;

	hKey = CreateKey(_T("SOFTWARE\\TENCENT\\TXSSO"));
	SetValue(hKey, _T("Version"), _T("1.2.1.38"));
	RegCloseKey(hKey);

	hKey = CreateKey(_T("SOFTWARE\\Classes\\SSOAxCtrlForPTLogin.SSOForPTLogin2"));
	SetValue(hKey, NULL, _T("SSOForPTLogin2 Class"));
	RegCloseKey(hKey);

	hKey = CreateKey(_T("SOFTWARE\\Classes\\SSOAxCtrlForPTLogin.SSOForPTLogin2\\CLSID"));
	SetValue(hKey, NULL, _T("{EAAED308-7322-4b9b-965E-171933ADD473}"));
	RegCloseKey(hKey);

	hKey = CreateKey(_T("SOFTWARE\\Classes\\SSOAxCtrlForPTLogin.SSOForPTLogin2\\CurVer"));
	SetValue(hKey, NULL, _T("SSOAxCtrlForPTLogin.SSOForPTLogin.2"));
	RegCloseKey(hKey);

	ShellExecute(NULL, _T("open"), _T("QQ.exe"), NULL, NULL, SW_SHOW);

	return 0;
}

 

posted on 2012-03-10 20:11  Devymex  阅读(7238)  评论(0编辑  收藏  举报