![]()
大昔に作成した COM で、BatchHelper オブジェクト
HTA は 32ビットなので当然動きますが、特殊設定の IE11 でも動作します BatchHelper のメソッド一覧 sample3.hta ファイルに保存するダイアログは、BatchHelper オブジェクトです。一般的な Windows の COM にはありません。それを使用して、Excel のブックを作成するのに、Lbox.BatchWsc( CreateBook ) を使用していますが、これは Windows Script Component と言って、VBScript で書いたコードを COM として登録したものです。ですから、内部では Excel.Application を使用しています。 BatchHelper の Sleep は C++ で書いたもので、Window そのものも停止します。二つ目は、TIMEOUT を起動してその終了を待たせて Sleep をしていますが、Window の処理(メッセージ)は止まりません。 最後は、ADOX で Access の .accdb ファイルを作成しています。
<!DOCTYPE html> <html> <head> <meta http-equiv="x-ua-compatible" content="ie=edge" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" /> <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css"> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <script src="https://winofsql.jp/hta.js"></script> <script> // ウインドウの位置とサイズ centerWindow( 1100, 600 ); // テーブルの行作成用 var row_data = ""; // WSH 標準 var WshShell = newObject("WScript.Shell"); var WshNetwork = newObject("WScript.Network"); // 連想配列=ハッシュ=ディクショナリ var Dict = newObject("Scripting.Dictionary"); // DB var AdoCn = newObject("ADODB.Connection"); var AdoRs = newObject("ADODB.Recordset"); var AdoCat = newObject("ADOX.Catalog"); // バイナリデータ var AdoStream = newObject("ADODB.Stream"); // Windows Shell var objShell = newObject("Shell.Application"); // テキストファイル var Fso = newObject("Scripting.FileSystemObject"); // メール送信 var Cdo = newObject("CDO.Message"); // 通信 var Http = newObject("Msxml2.ServerXMLHTTP"); // Base64 var Util = newObject("CAPICOM.Utilities"); // その他 var Guid = newObject("Scriptlet.TypeLib"); // 以下 要インストール var Helper = newObject("Lbox.BatchHelper"); var HelperWsc = newObject("Lbox.BatchWsc"); $(function(){ // *************************** // ボタン表示位置微調整 // *************************** $( ".btn" ).css({ "margin-top": "-4px" }); $("#act1").on("click", function(){ if ( Helper == null ) { alert("BatchHelper はインストールされていません"); return; } var filePath = Helper.SaveFileName( "ファイルの選択", "Excel,*.xlsx", "", "", "" ); if( filePath == "" ) { alert("ファイルの保存参照がキャンセルされました") return; } HelperWsc.CreateBook( filePath ); var messageArray = [ filePath + ".xlsx" ]; loadTable( messageArray ); }); $("#act2").on("click", function(){ if ( Helper == null ) { alert("BatchHelper はインストールされていません"); return; } // ※ Window も停止する Helper.Sleep = 3000; alert("Sleep が終了しました"); var messageArray = []; messageArray.push("現在のスレッドの実行 を3000 ミリ秒停止しました"); messageArray.push("※ Window も停止する"); loadTable( messageArray ); }); $("#act3").on("click", function(){ // 3秒間の停止( コマンドプロンプトウインドウを表示しない ) // ※ Window は停止しない WshShell.Run("TIMEOUT /T 3", 0, true); alert("停止 が終了しました"); var messageArray = []; messageArray.push("3秒間の停止( コマンドプロンプトウインドウを表示しない )"); messageArray.push("※ Window は停止しない"); loadTable( messageArray ); }); $("#act4").on("click", function(){ if ( Helper == null ) { alert("BatchHelper はインストールされていません"); return; } var filePath = Helper.SaveFileName( "ファイルの選択", "Access,*.accdb", "", "", "" ); if( filePath == "" ) { alert("ファイルの保存参照がキャンセルされました"); return; } var ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ".accdb;"; // Microsoft Access 作成 AdoCat.Create( ConnectionString ); // 解放 AdoCat = "" // 再作成 AdoCat = newObject("ADOX.Catalog"); var messageArray = [ filePath + ".accdb" ]; loadTable( messageArray ); }); }); </script> <style> html,body { height: 100%; } body { margin: 0; } /* ブロックを左右に表示 */ .ttl { display: inline-block; width: 120px; vertical-align: top; } .entry { display: inline-block; } .line { margin-bottom: 0; } #head { padding: 16px; } /* IFRAMEコントロール用 */ #head { padding: 16px; width: 100%; height: 180px; background-color: #e0e0e0; } #extend { padding: 4px 16px; display: block; margin-left: auto; margin-right: auto; width: calc( 100% - 3px ); height: calc( 100% - 180px - 2px ); border: solid 2px #c0c0c0; overflow: scroll; } .row_data td { cursor: default!important; } </style> </head> <body> <div id="head"> <p class="ttl"> ダイアログ </p> <p class="entry"> <input id="act1" class="ml-4 btn btn-outline-primary" type="button" value="Excel ブックを作成する(BatchHelper)"> <input id="act2" class="ml-4 btn btn-outline-primary" type="button" value="Sleep (BatchHelper)"> </p> <p class="line"></p> <p class="ttl"> </p> <p class="entry"> <input id="act3" class="ml-4 btn btn-outline-primary" type="button" value="Run で TIMEOUT /T 3 を実行"> <input id="act4" class="ml-4 btn btn-outline-primary" type="button" value="Access(.accdb) の作成"> </p> <p class="line"></p> <h4 class="text-danger"></h4> </div> <div id="extend"> <table class="table table-hover"> <tbody id="tbl"> </tbody> </table> <br> </div> </body> </html>
関連する記事 HTA + JavaScript + COM / ( その1 ) : BatchHelper(32ビット) と テキストファイル読み込みとプリンタ一覧 HTA (または IE11) で hostname を実行して標準出力からPC名の取得