Avatar of Miahmichno
Miahmichno
 asked on

HTA - VBS - Ping until reply

Hello All,
I have created an HTA file that will do several things that I need it to do for me, but the first thing I need it to do is ping our core switch until it receives a reply.

"Why would it not immediately receive a reply?" you may be asking yourself...
We are deploying Cisco's Clean Access Appliance which will remediate the PC's until they are deemed compliant.  With that said... back to the script...

SO my HTA will open a html window,
2) kill a couple of process' that need to be killed for the rest to work
3) run Ping against the core switch, and here in lies the issue...

I would like a VBS sub routine that will ping until reply is received
Once received, the rest of the HTA can proceed.

I have included my script, and have also tried to run the routine several ways.
1) within the VBS, it failed.  
2) I tried to call the external vbs using objshell.run "cscript //nologo file.vbs",2,true   <-- this never acted like it even ran.
3) I tried to call an exteral bat file using the objshell.run "path\file.bat" <-- again acted like it never ran the file.

Preferred method.
within the VBS that is in the body of the HTA, a loop routine that pings until reply, and does not show a dos box.  <-- very important.  All I want on my screen is the HTA file.
<HTML>
	<HEAD>
		<TITLE>Running CFCU Apps</TITLE>
				<HTA:APPLICATION ID ="oHTA"
				APPLICATIONNAME = "RunRoutine"
				BORDER = "Thin"
				BORDERSTYLE = "Normal"
				CAPTION = "Yes"
				ICON = ""
				INNERBORDER	= "No"
				MAXIMIZEBUTTON	= "Yes"
				MINIMIZEBUTTON	= "Yes"
				NAVIGABLE	= "Yes"
				SCROLL = "Yes"
				SCROLLFLAT	= "No"
				SELECTION	= "Yes"
				SHOWINTASKBAR = "No"
				SINGLEINSTANCE = "No"
				SYSMENU = "Yes"
				WINDOWSTATE = "normal" 
				>
	</HEAD>
 
<script language="VBscript">
Sub Window_onLoad
	intWidth = 500
	intHeight = 400
	Me.ResizeTo intWidth, intHeight
	Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
		Call ProcessKill
		Call Ping
		'Call Websense
		Call iAtlas
		Call LoginScript
		Call CloseWindow
End Sub
 
Sub Ping
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.run "%logonserver%\Netlogon\PingCheck.bat",2,True
'objShell.run "ping 10.10.10.19",2,true
End Sub
 
Sub Websense
' Used to create the Websense folder.
Dim fso, fldr, destination, source, webA, webB, webC, objShell
set fso = Createobject("Scripting.FileSystemObject") 
source = "%logonserver%\websense\*.*"
destination = "C:\Websense\"
If Not fso.FolderExists(destination) then
	set fldr = fso.CreateFolder("c:\websense")
End If
	fso.copyfile source,destination
Set objShell = CreateObject("wscript.shell")
webA="C:\Websense\LogonApp.exe "
webB="http://<IPADDRESS>:<port#> "
webC="/NOPERSIST"
	ObjShell.Run WebA & WebB & WebC,1,1
End Sub
 
Sub ProcessKill
'Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill 
strComputer = "."
strProcessKill = "'iAtlas.exe'" 
 
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\cimv2") 
 
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
	objProcess.Terminate()
Next 
End Sub
 
Sub iAtlas
'Option Explicit
Dim objWMIService, objProcess, objCalc
Dim strShell, objProgram, strComputer, strExe 
strComputer = "."
strExe = "C:\Program Files\iMM\iAtlas\iAtlas.exe"
set objWMIService = getobject("winmgmts://" & strComputer & "/root/cimv2") 
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_("Create").InParameters.SpawnInstance_
	objProgram.CommandLine = strExe 
Set strShell = objWMIService.ExecMethod( _
	"Win32_Process", "Create", objProgram) 
End Sub
 
Sub LoginScript
Dim objShell
Set objShell = CreateObject("wscript.shell")
	ObjShell.Run ("%logonserver%\NETLOGON\Coastal2.bat"), 2, True '<-----Displays the window as a minimized window.
End Sub
 
Sub CloseWindow
      self.close
End Sub
 
</script>
</HEAD> 
			<body STYLE="font:8 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')" onkeypress='vbs:Default_Buttons'>        
				<table width='90%' height = '100%' align='center' border='0'>
					<tr>
						<td align="center">
							<h4>Starting CFCU Login Process</h5><br>
							<h5>Please be patient</5><br><br><br>
							<h2><Font color = FFD700><b><br><br>Do not close this window</b></font></h2>
						</td>
					</tr>
				<tr>
					<td align='center'>
						<br><br>
						<span name="span_text" id="span_text"></span>
						<br><br>
					</td>
				</tr>
			</table>
		</body> 
</HTML>

