信頼するサイトの登録と設定

  Win32 Console Application で MFC の CString を使用



http://winofsql.jp/VA003334/asp051101194921.htm の C++ バージョンです

API のラップ関数は、API の引数の型が明示できるように、引数を参照で定義しています
また、MFC はスタティックライブラリを使用しています

  
#include "stdafx.h"
#include <afx.h>

BOOL LboxOpenReg( HKEY hRoot, LPCTSTR lpSubKey, HKEY &hNew );
BOOL LboxGetDword( HKEY hKey, LPCTSTR lpEntry, DWORD &Value );
BOOL LboxSetDword( HKEY hKey, LPCTSTR lpEntry, DWORD dwValue );

CString domain = "";
CString server = "layla";

int main(int argc, char* argv[])
{
	BOOL bRet;
	HKEY hKey;
	CString strRegPath;

	// *********************************************************
	// このゾーンのサイトには全てサーバーの確認 (https:) を必要とする
	// というチェックを外す
	// *********************************************************
	strRegPath = 
		"Software\\Microsoft\\Windows\\CurrentVersion\\"
		"Internet Settings\\Zones\\2";
	bRet = ::LboxOpenReg(
		HKEY_CURRENT_USER,
		(LPCTSTR)strRegPath,
		hKey
	);

	if ( bRet ) {
		DWORD dw;

		if ( ::LboxGetDword( hKey, "Flags", dw ) ) {
			dw &= 0xfffffffb;
			::LboxSetDword( hKey, "Flags", dw );
		}

		RegCloseKey( hKey );
	}


	// *********************************************************
	// サイトの登録
	// *********************************************************
	strRegPath = 
		"Software\\Microsoft\\Windows\\CurrentVersion\\"
		"Internet Settings\\ZoneMap\\Domains\\";

	if ( domain != "" ) {
		strRegPath += ( domain + "\\" );
	}
	strRegPath += server;

	bRet = ::LboxOpenReg(
		HKEY_CURRENT_USER,
		(LPCTSTR)strRegPath,
		hKey
	);
	
	if ( bRet ) {
		::LboxSetDword( hKey, "http", 2 );
		RegCloseKey( hKey );
	}
	
	// *********************************************************
	// 詳細設定
	// *********************************************************
	strRegPath = 
		"Software\\Microsoft\\Windows\\CurrentVersion\\"
		"Internet Settings\\Zones\\2";
	bRet = ::LboxOpenReg(
		HKEY_CURRENT_USER,
		(LPCTSTR)strRegPath,
		hKey
	);

	if ( bRet ) {
		// ActiveX コントロールとプラグインの実行
		::LboxSetDword( hKey, "1200", 0 );

		// スクリプトを実行しても安全だとマークされていない
		// ActiveX コントロールの初期化とスクリプトの実行
		::LboxSetDword( hKey, "1201", 0 );

		// スクリプトを実行しても安全だとマークされている
		// ActiveX コントロールのスクリプトの実行
		::LboxSetDword( hKey, "1405", 0 );

		// 署名済み ActiveX コントロールのダウンロード
		::LboxSetDword( hKey, "1001", 0 );

		// 未署名の ActiveX コントロールのダウンロード
		::LboxSetDword( hKey, "1004", 0 );

		// 未署名の ActiveX コントロールのダウンロード
		::LboxSetDword( hKey, "1004", 0 );

		// Java アプレットのスクリプト
		::LboxSetDword( hKey, "1402", 0 );

		// アクティブ スクリプト
		::LboxSetDword( hKey, "1400", 0 );

		// スクリプトによる貼り付け処理の許可
		::LboxSetDword( hKey, "1407", 0 );

		// ドメイン間でのデータ ソースのアクセス
		::LboxSetDword( hKey, "1406", 0 );

		RegCloseKey( hKey );
	}

	return 0;
}

// *********************************************************
// レジストリキーの作成
// *********************************************************
BOOL LboxOpenReg( HKEY hRoot, LPCTSTR lpSubKey, HKEY &hNew )
{
	LONG nRet;
	DWORD dwDisposition;

	nRet = RegCreateKeyEx(
		hRoot,
		lpSubKey,
		0,
		NULL,
		REG_OPTION_NON_VOLATILE,
		KEY_ALL_ACCESS,
		NULL,
		&hNew,
		&dwDisposition
	);

	if ( nRet == ERROR_SUCCESS ) {
		return true;
	}
	return false;
}

// *********************************************************
// DWORD 値の取得
// *********************************************************
BOOL LboxGetDword( HKEY hKey, LPCTSTR lpEntry, DWORD &Value )
{
	DWORD nType,nSize;
	LONG nRet;

	nSize = 4;

	nRet = RegQueryValueEx(
		hKey,
		lpEntry,
		NULL,
		&nType,
		(LPBYTE)(&Value),
		(unsigned long *)(&nSize)
	);

	if ( nRet == ERROR_SUCCESS ) {
		return true;
	}
	else {
		return false;
	}
}

// *********************************************************
// DWORDの登録
// *********************************************************
BOOL LboxSetDword( HKEY hKey, LPCTSTR lpEntry, DWORD dwValue )
{
	LONG nRet;
	long nLen;

	nLen = 4;

	nRet =  RegSetValueEx(
		hKey,
		lpEntry,
		0,
		REG_DWORD,
		(const unsigned char *)&dwValue,
		nLen
	);

	if ( nRet == ERROR_SUCCESS ) {
		return true;
	}
	else {
		return false;
	}
}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