<?xml version="1.0"?>
<component id="BrowseList">
<registration
	description="Filter the browse list"
	progid="BrowseListFilter.WSC"
	version="2.0.1"
	classid="{79e350e5-75ec-4f15-8e4a-23dcb6e7b276}"
>
</registration>

<comment>
BrowseListFilter.wsc
Version 2.0.1
Written by Rick Kasten, UpOnTech - rkasten@upontech.com
Latest update: December 18, 2003

Requirements:
1) Windows Script 5.6
2) BROWSTAT.EXE - from the Windows NT 4.0 Server Resource Kit

Description:
This object exposes the computers in the active browse list - essentially what is in the
"NET VIEW" list.  That list is gathered by using BROWSTAT.EXE from the Windows NT 4.0 Server 
Resource Kit, And the various flags used by BROWSTAT are the basis for the "Filter" property
declared by this component.
</comment>

<public>
	<property name="Count">
		<comment>
			The total number of computernames found by the GetBrowseList method.
		</comment>
		<get/>
	</property>
	<property name="Domain">
		<comment>
			The domain to be viewed (default is the local domain)
		</comment>
		<get/>
		<put/>
	</property>
	<property name="Filter">
		<comment>
			The filter of computernames based on BROWSTAT flags.
			Currently accepted filters are:
				SERVER		: servers only
				WORKSTATION	: workstations only
				DC		: domain controllers only
				NONE (or blank)	: no filter
		</comment>
		<get/>
		<put/>
	</property>
	<property name="InvFilter">
		<comment>
			The inverse of the BrowseListFilter.Filter, as in
				NOT (BrowseListFilter.Filter)
		</comment>
		<get/>
		<put/>
	</property>
	<property name="OSType">
		<comment>
			The operating system of InvFilter selected.
			Currently accepted OS types are:
				NT		: NT only
				2000		: 2000 only
				XP		: Windows XP only
				2003		: Windows Server 2003 only
				ALL (or blank)	: All computers
		</comment>
		<get/>
		<put/>
	</property>
	<property name="InvOSType">
		<comment>
			The inverse of the BrowseListFilter.OSType, as in
				NOT (BrowseListFilter.OSType)
		</comment>
		<get/>
		<put/>
	</property>
	<property name="Virtuals">
		<comment>
			Include virtual servers as well as actual servers
		</comment>
		<get/>
		<put/>
	</property>
	<method name="GetBrowseList">
		<comment>
			Gathers the browselist And returns a filtered array of computernames
		</comment>
	</method>
</public>

<object id="fso"		progid="Scripting.FileSystemObject"/>
<object id="wshShell"		progid="WScript.Shell"/>
<object id="wshNetwork"		progid="WScript.Network"/>

