Reading a tab delimited text file through a hta

Hi guys i hope you are well.
Guys i have attached a screen dump of what im trying to achieve.
Id like to create a vbs (hta) file that:
1) Reads a tab delimited text file 2 columns wide (computers.txt)
2) For each computer name listed in computers.txt (column 2), do what the objectives i have in the screen dump.

Any help greatly appreciated.
color.jpg
LVL 1
Simon336697Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
Hi Simon,

Give this a shot....I haven't been able to test all of it, but see how it goes...

Regards,

Rob.
<head>
<title>System Information Report</title>
<HTA:APPLICATION 
     APPLICATIONNAME="System Information Report"
     BORDER="thin"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
>
</head>
 
<script language="VBScript">
 
Dim dictComputers
Const intForReading = 1
 
Sub Window_OnLoad
	intWidth = 800
	intHeight = 600
	Me.ResizeTo intWidth, intHeight
	Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
	span_progress.InnerHTML = ""
	span_results.InnerHTML = ""
	Set dictComputers = CreateObject("Scripting.Dictionary")
End Sub
 
Sub Run_Script
	If txt_textfile.Value = "" Then
		MsgBox "Please select a text file."
		txt_textfile.Focus
	Else
		Set objFSO = CreateObject("Scripting.FileSystemObject")
		Set objFile = objFSO.OpenTextFile(txt_textfile.Value, intForReading, False)
		While Not objFile.AtEndOfStream
			strLine = objFile.ReadLine
			If InStr(strLine, vbTab) > 0 Then
				dictComputers.Add Split(strLine, vbTab)(0), Split(strLine, vbTab)(1)
			End If
		Wend
		objFile.Close
		arrComputers = Split(strComputers, ";")
		strHTML = "<table width='100%' border='1'>"
		span_results.InnerHTML = strHTML
		strHTML = strHTML & "<tr><th>Case</th><th>System</th><th>Ping</th><th>Net Use</th><th>Alerter</th><th>Browser</th><th>Server</th></tr>"
		span_results.InnerHTML = strHTML
		intCount = 0
		For Each strCase In dictComputers
			intCount = intCount + 1
			span_progress.InnerHTML = "Scanning " & intCount & " of " & dictComputers.Count
			boolPingStatus = Ping(dictComputers(strCase))
			If boolPingStatus = True Then
				strBGColor = "white"
				boolPingStatus = "Y"
				boolNetUseStatus = TestNetUseCommand(strComputer)
				If boolNetUserStatus = "X" Then strBGColor = "orange"
				strAlerterStatus = Get_Service_State(strComputer, "alerter")
				strBrowserStatus = Get_Service_State(strComputer, "browser")
				strServerStatus = Get_Service_State(strComputer, "lanmanserver")
			Else
				strBGColor = "red"
				boolPingStatus = "X"
				boolNetUseStatus = "X"
				strAlerterStatus = "X"
				strBrowserStatus = "X"
				strServerStatus = "X"
				span_results.InnerHTML = strHTML
			End If
			strHTML = strHTML & "<tr>" & _
				"<td bgcolor='" & strBGColor & "'>" & strCase & "</td>" & _
				"<td bgcolor='" & strBGColor & "'>" & dictComputers(strCase) & "</td>" & _
				"<td bgcolor='" & strBGColor & "'>" & boolPingStatus & "</td>" & _
				"<td bgcolor='" & strBGColor & "'>" & boolNetUseStatus & "</td>" & _
				"<td bgcolor='" & strBGColor & "'>" & strAlerterStatus & "</td>" & _
				"<td bgcolor='" & strBGColor & "'>" & strBrowserStatus & "</td>" & _
				"<td bgcolor='" & strBGColor & "'>" & strServerStatus & "</td>" & _
				"</tr>"
			span_results.InnerHTML = strHTML
		Next
	End If
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
 
