Solved

Reading a tab delimited text file through a hta

Posted on 2009-06-30
8
407 Views
Last Modified: 2012-05-07
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
0
Comment
Question by:Simon336697
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 24751925
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
 
LVL 1

Author Comment

by:Simon336697
ID: 24752219
Rob,
Hi mate hope you are well bud :>)

Will do and let you know.
0
 
LVL 1

Author Comment

by:Simon336697
ID: 24752264
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Simon336697
ID: 24752271
Rob, ill leave this one open, and create a new question.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 24761651
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
 
LVL 1

Author Comment

by:Simon336697
ID: 24761862
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
 
LVL 1

Author Closing Comment

by:Simon336697
ID: 31598551
Rob youre the best.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24762039
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question