Open in new window

VB Script

Avatar of undefined
Last Comment
RobSampson

8/22/2022 - Mon
RobSampson

Hi, try this.  I've added my own Ping function, and in the Window_OnLoad used a While loop to wait for the ping to return true.

Regards,

Rob.
<HTML>
	<HEAD>
		<TITLE>Running CFCU Apps</TITLE>
				<HTA:APPLICATION ID ="oHTA"
				APPLICATIONNAME = "RunRoutine"
				BORDER = "Thin"
				BORDERSTYLE = "Normal"
				CAPTION = "Yes"
				ICON = ""
				INNERBORDER	= "No"
				MAXIMIZEBUTTON	= "Yes"
				MINIMIZEBUTTON	= "Yes"
				NAVIGABLE	= "Yes"
				SCROLL = "Yes"
				SCROLLFLAT	= "No"
				SELECTION	= "Yes"
				SHOWINTASKBAR = "No"
				SINGLEINSTANCE = "No"
				SYSMENU = "Yes"
				WINDOWSTATE = "normal" 
				>
	</HEAD>
 
<script language="VBscript">
Sub Window_onLoad
	intWidth = 500
	intHeight = 400
	Me.ResizeTo intWidth, intHeight
	Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
		Call ProcessKill
		Set objShell = CreateObject("WScript.Shell")
		boolPinged = Ping("10.10.10.19")
		While boolPinged = False
			' Wait for one second, given by -n #
			objShell.Run "cmd /c ping -n 1 localhost > nul", 0, True
			boolPinged = Ping("10.10.10.19")
		Wend
		'Call Websense
		Call iAtlas
		Call LoginScript
		Call CloseWindow
End Sub
 
Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function
 
Sub Ping_Old
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.run "%logonserver%\Netlogon\PingCheck.bat",2,True
'objShell.run "ping 10.10.10.19",2,true
End Sub
 
Sub Websense
' Used to create the Websense folder.
Dim fso, fldr, destination, source, webA, webB, webC, objShell
set fso = Createobject("Scripting.FileSystemObject") 
source = "%logonserver%\websense\*.*"
destination = "C:\Websense\"
If Not fso.FolderExists(destination) then
	set fldr = fso.CreateFolder("c:\websense")
End If
	fso.copyfile source,destination
Set objShell = CreateObject("wscript.shell")
webA="C:\Websense\LogonApp.exe "
webB="http://<IPADDRESS>:<port#> "
webC="/NOPERSIST"
	ObjShell.Run WebA & WebB & WebC,1,1
End Sub
 
Sub ProcessKill
'Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill 
strComputer = "."
strProcessKill = "'iAtlas.exe'" 
 
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\cimv2") 
 
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
	objProcess.Terminate()
Next 
End Sub
 
Sub iAtlas
'Option Explicit
Dim objWMIService, objProcess, objCalc
Dim strShell, objProgram, strComputer, strExe 
strComputer = "."
strExe = "C:\Program Files\iMM\iAtlas\iAtlas.exe"
set objWMIService = getobject("winmgmts://" & strComputer & "/root/cimv2") 
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_("Create").InParameters.SpawnInstance_
	objProgram.CommandLine = strExe 
Set strShell = objWMIService.ExecMethod( _
	"Win32_Process", "Create", objProgram) 
End Sub
 
Sub LoginScript
Dim objShell
Set objShell = CreateObject("wscript.shell")
	ObjShell.Run ("%logonserver%\NETLOGON\Coastal2.bat"), 2, True '<-----Displays the window as a minimized window.
End Sub
 
Sub CloseWindow
      self.close
End Sub
 
</script>
</HEAD> 
			<body STYLE="font:8 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')" onkeypress='vbs:Default_Buttons'>        
				<table width='90%' height = '100%' align='center' border='0'>
					<tr>
						<td align="center">
							<h4>Starting CFCU Login Process</h5><br>
							<h5>Please be patient</5><br><br><br>
							<h2><Font color = FFD700><b><br><br>Do not close this window</b></font></h2>
						</td>
					</tr>
				<tr>
					<td align='center'>
						<br><br>
						<span name="span_text" id="span_text"></span>
						<br><br>
					</td>
				</tr>
			</table>
		</body> 
</HTML>

Open in new window

Miahmichno

ASKER
Thanks for the help...
I am now receiving error on line 31 Type mismatch: 'Ping'


Line 31:Set objShell = CreateObject("WScript.Shell")
Line 32:boolPinged = Ping("10.10.10.1")

Open in new window

Miahmichno

ASKER
IP is suppose to be 10.10.10.1 instead of 10.10.10.19
sorry for the confusion.  Still no workie.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
RobSampson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Miahmichno

ASKER
Sorry for the delay.  It works great.  Thank you
RobSampson

No problem.  Thanks for the grade.

Regards,

Rob.