?
Solved

Reading a tab delimited text file through a hta

Posted on 2009-06-30
8
Medium Priority
?
431 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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 2000 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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Watch the video to know how one can repair corrupt Exchange OST file effortlessly and convert OST emails to MS Outlook PST file format by using Kernel for OST to PST converter tool. It can convert OST to MSG, MBOX, EML to access them. It can migrate…
Watch the working video to know how to import Outlook PST/OST files to Amazon WorkMail. Kernel released this tool which is very easy to use and migrate single or multiple PST and OST files to Amazon WorkMail. To know more about Kernel Import PST to …

589 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