
このメッセージが表示されないようにするサンプルを作成しました。
一度Openしたオブジェクトは、コネクションが維持されているあいだは再度OpenしなくてもExecuteコマンドが使用できますが、それが維持される期間の長さはスクリプト側からは自由に変更できません。
Executeするたびに期間が延長できる設定になっている場合は、一定期間ごとにExecuteを実行するようにしておけば、上記メッセージが表示されるのはプログラム起動時の一回だけです。
しかしその一回すら面倒になってきましたので、全く表示されない方法を考えました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<title>ADO使用時の警告回避</title> | |
<body><pre></pre></body> | |
<script> | |
fs = new ActiveXObject('Scripting.FileSystemObject') | |
shell = new ActiveXObject('WScript.Shell') | |
txt = (function(){/* | |
<job> | |
<script> | |
path0 = WScript.Arguments(0) | |
fs = new ActiveXObject('Scripting.FileSystemObject') | |
with(fs.OpenTextFile(path0)){SQL=ReadAll();Close()} | |
mysql = new ActiveXObject('ADODB.Connection') | |
mysql.Open('MySQL') | |
rec = mysql.execute(SQL) | |
フィールド数 = rec.Fields.count | |
arrフィールド名 = [] | |
for(i=0; i<フィールド数 ;i++){ arrフィールド名[i] = rec.Fields(i).Name } | |
arr = [] | |
for(i=0; !rec.EOF ;rec.MoveNext(),i++){ | |
arr[i] = [] | |
for(j=0; j<フィールド数 ;j++){ | |
フィールド名 = arrフィールド名[j] | |
arr[i][j] = rec.Fields(フィールド名).Value | |
} | |
arr[i] = arr[i].join('\t') | |
} | |
with(fs.CreateTextFile(path0)){Write(arrフィールド名.join('\t') + '\n' + arr.join('\n')); Close()} | |
</script> | |
</job> | |
*/}+'').replace(/</g,'<') | |
txt = txt.split('/*') | |
txt = txt.slice(1,txt.length ).join('/*').split('*/') | |
txt = txt.slice(0,txt.length-1).join('*/') | |
path0 = fs.GetSpecialFolder(2)+'/'+fs.GetTempName() | |
path1 = path0 + '.wsf' | |
with(fs.CreateTextFile(path1)){Write(txt);Close()} | |
// SQLは引数で渡そうとすると「"」と「'」のエスケープが問題になったりして面倒なので、ファイルに出力して受け渡す。 | |
SQL = "SELECT * FROM table1" | |
with(fs.CreateTextFile(path0)){Write(SQL);Close()} | |
// 作成したWSFファイルをcscriptで実行する。Runの第2引数=0でウィンドウ非表示、第3引数=trueで呼び出し先の処理完了までhta側の処理停止 | |
shell.run('cmd /C cscript '+path1+' '+path0, 0, true) | |
with(fs.OpenTextFile(path0)){document.body.firstChild.innerText=ReadAll();Close()} | |
fs.DeleteFile(path0) | |
fs.DeleteFile(path1) | |
</script> | |
</html> |
上記サンプルを実行したら以下のような結果が得られました。

※<PRE>タグのinnerTextにタブ区切りのテキストを入れているのですが、それだと見栄えがイマイチですが・・・これはサンプルなのでヨシとします。
0 件のコメント:
コメントを投稿