Function TestNetUseCommand(strComputer)
	Set objShell = CreateObject("WScript.Shell")
	strDrive = Get_Next_Available_Drive_Letter
	strCommand = "net use " & strDrive & ": \\" & strComputer & "\IPC$"
	intReturn = objShell.Run(strCommand, 0, True)
	If intReturn = 0 Then
		strStatus = "Y"
		strCommand = "net use " & strDrive & ": /delete"
		objShell.Run strCommand, 0, True
	Else
		strStatus = "X"
	End If
	TestNetUseCommand = strStatus
End Function
 
Function Get_Service_State(strComputer, strServiceName)
	Const wbemFlagReturnImmediately = &h10
	Const wbemFlagForwardOnly = &h20
	On Error Resume Next
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
	Set colItems = objWMIService.ExecQuery("SELECT State FROM Win32_Service WHERE Name='" & strServiceName & "'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
	For Each objItem In colItems
		strState = objItem.State
	Next
	If Err.Number <> 0 Then
		strState = "N/A"
		Err.Clear
	End If
	On Error GoTo 0
	Get_Service_State = strState
End Function
 
Function Get_Next_Available_Drive_Letter
	' Use the ASCII code to be converted to a letter of the alphabet
	' starting from "E" which is character number 69
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	strFirstAvailable = ""
	For intChar = 69 To 90
		If objFSO.DriveExists(Chr(intChar) & ":") = False Then
			strFirstAvailable = Chr(intChar) & ":"
			Exit For
		End If
	Next
	If strFirstAvailable <> "" Then
		Get_Next_Available_Drive_Letter = Chr(intChar) & ":"
	Else
		Get_Next_Available_Drive_Letter = ""
	End If
End Function
 
</script>
 
<body>
<table width='90%' height='90%' align='center' border='0'>
	<tr height="100">
		<td align='center' colspan="2">
			<h3>System Information Report</h3>
		</td>
	</tr>
	<tr height="100">
		<td>
			Text file:
		</td>
		<td>
			<input type="file" size="40" id="txt_textfile" name="txt_textfile">&nbsp;&nbsp;&nbsp;<button name="btn_runscript" accesskey="R" onclick="Run_Script"><u>R</u>un Script</button>
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<span id="span_progress"></span><br>
			<span id="span_results"></span>
		</td>
	</tr>
</table>
</body>

Open in new window

0
Simon336697Author Commented:
Rob,
Hi mate hope you are well bud :>)

Will do and let you know.
0
Simon336697Author Commented:
Rob youre the best.
That does work.
There is a dns issue where i am, so im getting a lot of issues using the hostname to ping and net use.
Im having much more luck using the ip address.

Rob,

Is there any way to somehow alter your brilliant work here, and retrieve the ip address for each host by using the nslookup command?

Or,

Id be happy with the following mate (always happy with you anyway :>)).

Create another hta (separate question probably):

----------------------------------------------------- createtextfileofips.hta
Please load a text file of computer names ________
Run script...

This would read the text file of computer names, and for each, return the ip address of the host, and write it to a new file called ips.txt


0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Simon336697Author Commented:
Rob, ill leave this one open, and create a new question.
0
RobSampsonCommented:
Hey, it's probably easier to go with the NSLookup output to get the IP address.  I noticed you've got a few other questions open along these lines.  If you've got DNS issues, then the IP Address given by the Ping command may not be reliable.  Can you post an example NSLookup command, and the corresponding output, for a hostname that has a DNS record issue?  We could then use that IP address instead, and if there's multiples, we can try both.

Let me know if that suits, or if you've already got a solution from one of the other questions, and we can incorporate that if you like.

Regards,

Rob.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Simon336697Author Commented:
Rob,

I TOTALLY agree.
And youre right. We do have DNS issues.
PInging by the ip address/es returned by the nslookup id rather :>)

As im now at home, i havent got a production example Rob.
Most of our client systems would have 1 ip address returned, but i spose it would be good to factor those in with multiple ips.

The points are yours mate here.
Ill post another question called "NSLOOKUP IP" Rob :>)
Always great communicating with you mate.
0
Simon336697Author Commented:
Rob youre the best.
0
RobSampsonCommented:
OK, no problem. Thanks for the grade. Let me know the URL of the new question, and I'll take a look at it soon.

Regards,

Rob.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.