<script language="VBScript">
<![CDATA[

' *** Check requirements ***
aPath = Split(WshShell.ExpandEnvironmentStrings("%PATH%"),";")
For Each Item In aPath
	If fso.FileExists(Item & "\VBSCRIPT.DLL") Then
		If fso.GetFileVersion(Item & "\VBSCRIPT.DLL") >= "5.6" Then VBSVer56 = True
	ElseIf fso.FileExists(Item & "\BROWSTAT.EXE") Then
		ResKitInstalled = True
	End If
Next
If Not VBSVer56 Then ERROR 1, "Windows Script 5.6 Or greater required"
If Not ResKitInstalled Then ERROR 2, "BROWSTAT.EXE from the Windows NT 4.0 Server Resource Kit required"

' *** Main Procedure ****
Dim Index, BrowseList, Domain, Filter
Index = -1
BrowseList = Array()
Domain = Empty
Filter = "NONE"
blInvFilter = False
OSType = "ALL"
blInvOSType = False
blVirtuals = True

Function ERROR(num, desc)			' Raise errors
	On Error GoTo 0
	Err.Raise vbObjectError + 1024 + num, "BrowseListFilter", desc
End Function

Function get_Count()				' Get the number of computernames returned
	get_Count = UBound(BrowseList) + 1
End Function

Function get_Domain(Domain)			' Get the current domain
	Domain = Domain
End Function

Function put_Domain(newValue)			' Set the current domain
	Domain = newValue
End Function

Function get_Filter()				' Get type of filter
	get_Filter = Filter
End Function

Function put_Filter(newValue)			' Set type of filter
	newValue = UCase(newValue)
	If newValue = "WORKSTATION" Or newValue = "SERVER" Or newValue = "DC" Or newValue = "MEMBER" Or newValue = "NONE" Then
		Filter = newValue
	Else
		ERROR 3, "Invalid option for BrowseListFilter.Filter" & vbNewLine &_
			"Valid options are: WORKSTATION, SERVER, DC, MEMBER, NONE"
	End If
End Function

Function get_InvFilter()			' Get type of blInvFilter
	get_InvFilter = blInvFilter
End Function

Function put_InvFilter(newValue)		' Set type of blInvFilter
	If newValue = True Or newValue = False Then
		blInvFilter = newValue
	Else
		ERROR 4, "Invalid option for BrowseListFilter.InvFilter" & vbNewLine &_
			"Valid options are: True, False"
	End If
End Function

Function get_OSType()				' Get type of OSType
	get_OSType = OSType
End Function

Function put_OSType(newValue)			' Set type of OSType
	newValue = UCase(newValue)
	If newValue = "NT" Or newValue = "2000" Or newValue = "XP" Or newValue = "2003" Or newValue = "ALL" Then
		OSType = newValue
	Else
		ERROR 5, "Invalid option for BrowseListFilter.OSType" & vbNewLine &_
			"Valid options are: NT, 2000, XP, 2003, ALL"
	End If
End Function

Function get_InvOSType()			' Get type of blInvOSType
	get_InvOSType = blInvOSType
End Function

Function put_InvOSType(newValue)		' Set type of blInvOSType
	If newValue = True Or newValue = False Then
		blInvOSType = newValue
	Else
		ERROR 6, "Invalid option for BrowseListFilter.InvOSType" & vbNewLine &_
			"Valid options are: True, False"
	End If
End Function

Function get_Virtuals()				' Get the status of displaying virtual servers
	get_Virtuals = blVirtuals
End Function

Function put_Virtuals(newValue)			' Set the status of displaying virtual servers
	If newValue = True Or newValue = False Then
		blVirtuals = newValue
	Else
		ERROR 7, "Invalid option for BrowseListFilter.Virtuals" & vbNewLine &_
			"Valid options are: True, False"
	End If
End Function

Function GetBrowseList()			' Returns an array of the browse list
	If IsEmpty(Domain) Then Domain = wshNetwork.UserDomain
	Set wshExec = wshShell.Exec("net config rdr")
	If wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion") = "4.0" Then
		wshExec.StdOut.SkipLine
		wshExec.StdOut.SkipLine
		wshExec.StdOut.SkipLine
		InLine = wshExec.StdOut.ReadLine
		aIn = Split(InLine)
		Transport = aIn(UBound(aIn) - 2)
	Else
		wshExec.StdOut.SkipLine
		wshExec.StdOut.SkipLine
		wshExec.StdOut.SkipLine
		wshExec.StdOut.SkipLine
		wshExec.StdOut.SkipLine
		Do While not wshExec.StdOut.AtEndOfStream
			InLine = wshExec.StdOut.ReadLine
			aIn = Split(InLine)
			If InStr(aIn(0), "Tcpip") Then 
				Transport = aIn(0)
				Exit Do
			End If
		Loop
	End If
	Set wshExecNetView = WshShell.Exec("browstat view " & Transport & " " & Domain)
	wshExecNetView.StdOut.SkipLine
	Do While not wshExecNetView.StdOut.AtEndOfStream
		InLine = wshExecNetView.StdOut.ReadLine
		If Not InLine = "" Then
			NumComps = (Split(InLine, " "))(0)
			Exit Do
		Else
			GetBrowseList = Array()
			Exit Function
		End If
	Loop
	ReDim BrowseList(NumComps)
	wshExecNetView.StdOut.SkipLine
	If blInvFilter Then
		If Filter = "WORKSTATION" Then
			Filter = "SERVER"
		ElseIf Filter = "SERVER" Then
			Filter = "WORKSTATION"
		ElseIf Filter = "DC" Then
			Filter = "NON-DC"
		ElseIf Filter = "MEMBER" Then
			Filter = "NON-MEMBER"
		End If
	End If
	If blInvOSType Then
		If OSType = "NT" Then
			OSType = "NON-NT"
		ElseIf OSType = "2000" Then
			OSType = "NON-2000"
		ElseIf OSType = "XP" Then
			OSType = "NON-XP"
		ElseIf OSType = "2003" Then
			OSType = "NON-2003"
		End If
	End If
	Set objREFixSpace = New RegExp
	objREFixSpace.Pattern = "  +"
	objREFixSpace.Global = True
	Do While not wshExecNetView.StdOut.AtEndOfStream
		InLine = objREFixSpace.Replace(wshExecNetView.StdOut.ReadLine, " ")
		aIn = Split(InLine)
		If aIn(1) = "NT" And (aIn(2) = "04.00" Or InStr(aIn(2),"05.0") > 0) Then
			Select Case Filter
				Case "DC"		If InStr(aIn(3),"DC,") > 0 Then sTmp1 = aIn(0)
				Case "MEMBER"		If InStr(aIn(3),",SS") > 0 And InStr(aIn(3),"DC,") = 0 Then sTmp1 = aIn(0)
				Case "NON-DC"		If InStr(aIn(3),"DC,") = 0 Then sTmp1 = aIn(0)
				Case "NON-MEMBER"	If InStr(aIn(3),"DC,") > 0 Or InStr(aIn(3),",SS") = 0 Then sTmp1 = aIn(0)
				Case "SERVER"		If InStr(aIn(3),",SS") Or InStr(aIn(3),"DC,") > 0 Then sTmp1 = aIn(0)
				Case "WORKSTATION"	If (InStr(aIn(3),",SS") = 0 And InStr(aIn(3),"DC,") = 0) And _
								InStr(aIn(3),"(W,") > 0 Then sTmp1 = aIn(0)
				Case Else		sTmp1 = aIn(0)
			End Select
			If Not blVirtuals And InStr(aIn(3),"(W,") = 0 Then sTmp1 = Empty
			Select Case OSType
				Case "NT"		If aIn(2) = "04.00" Then sTmp = sTmp1
				Case "NON-NT"		If aIn(2) <> "04.00" Then sTmp = sTmp1
				Case "2000"		If aIn(2) = "05.00" Then sTmp = sTmp1
				Case "NON-2000"		If aIn(2) <> "05.00" Then sTmp = sTmp1
				Case "XP"		If aIn(2) = "05.01" Then sTmp = sTmp1
				Case "NON-XP"		If aIn(2) <> "05.01" Then sTmp = sTmp1
				Case "2003"		If aIn(2) = "05.02" Then sTmp = sTmp1
				Case "NON-2003"		If aIn(2) <> "05.02" Then sTmp = sTmp1
				Case Else		sTmp = sTmp1
			End Select
			If Not IsEmpty(sTmp) Then
				Index = Index + 1
				BrowseList(Index) = sTmp
			End If
			sTmp1 = Empty
			sTmp = Empty
		End If
	Loop
	ReDim Preserve BrowseList(Index)
	GetBrowseList = BrowseList
End Function

]]>
</script>

</component>
