IE11のソースエディタの変更 / VBScript

最新の IE11 では、HKEY_CURRENT_USER でしか動作しないようです。





全て VBScript のみで実行しています。ですから、ファイル参照ウインドウの表示が、現在表示しているウインドウに隠れたりする場合があるので注意して下さい。

ieSrcEditor.wsf をエクスプローラから実行すると、ファイルを参照するダイアログが開きます。内部のコードは以下のようになっていますが、必要な関数等はインターネット上に保存して使用しています。ここでは、ローカルのファイルを開いてパスを取得する為に、InternetExplorer.Application を使用しています。

アンインストールは、zip 内の uninstall.reg か 以下のテキストを uninstall.reg として shift_jis か Unicode で保存してエクスプローラから実行します。内部は、Microsoft の仕様によるレジストリエントリの削除記述となっています。ですから、実際削除を行うのは、regedit.exe です。
Windows Registry Editor Version 5.00

[-HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\View Source Editor]


▼ 実行用のソースコードです
<JOB>
<COMMENT>
************************************************************
 WEB WSH 実行スケルトン
************************************************************
</COMMENT>

<COMMENT>
************************************************************
 外部スクリプト定義
************************************************************
</COMMENT>
<SCRIPT
	language="VBScript"
	src="http://lightbox.in.coocan.jp/laylaClass.vbs">
</SCRIPT>

<SCRIPT language=VBScript>
' 管理者として実行を強制する
Set obj = Wscript.CreateObject("Shell.Application")
if Wscript.Arguments.Count = 0 then
	obj.ShellExecute "wscript.exe", WScript.ScriptFullName & " runas", "", "runas", 1
	Wscript.Quit
end if

' ***********************************************************
' 処理開始
' ***********************************************************
Call laylaFunctionTarget( "http://lightbox.in.coocan.jp/" )
Call laylaLoadFunction( "baseFunction.vbs" )
Call laylaLoadFunction( "wmiReg.vbs" )
Call laylaLoadFunction( "toolFunction.vbs" )

' **********************************************************
' エディタ選択
' **********************************************************
strValue = OpenLocalFileName
if strValue = "" then
	Wscript.Quit
end if

' **********************************************************
' レジストリ
' **********************************************************
strPath = "SOFTWARE\Microsoft\Internet Explorer\View Source Editor\Editor Name"
Call WMIRegCreateKey( HKEY_CURRENT_USER, strPath )
strValue = Dd( strValue )
Call WMIRegSetStringValue( HKEY_CURRENT_USER, strPath, Empty, strValue )

MsgOk( strValue & " を IE のソースエディタとして登録しました" )

Function OpenLocalFileName( )

	Call GetObj( "IEDocument", "InternetExplorer.Application" )
	IEDocument.Navigate( ScriptDir( ) & "\local.htm" )
	IEDocument.document.getElementsByTagName("BODY")(0).innerHTML = "<input id=FilePath type=file>"
	IEDocument.document.getElementById("FilePath").click
	if IEDocument.document.getElementById("FilePath").value = "" then
		OpenLocalFileName = ""
		IEDocument.Quit
		Set IEDocument = Nothing
		Exit Function
	end if

	OpenLocalFileName = IEDocument.document.getElementById("FilePath").value

	IEDocument.Quit
	Set IEDocument = Nothing

End Function
</SCRIPT>
</JOB>






IE11, VBScript, ツール

IE11 で Excel のブックにアクセスする / JavaScript を使用して Excel のブックのセルにデータをセットして更新

⭕ まず、信頼するサイトlocalhost( またはイントラネットのサーバ ) を登録します。



⭕ レベルのカスタマイズで『スクリプトを実行しても安全だとマークされていないActiveX コントロール』を『有効』にします。



▼ 以下の .reg ファイルをエクスプローラからダブルクリックしてインポートする事もできます
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2]
"1201"=dword:00000000

▼ .reg ファイルをダウンロード
その上で以下のコードを localhost で実行が可能です。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-type" content="text/html; charset=shift_jis">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>

// *************************************
// IE 用オブジェクト作成関数
// *************************************
function newObject( className ) {

	var obj;

	try {
		obj = new ActiveXObject( className );
	}
	catch (e) {
		obj = null;
	}

	return obj;

}

// *************************************
// Excel 用オブジェクト 格納変数
// *************************************
var excelApp = null;
var myBook = null;

// *************************************
// Exce ブックを読み込んで更新して終了
// *************************************
function excelTest() {

	// Excel オブジェクト作成
	if ( excelApp == null ) {
		 excelApp = newObject("Excel.Application");
	}

	// Excel ブックの読み込み
	myBook = excelApp.Workbooks.Open("C:\\Users\\lightbox\\Documents\\Book1.xlsx");

	// アクティブなウィンドウを最大化
	excelApp.ActiveWindow.WindowState = 2;
	// 表示時様態にする
	excelApp.Visible = true;

	// jQuery でオブジェクトの一覧を取得して Excel のセルに情報をセットする
	var row = 0;
	$.each( window.navigator, function( key, value ){

		row++;
		// シートのセルに書き込み
		myBook.Sheets("Sheet1").Cells(row, 1) = key;
		myBook.Sheets("Sheet1").Cells(row, 2) = typeof value;
		myBook.Sheets("Sheet1").Cells(row, 3) = value;

	});

	// 保存
	myBook.Save();

	// Excel の終了
	if ( excelApp != null ) {
		excelApp.Quit();
		excelApp = null;
	}

}

</script>
</head>
<body>
<input id="export" type="button" value="Excel のテスト" onclick="excelTest();">
</body>
</html>