IE11 での実行には設定が必要です => HTA(HTMLアプリケーション) のコードを html として IE11 でデバッグする方法コマンドプロンプトベースのアプリケーションを実行するので、一瞬コマンドプロンプトが現れます。その後、コマンドプロンプトに表示された内容を取得する方法です。 ※ StdOut は、TextStream オブジェクトのメソッドで処理に該当するものが使えます。 ※ WshScriptExec オブジェクト ▼ HTA(HTML アプリケーション) : pcname-from-stdout.hta▼ IE11 : pcname-from-stdout.html
![]()
<!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="hta.js"></script>
<script>
// ウインドウの位置とサイズ
centerWindow( 1100, 600 );
// WSH 標準
var WshShell = newObject("WScript.Shell");
$(function(){
// ***************************
// ボタン表示位置微調整
// ***************************
$( ".btn" ).css({
"margin-top": "-4px"
});
// ***************************
// hostname を実行して
// 結果を取得する
// ***************************
$("#act1").on("click", function(){
var oExec = WshShell.Exec("hostname");
var str = "";
str += oExec.StdOut.ReadAll();
var arrData = [ str ];
loadTable( arrData );
});
});
</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: 120px;
background-color: #e0e0e0;
}
#extend {
padding: 4px 16px;
display: block;
margin-left: auto;
margin-right: auto;
width: calc( 100% - 3px );
height: calc( 100% - 120px - 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="hostname を実行して標準出力からPC名の取得">
</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.js
// *************************************
// ウインドウの位置とサイズ
// *************************************
function baseWindow( x, y, w, h ) {
top.moveTo( x, y );
top.resizeTo( w, h );
}
// *************************************
// デスクトップ中央
// *************************************
function centerWindow( w, h ) {
// ウインドウの位置とサイズ
top.resizeTo( w, h );
top.moveTo((screen.width-w)/2, (screen.height-h)/2 )
}
// *************************************
// CreateObject
// *************************************
function newObject( className ) {
var obj;
try {
obj = new ActiveXObject( className );
}
catch (e) {
obj = null;
}
return obj;
}
// *************************************
// テーブル作成
// *************************************
function loadTable( arrayData ) {
var row_data = "";
// テーブル表示リセット
$("#tbl .row_data").remove();
var len = arrayData.length;
for( i = 0; i < len; i++ ) {
row_data = $("<tr></tr>")
.addClass("row_data")
.appendTo( "#tbl" );
$("<td></td>")
.text(arrayData[i])
.appendTo( row_data );
}
}
|
|
【HTA ( HTMLアプリケーション )の最新記事】
- HTA / ADO / Jscript : Access( .accdb .mdb ) の読み込みと表示
- HTML Application : JavaScript で新しい Excel の Book を作成する
- HTML Application : JavaScript で Windows のいろいろなフォルダを開く
- HTA (または IE11) で フォルダ選択ダイアログからフォルダとファイルの一覧
- HTA : 『x-frame-options: SAMEORIGIN』の設定されていないページの情報を IFRAME 内に表示して jQuery で取り出す / iframe内 参照と .clone(..
- HTA (HTMLアプリケーション) で JavaScript と VBScript を混在させる手法 / GetObject を VBScript 側で使用する
- HTA + Basp21 + jQuery + twitter-bootstrap(4.1.1) でメール受信ツール
- HTA + Basp21 + jQuery + twitter-bootstrap(4.1.1) でメール送信ツール



▼ IE11 : pcname-from-stdout.html




