【发布时间】:2016-06-01 20:28:11
【问题描述】:
无法让此代码正常工作。我可以在 vbscript 中运行脚本(有更改)并且运行良好。但我无法让这个版本返回 0 以外的 ping 错误返回值。感谢任何帮助。
这是扫描带有复选框的远程计算机列表并返回选中的值。我想在继续之前运行 ping 以验证远程机器是否存在。但是对于所有查询都返回 0 的错误是没有用的。
function statuschk3(){
var checkedValue = null;
var inputElements = document.getElementsByName("comp");
for(var i=0; inputElements[i]; ++i){
if(inputElements[i].checked)
{checkedValue = inputElements[i].value;
var WshShell = new ActiveXObject("WScript.Shell");
var status = WshShell.run ("ping -n 1 -a" + checkedValue + ",0 ,true");
if(status == 0)
{ var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.OpenTextFile("C:/script/testfile1.txt", 8, true);
s.WriteLine(checkedValue + " is turned off or off the domain");
s.Close();
}
else`
【问题讨论】:
-
认为问题在于没有等待时间(
-w)。见Ping from windows 7 get no reply but sets errorlevel to 0 -
OP,如果以下任何答案有帮助,请考虑将其中一个标记为已接受。 See this post 解释为什么这很重要。您应该为all the other questions you asked 执行此操作。