HTML5を利用するためにHTAでレンダリングモードを変更するとGetObjectが使えなくなり、WMIからデータを取得したりすることができません。
HTML5を利用しつつGetObjectを使うためのサンプルを作成しました。
実行画面

「errorになる」を押した場合

「errorにならない」を押した場合

以下ソース
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> | |
<head> | |
<meta http-equiv="X-UA-Compatible" content="IE=9"> | |
<title>GetObject</title> | |
</head> | |
<body> | |
<button id=btn0>errorになる</button> | |
<button id=btn1>errorにならない</button> | |
</body> | |
<script> | |
btn0.onclick=function(){ GetObject("winmgmts:root\\CIMV2") } | |
btn1.onclick=function(){ 外部ファイルで実行() } | |
外部ファイルで実行=function(){ | |
var AXO=function(n){return new ActiveXObject(n)}, fs=AXO('Scripting.FileSystemObject'), shell=AXO('WScript.Shell') | |
var W=function(path,str){with(fs.CreateTextFile(path)){Write(str);Close()}} | |
var path=fs.GetSpecialFolder(2)+'/'+(new Date()).getTime()+'.js' | |
W(path,'!'+function(){ | |
cimv2 = GetObject("winmgmts:root\\CIMV2") | |
getプロセス = function(PID){return (new Enumerator(cimv2.ExecQuery("SELECT * FROM Win32_Process where ProcessID="+PID))).item()} | |
f = function(){ | |
var childPID = (new ActiveXObject('WScript.Shell')).Exec('wscript //B').ProcessID | |
return getプロセス(childPID).ParentProcessID | |
} | |
thisPID = f() || f() | |
WScript.StdOut.Write(getプロセス(thisPID).ParentProcessID) | |
}+'()') | |
confirm(shell.exec('cscript //Nologo '+path).StdOut.ReadAll()) | |
fs.DeleteFile(path) | |
} | |
</script> | |
</html> |
0 件のコメント:
コメントを投稿