Exemple #1
0
BOOL CRegistry::SetDword(LPCTSTR pszSection, LPCTSTR pszName, DWORD nValue, LPCTSTR pszSubKey)
{
	CString strSection( pszSubKey ? pszSubKey : _T("Software\\PeerProject\\PeerProject") );
	if ( pszSection && *pszSection )
	{
		if ( pszSection[0] != _T('\\') )
			strSection += _T("\\");
		strSection += pszSection;
	}

	LONG nErrorCode = SHRegSetUSValue( (LPCTSTR)strSection, pszName, REG_DWORD,
		(LPCVOID)&nValue, sizeof( nValue ), SHREGSET_FORCE_HKCU );
	return ( nErrorCode == ERROR_SUCCESS );
}
Exemple #2
0
BOOL CRegistry::SetString(LPCTSTR pszSection, LPCTSTR pszName, LPCTSTR pszValue, LPCTSTR pszSubKey)
{
	CString strSection( pszSubKey ? pszSubKey : _T("Software\\PeerProject\\PeerProject") );
	if ( pszSection && *pszSection )
	{
		if ( pszSection[0] != _T('\\') )
			strSection += _T("\\");
		strSection += pszSection;
	}

	LONG nErrorCode = SHRegSetUSValue( (LPCTSTR)strSection, pszName, REG_SZ,
		(LPCVOID)pszValue, ( lstrlen( pszValue ) + 1 ) * sizeof( TCHAR ), SHREGSET_FORCE_HKCU );
	return ( nErrorCode == ERROR_SUCCESS );
}
// 函数实现
int InstallISISandBox(const wchar_t *aServiceName)
{
	BOOL bOK = FALSE;

	SC_HANDLE hManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if (hManager == NULL)
		goto InstallISISandBox_Error;

	DWORD dwTag = 5;
	SC_HANDLE hService = CreateService (hManager, _T("ISISandBox"), _T("ISISandBox"),
		SERVICE_ALL_ACCESS, SERVICE_FILE_SYSTEM_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
		_T("System32\\drivers\\ISISandBox.sys"), _T("FSFilter Virtualization"), &dwTag, _T("FltMgr"), NULL, NULL);

	if (hService == NULL)
		goto InstallISISandBox_Error;
	else
		CloseServiceHandle (hService);

	// 写注册表(MiniFilter规定的注册表)
	{
		TCHAR chPath[MAX_PATH];
		ZeroMemory(chPath, sizeof(TCHAR)*MAX_PATH);

		CString szAltitude = _T("135678");
		DWORD dwFlags = 0;
		CString szInst = _T("ISISandBox Instance");
		_tcscpy(chPath, szInst.GetString());
		CString szRegPath = _T("SYSTEM\\CurrentControlSet\\Services\\ISISandBox\\Instances");
		SHRegSetUSValue(szRegPath, _T("DefaultInstance"), REG_SZ, chPath, szInst.GetLength()*sizeof(TCHAR), SHREGSET_FORCE_HKLM);

		szRegPath = _T("SYSTEM\\CurrentControlSet\\Services\\ISISandBox\\Instances\\ISISandBox Instance");
		ZeroMemory(chPath, sizeof(TCHAR)*MAX_PATH);
		_tcscpy(chPath, szAltitude.GetString());
		DWORD dwLength = szAltitude.GetLength()*2;
		SHRegSetUSValue(szRegPath, _T(""), REG_SZ, chPath, 0, SHREGSET_FORCE_HKLM);
		SHRegSetUSValue(szRegPath, _T("Altitude"), REG_SZ, chPath, dwLength, SHREGSET_FORCE_HKLM);
		SHRegSetUSValue(szRegPath, _T("Flags"), REG_DWORD, &dwFlags, sizeof(DWORD), SHREGSET_FORCE_HKLM);
	}

	hService = OpenService (hManager, _T("ISISandBox"), SERVICE_ALL_ACCESS);
	if (hService == NULL)
		goto InstallISISandBox_Error;

	BOOL bRet = StartService (hService, 0, NULL);
	if (bRet == FALSE)
		goto InstallISISandBox_Error;

	bOK = TRUE;

InstallISISandBox_Error:

	DWORD dwError = GetLastError();
	if (dwError == ERROR_SERVICE_EXISTS)
	{
		hService = OpenService (hManager, _T("ISISandBox"), SERVICE_ALL_ACCESS);
		if (hService == NULL)
			goto InstallISISandBox_Error;

		bRet = StartService (hService, 0, NULL);
		if (bRet == FALSE)
			goto InstallISISandBox_Error;

		bOK = TRUE;
	}

	if (bOK == FALSE && dwError != ERROR_SERVICE_ALREADY_RUNNING)
	{
		bOK = FALSE;
	}
	else
	{
		bOK = TRUE;
		dwError = 0;
	}

	if (hService != NULL)
		CloseServiceHandle (hService);

	if (hManager != NULL)
		CloseServiceHandle (hManager);

	return dwError;
}