Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run from an HTA 2

Status
Not open for further replies.

mishbaker

Technical User
Jan 17, 2004
94
US
Ok I've banging my head off the desk on this one...

Why doesn't this work? I'm using it as the onclick event for a button in my HTA.

Code:
<html>
<head>
[COLOR=#800000]<script type="text/vbscript">
sub mit()
  set oShell = CreateObject("WScript.Shell")
  iRes = oShell.run("ping 192.168.2.1 > pingres.txt", 0)
  set oShell = Nothing
end sub
</script>[/color]
</head>
<body>
<form id="fform" name="fform">
<input type="button" name="btn" value="Ping" onclick="mit">
</form>
</body>
</html>

I've also changed the window to 1 and tried to see what was going on but the iRes result is 1 and nothing happens when the cmd window pops up. I've also tried setting the waitforreturn option to true and still nothing. If I remove the > redirection operator and filename, it works like a champ.



All lessons learned from the School of Hard Knocks........at least tuition is cheap.
 
Try

%comspec% /c ping.exe 192.168.2.1 > C:\temp\pingres.txt

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Rather than writing to a text file the way you are, you could use WMI to get the ping status and use that as a variable. Might open some more doors for you. here is a sample.

Code:
strComputer = "192.168.0.13"

Dim wmiQuery, objWMIService, objPing, objStatus
 
 wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strComputer & "'"
 
 Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
 Set objPing = objWMIService.ExecQuery(wmiQuery)
 
 For Each objStatus in objPing
     If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
         Reachable = "Machine is unreachable"
     Else
         Reachable = "PING SUCCESS!!!"
     End If
 Next

WScript.Echo Reachable

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks guys. Also, WMI Ping won't work since this is being run on some Pre-XP systems. But thanks for the response. ((Oh yes, bow down before the WMI)).


All lessons learned from the School of Hard Knocks........at least tuition is cheap.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top