2013-07-26 96 views
1

我能夠通過使用下面的代碼來ping遠程服務器:獲取HDA應用程序的遠程服務器正常運行時間

function ping(server) { 
var objPing = GetObject("winmgmts:").Get("Win32_PingStatus.Address='" + server + "'"); 
    $("#myInfo").html("<div><b>" + server + ":</b></div> \ 
        <div>IP: " + objPing.ProtocolAddress + "</div> \ 
       <div>Time to resolve: " + objPing.ResponseTime + "ms</div>"); 
    } 

我想也得到遠程服務器正常運行時間加入: VAR objWMIService = GetObject的(「winmgmts:\」+ server +「\ root \ cimv2」)

一旦我得到那個工作,我將能夠查詢服務器並獲得正常運行時間。在VBS代碼看起來像下面,但我需要它在我的HTA應用程序的工作,而不是作爲VBS:

Set objWMIService = GetObject("winmgmts:\\" & server & "\root\cimv2") 
Set colOperatingSystems = objWMIService.ExecQuery _ 
("Select * From Win32_PerfFormattedData_PerfOS_System") 

For Each objOS in colOperatingSystems 
intSystemUptime = Int(objOS.SystemUpTime/60/60) 
Wscript.Echo intSystemUptime & " hours" 
Next 

要添加到這一點,我也包括在我的HTA應用程序腳本會啓動膩子上點擊。我發現這個功能的解決方案是爲了逃避後臺空間。該函數的剪斷它看起來像如下:

WshShell.Run('"C:/\Program Files (x86)/\Putty/\putty.exe" -ssh ' + server); 

所以我想逃避可能幫助像這樣的,但我仍然得到一個錯誤:

var objWMIService = GetObject("winmgmts:/\/\" + server + "/\root/\cimv2") 

回答

1

一些快速google搜索根據止跌回升this page這樣的東西應該工作:

var server = "." 

var locator = new ActiveXObject("WbemScripting.SWbemLocator"); 
var svc = locator.ConnectServer(server, "/root/cimv2"); 
svc.Security_.AuthenticationLevel = 0; 
svc.Security_.ImpersonationLevel = 3; 

var qry = "SELECT SystemUptime FROM Win32_PerfFormattedData_PerfOS_System"; 
var data = new Enumerator(svc.ExecQuery(qry)); 
for (;!data.atEnd();data.moveNext()) { 
    var counters = new Enumerator(data.item().Properties_); 
    for (;!counters.atEnd();counters.moveNext()) { 
    WScript.Echo(counters.item().Value); 
    } 
} 
+0

完美!除了WScript.Echo不能在js中工作,所以我把它變成了一個變量,並附加了我想要的div。謝謝! – Jeight

相關問題