Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Can anyone offer assitance with this script?

Reply
 
Old 07-06-2009   #1 (permalink)
Cary Shultz


 
 

Can anyone offer assitance with this script?

Good afternoon!

Please find below the script. It is rather long. Sorry.

This script is doing something funny...when I run it in environments where
there is but one server I have no issues. However, when I run in it
environments where there are multiple environments I have issues. It seems
that the results of the first computer are carried over into the results of
the succedding computers.

I am using a text file that contains each server in the envioronment for the
input file (I have verified that the text file is accurate). As a test
(read: troubleshooting) if I modify this script slight so that I simply
manually enter in the computer (strComputer = "EXCH01") - thus, removing the
use of the input file and the "DO Until ... LOOP" - it runs fine. However,
I really would like to resolve this as some environments have some 20
servers (we have about six of those....really do not want to have to do
this!).

However, I have several other scripts of this nature that work fine! I am
missing something here!

Thanks!


'==================================================================================================
'
' VBScript Source File
'
' NAME: Query-Specific-Services.VBS
' VERSION: 1.0
' COMPANY: XXX
' AUTHOR: XXX
' CREATE DATE : 07/06/2009
' LAST MODIFIED : n/a
'==================================================================================================
' COMMENT: This script will determine if the pre-defined services are
running on the servers
'==================================================================================================


Option Explicit

Dim objWMIService, colServices, objService
Dim objFSO, objTextFile, objTS
Dim strComputer
Dim strInputFile, strOutputFile
Dim colServicesDHCP, colServicesDNS, colServicesWINS, colServicesRRAS,
colServicesIAS, colServicesIndex, colServicesTSLS, colServicesBackup
Dim objServiceDHCP, objServiceDNS, objServiceWINS, objServiceRRAS,
objServiceIAS, objServiceIndex, objServiceTSLS, objServiceBackup
Dim strDHCPService, strDHCPServiceStartMode, strDHCPState
Dim strDNSService, strDNSServiceStartMode, strDNSState
Dim strWINSService, strWINSServiceStartMode, strWINSState
Dim strRRASService, strRRASServiceStartMode, strRRASState
Dim strIASService, strIASServiceStartMode, strIASState
Dim strIndexService, strIndexServiceStartMode, strIndexState
Dim strTSLSService, strTSLSServiceStartMode, strTSLSState
Dim strBackupService, strBackupServiceStartMode, strBackupState

CONST ForReading = 1
CONST ForWriting = 2

strInputFile = "C:\Scripts\Servers Info\Servers-TxtFile.txt"
strOutputFile = "C:\Scripts\Results\Services-Running.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(strInputFile,ForReading)
Set objTS = objFSO.CreateTextFile(strOutputFile,ForWriting,False)

Do Until objTextFile.AtEndOfStream
strcomputer = objTextFile.Readline

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" &
strComputer & "\root\cimv2")


If (Err.Number <> 0) Then
objTS.WriteLine string(50,".")
objTS.WriteLine string(50,".")
objTS.WriteLine "ERROR: Unable to connect to the WMI NameSpace on " &
strComputer
objTS.WriteLine string(50,".")
objTS.WriteLine string(50,".")
objTS.WriteLine()
Err.Clear
Else

Set colServicesDHCP = objWMIService.ExecQuery("SELECT * FROM
Win32_Service WHERE Name = 'DHCPServer'",,48)
Set colServicesDNS = objWMIService.ExecQuery("SELECT * FROM Win32_Service
WHERE Name = 'DNS'",,48)
Set colServicesWINS = objWMIService.ExecQuery("SELECT * FROM
Win32_Service WHERE Name = 'WINS'",,48)
Set colServicesRRAS = objWMIService.ExecQuery("SELECT * FROM
Win32_Service WHERE Name = 'RemoteAccess'",,48)
Set colServicesIAS = objWMIService.ExecQuery("SELECT * FROM Win32_Service
WHERE Name = 'IAS'",,48)
Set colServicesIndex = objWMIService.ExecQuery("SELECT * FROM
Win32_Service WHERE Name = 'CiSvc'",,48)
Set colServicesTSLS = objWMIService.ExecQuery("SELECT * FROM
Win32_Service WHERE Name = 'TermServLicensing'",,48)
Set colServicesBackUp = objWMIService.ExecQuery("SELECT * FROM
Win32_Service WHERE Name = 'BackupExecJobEngine'",,48)


For Each objServiceDHCP in colServicesDHCP
strDHCPService = objServiceDHCP.DisplayName
strDHCPServiceStartMode = objServiceDHCP.StartMode
strDHCPState = objServiceDHCP.State
NEXT

For Each objServiceDNS in colServicesDNS
strDNSService = objServiceDNS.DisplayName
strDNSServiceStartMode = objServiceDNS.StartMode
strDNSState = objServiceDNS.State
NEXT

For Each objServiceWINS in colServicesWINS
strWINSService = objServiceWINS.DisplayName
strWINSServiceStartMode = objServiceWINS.StartMode
strWINSState = objServiceWINS.State
NEXT

For Each objServiceRRAS in colServicesRRAS
strRRASService = objServiceRRAS.DisplayName
strRRASServiceStartMode = objServiceRRAS.StartMode
strRRASState = objServiceRRAS.State
NEXT

For Each objServiceIAS in colServicesIAS
strIASService = objServiceIAS.DisplayName
strIASServiceStartMode = objServiceIAS.StartMode
strIASState = objServiceIAS.State
NEXT

For Each objServiceIndex in colServicesIndex
strIndexService = objServiceIndex.DisplayName
strIndexServiceStartMode = objServiceIndex.StartMode
strIndexState = objServiceIndex.State
NEXT


For Each objServiceTSLS in colServicesTSLS
strTSLSService = objServiceTSLS.DisplayName
strTSLSServiceStartMode = objServiceTSLS.StartMode
strTSLSState = objServiceTSLS.State
NEXT

For Each objServiceBackup in colServicesBackup
strBackupService = objServiceBackup.DisplayName
strBackupServiceStartMode = objServiceBackup.StartMode
strBackupState = objServiceBackup.State
NEXT


objTS.WriteLine string(50,"=")
objTS.WriteLine string(50,"=")
objTS.WriteLine "Computer Name: " & strComputer
objTS.WriteLine string(50,"=")
objTS.WriteLine string(50,"=")
objTS.WriteLine "DHCP Service: " & strDHCPService
objTS.WriteLine "DHCP Start UP: " & strDHCPServiceStartMode
objTS.WriteLine "DHCP Running: " & strDHCPState
objTS.WriteLine string(50,".")
objTS.WriteLine "DNS Service: " & strDNSService
objTS.WriteLine "DNS Start Up: " & strDNSServiceStartMode
objTS.WriteLine "DNS Running: " & strDNSState
objTS.WriteLine string(50,".")
objTS.WriteLine "WINS Service: " & strWINSService
objTS.WriteLine "WINS Start Up: " & strWINSServiceStartMode
objTS.WriteLine "WINS Running: " & strWINSState
objTS.WriteLine string(50,".")
objTS.WriteLine "RRAS Service: " & strRRASService
objTS.WriteLine "RRAS Start Up: " & strRRASServiceStartMode
objTS.WriteLine "RRAS Running: " & strRRASState
objTS.WriteLine string(50,".")
objTS.WriteLine "IAS Service: " & strIASService
objTS.WriteLine "IAS Start Up: " & strIASServiceStartMode
objTS.WriteLine "IAS Running: " & strIASState
objTS.WriteLine string(50,".")
objTS.WriteLine "Index Service: " & strIndexService
objTS.WriteLine "Index Start Up: " & strIndexServiceStartMode
objTS.WriteLine "Index Running: " & strIndexState
objTS.WriteLine string(50,".")
objTS.WriteLine "TSLS Server: " & strTSLSService
objTS.WriteLine "TSLS Start Up: " & strTSLSServiceStartMode
objTS.WriteLine "TSLS Running: " & strTSLSState
objTS.WriteLine string(50,".")
objTS.WriteLine "Backup Server: " & strBackupService
objTS.WriteLine "Backup Start Up: " & strBackupServiceStartMode
objTS.WriteLine "Backup Running: " & strBackupState
objTS.WriteLine()
objTS.WriteLine()

End If

Loop


objTextFile.Close
objTS.Close

Set objTextFile = Nothing
Set objTS = Nothing
Set objFSO = Nothing


My System SpecsSystem Spec
Old 07-06-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: Can anyone offer assitance with this script?


"Cary Shultz" <cshultz@xxxxxx> wrote in message
news:OZlB2hn$JHA.3612@xxxxxx
Quote:

> Good afternoon!
>
> Please find below the script. It is rather long. Sorry.
>
> This script is doing something funny...when I run it in environments where
> there is but one server I have no issues. However, when I run in it
> environments where there are multiple environments I have issues. It
> seems that the results of the first computer are carried over into the
> results of the succedding computers.
>
> I am using a text file that contains each server in the envioronment for
> the input file (I have verified that the text file is accurate). As a
> test (read: troubleshooting) if I modify this script slight so that I
> simply manually enter in the computer (strComputer = "EXCH01") - thus,
> removing the use of the input file and the "DO Until ... LOOP" - it runs
> fine. However, I really would like to resolve this as some environments
> have some 20 servers (we have about six of those....really do not want to
> have to do this!).
>
> However, I have several other scripts of this nature that work fine! I am
> missing something here!
>
> Thanks!
>
>
> '==================================================================================================
> '
> ' VBScript Source File
> '
> ' NAME: Query-Specific-Services.VBS
> ' VERSION: 1.0
> ' COMPANY: XXX
> ' AUTHOR: XXX
> ' CREATE DATE : 07/06/2009
> ' LAST MODIFIED : n/a
> '==================================================================================================
> ' COMMENT: This script will determine if the pre-defined services are
> running on the servers
> '==================================================================================================
>
>
> Option Explicit
>
> Dim objWMIService, colServices, objService
> Dim objFSO, objTextFile, objTS
> Dim strComputer
> Dim strInputFile, strOutputFile
> Dim colServicesDHCP, colServicesDNS, colServicesWINS, colServicesRRAS,
> colServicesIAS, colServicesIndex, colServicesTSLS, colServicesBackup
> Dim objServiceDHCP, objServiceDNS, objServiceWINS, objServiceRRAS,
> objServiceIAS, objServiceIndex, objServiceTSLS, objServiceBackup
> Dim strDHCPService, strDHCPServiceStartMode, strDHCPState
> Dim strDNSService, strDNSServiceStartMode, strDNSState
> Dim strWINSService, strWINSServiceStartMode, strWINSState
> Dim strRRASService, strRRASServiceStartMode, strRRASState
> Dim strIASService, strIASServiceStartMode, strIASState
> Dim strIndexService, strIndexServiceStartMode, strIndexState
> Dim strTSLSService, strTSLSServiceStartMode, strTSLSState
> Dim strBackupService, strBackupServiceStartMode, strBackupState
>
> CONST ForReading = 1
> CONST ForWriting = 2
>
> strInputFile = "C:\Scripts\Servers Info\Servers-TxtFile.txt"
> strOutputFile = "C:\Scripts\Results\Services-Running.txt"
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile(strInputFile,ForReading)
> Set objTS = objFSO.CreateTextFile(strOutputFile,ForWriting,False)
>
> Do Until objTextFile.AtEndOfStream
> strcomputer = objTextFile.Readline
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" &
> strComputer & "\root\cimv2")
>
>
> If (Err.Number <> 0) Then
> objTS.WriteLine string(50,".")
> objTS.WriteLine string(50,".")
> objTS.WriteLine "ERROR: Unable to connect to the WMI NameSpace on " &
> strComputer
> objTS.WriteLine string(50,".")
> objTS.WriteLine string(50,".")
> objTS.WriteLine()
> Err.Clear
> Else
>
> Set colServicesDHCP = objWMIService.ExecQuery("SELECT * FROM
> Win32_Service WHERE Name = 'DHCPServer'",,48)
> Set colServicesDNS = objWMIService.ExecQuery("SELECT * FROM
> Win32_Service WHERE Name = 'DNS'",,48)
> Set colServicesWINS = objWMIService.ExecQuery("SELECT * FROM
> Win32_Service WHERE Name = 'WINS'",,48)
> Set colServicesRRAS = objWMIService.ExecQuery("SELECT * FROM
> Win32_Service WHERE Name = 'RemoteAccess'",,48)
> Set colServicesIAS = objWMIService.ExecQuery("SELECT * FROM
> Win32_Service WHERE Name = 'IAS'",,48)
> Set colServicesIndex = objWMIService.ExecQuery("SELECT * FROM
> Win32_Service WHERE Name = 'CiSvc'",,48)
> Set colServicesTSLS = objWMIService.ExecQuery("SELECT * FROM
> Win32_Service WHERE Name = 'TermServLicensing'",,48)
> Set colServicesBackUp = objWMIService.ExecQuery("SELECT * FROM
> Win32_Service WHERE Name = 'BackupExecJobEngine'",,48)
>
>
> For Each objServiceDHCP in colServicesDHCP
> strDHCPService = objServiceDHCP.DisplayName
> strDHCPServiceStartMode = objServiceDHCP.StartMode
> strDHCPState = objServiceDHCP.State
> NEXT
>
> For Each objServiceDNS in colServicesDNS
> strDNSService = objServiceDNS.DisplayName
> strDNSServiceStartMode = objServiceDNS.StartMode
> strDNSState = objServiceDNS.State
> NEXT
>
> For Each objServiceWINS in colServicesWINS
> strWINSService = objServiceWINS.DisplayName
> strWINSServiceStartMode = objServiceWINS.StartMode
> strWINSState = objServiceWINS.State
> NEXT
>
> For Each objServiceRRAS in colServicesRRAS
> strRRASService = objServiceRRAS.DisplayName
> strRRASServiceStartMode = objServiceRRAS.StartMode
> strRRASState = objServiceRRAS.State
> NEXT
>
> For Each objServiceIAS in colServicesIAS
> strIASService = objServiceIAS.DisplayName
> strIASServiceStartMode = objServiceIAS.StartMode
> strIASState = objServiceIAS.State
> NEXT
>
> For Each objServiceIndex in colServicesIndex
> strIndexService = objServiceIndex.DisplayName
> strIndexServiceStartMode = objServiceIndex.StartMode
> strIndexState = objServiceIndex.State
> NEXT
>
>
> For Each objServiceTSLS in colServicesTSLS
> strTSLSService = objServiceTSLS.DisplayName
> strTSLSServiceStartMode = objServiceTSLS.StartMode
> strTSLSState = objServiceTSLS.State
> NEXT
>
> For Each objServiceBackup in colServicesBackup
> strBackupService = objServiceBackup.DisplayName
> strBackupServiceStartMode = objServiceBackup.StartMode
> strBackupState = objServiceBackup.State
> NEXT
>
>
> objTS.WriteLine string(50,"=")
> objTS.WriteLine string(50,"=")
> objTS.WriteLine "Computer Name: " & strComputer
> objTS.WriteLine string(50,"=")
> objTS.WriteLine string(50,"=")
> objTS.WriteLine "DHCP Service: " & strDHCPService
> objTS.WriteLine "DHCP Start UP: " & strDHCPServiceStartMode
> objTS.WriteLine "DHCP Running: " & strDHCPState
> objTS.WriteLine string(50,".")
> objTS.WriteLine "DNS Service: " & strDNSService
> objTS.WriteLine "DNS Start Up: " & strDNSServiceStartMode
> objTS.WriteLine "DNS Running: " & strDNSState
> objTS.WriteLine string(50,".")
> objTS.WriteLine "WINS Service: " & strWINSService
> objTS.WriteLine "WINS Start Up: " & strWINSServiceStartMode
> objTS.WriteLine "WINS Running: " & strWINSState
> objTS.WriteLine string(50,".")
> objTS.WriteLine "RRAS Service: " & strRRASService
> objTS.WriteLine "RRAS Start Up: " & strRRASServiceStartMode
> objTS.WriteLine "RRAS Running: " & strRRASState
> objTS.WriteLine string(50,".")
> objTS.WriteLine "IAS Service: " & strIASService
> objTS.WriteLine "IAS Start Up: " & strIASServiceStartMode
> objTS.WriteLine "IAS Running: " & strIASState
> objTS.WriteLine string(50,".")
> objTS.WriteLine "Index Service: " & strIndexService
> objTS.WriteLine "Index Start Up: " & strIndexServiceStartMode
> objTS.WriteLine "Index Running: " & strIndexState
> objTS.WriteLine string(50,".")
> objTS.WriteLine "TSLS Server: " & strTSLSService
> objTS.WriteLine "TSLS Start Up: " & strTSLSServiceStartMode
> objTS.WriteLine "TSLS Running: " & strTSLSState
> objTS.WriteLine string(50,".")
> objTS.WriteLine "Backup Server: " & strBackupService
> objTS.WriteLine "Backup Start Up: " & strBackupServiceStartMode
> objTS.WriteLine "Backup Running: " & strBackupState
> objTS.WriteLine()
> objTS.WriteLine()
>
> End If
>
> Loop
>
>
> objTextFile.Close
> objTS.Close
>
> Set objTextFile = Nothing
> Set objTS = Nothing
> Set objFSO = Nothing
Let's assume that WINS is installed on Server1. You therefore execute this
loop:
For Each objServiceWINS in colServicesWINS
strWINSService = objServiceWINS.DisplayName
strWINSServiceStartMode = objServiceWINS.StartMode
strWINSState = objServiceWINS.State
NEXT

Let's assume that WINS is not installed on Server2. You will now skip the
above loop - but the values you assigned to your three strings will persist
because you never cleared them.


My System SpecsSystem Spec
Old 07-06-2009   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: Can anyone offer assitance with this script?


"Pegasus [MVP]" <news@xxxxxx> wrote in message
news:uWOXLGo$JHA.5780@xxxxxx
Quote:

>
> "Cary Shultz" <cshultz@xxxxxx> wrote in message
> news:OZlB2hn$JHA.3612@xxxxxx
Quote:

>> Good afternoon!
>>
>> Please find below the script. It is rather long. Sorry.
>>
>> This script is doing something funny...when I run it in environments
>> where there is but one server I have no issues. However, when I run in
>> it environments where there are multiple environments I have issues. It
>> seems that the results of the first computer are carried over into the
>> results of the succedding computers.
>>
>> I am using a text file that contains each server in the envioronment for
>> the input file (I have verified that the text file is accurate). As a
>> test (read: troubleshooting) if I modify this script slight so that I
>> simply manually enter in the computer (strComputer = "EXCH01") - thus,
>> removing the use of the input file and the "DO Until ... LOOP" - it runs
>> fine. However, I really would like to resolve this as some environments
>> have some 20 servers (we have about six of those....really do not want to
>> have to do this!).
>>
>> However, I have several other scripts of this nature that work fine! I
>> am missing something here!
>>
>> Thanks!
>>
>>
>> '==================================================================================================
>> '
>> ' VBScript Source File
>> '
>> ' NAME: Query-Specific-Services.VBS
>> ' VERSION: 1.0
>> ' COMPANY: XXX
>> ' AUTHOR: XXX
>> ' CREATE DATE : 07/06/2009
>> ' LAST MODIFIED : n/a
>> '==================================================================================================
>> ' COMMENT: This script will determine if the pre-defined services are
>> running on the servers
>> '==================================================================================================
>>
>>
>> Option Explicit
>>
>> Dim objWMIService, colServices, objService
>> Dim objFSO, objTextFile, objTS
>> Dim strComputer
>> Dim strInputFile, strOutputFile
>> Dim colServicesDHCP, colServicesDNS, colServicesWINS, colServicesRRAS,
>> colServicesIAS, colServicesIndex, colServicesTSLS, colServicesBackup
>> Dim objServiceDHCP, objServiceDNS, objServiceWINS, objServiceRRAS,
>> objServiceIAS, objServiceIndex, objServiceTSLS, objServiceBackup
>> Dim strDHCPService, strDHCPServiceStartMode, strDHCPState
>> Dim strDNSService, strDNSServiceStartMode, strDNSState
>> Dim strWINSService, strWINSServiceStartMode, strWINSState
>> Dim strRRASService, strRRASServiceStartMode, strRRASState
>> Dim strIASService, strIASServiceStartMode, strIASState
>> Dim strIndexService, strIndexServiceStartMode, strIndexState
>> Dim strTSLSService, strTSLSServiceStartMode, strTSLSState
>> Dim strBackupService, strBackupServiceStartMode, strBackupState
>>
>> CONST ForReading = 1
>> CONST ForWriting = 2
>>
>> strInputFile = "C:\Scripts\Servers Info\Servers-TxtFile.txt"
>> strOutputFile = "C:\Scripts\Results\Services-Running.txt"
>>
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> Set objTextFile = objFSO.OpenTextFile(strInputFile,ForReading)
>> Set objTS = objFSO.CreateTextFile(strOutputFile,ForWriting,False)
>>
>> Do Until objTextFile.AtEndOfStream
>> strcomputer = objTextFile.Readline
>>
>> Set objWMIService = GetObject("winmgmts:" _
>> & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" &
>> strComputer & "\root\cimv2")
>>
>>
>> If (Err.Number <> 0) Then
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "ERROR: Unable to connect to the WMI NameSpace on " &
>> strComputer
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine()
>> Err.Clear
>> Else
>>
>> Set colServicesDHCP = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'DHCPServer'",,48)
>> Set colServicesDNS = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'DNS'",,48)
>> Set colServicesWINS = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'WINS'",,48)
>> Set colServicesRRAS = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'RemoteAccess'",,48)
>> Set colServicesIAS = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'IAS'",,48)
>> Set colServicesIndex = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'CiSvc'",,48)
>> Set colServicesTSLS = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'TermServLicensing'",,48)
>> Set colServicesBackUp = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'BackupExecJobEngine'",,48)
>>
>>
>> For Each objServiceDHCP in colServicesDHCP
>> strDHCPService = objServiceDHCP.DisplayName
>> strDHCPServiceStartMode = objServiceDHCP.StartMode
>> strDHCPState = objServiceDHCP.State
>> NEXT
>>
>> For Each objServiceDNS in colServicesDNS
>> strDNSService = objServiceDNS.DisplayName
>> strDNSServiceStartMode = objServiceDNS.StartMode
>> strDNSState = objServiceDNS.State
>> NEXT
>>
>> For Each objServiceWINS in colServicesWINS
>> strWINSService = objServiceWINS.DisplayName
>> strWINSServiceStartMode = objServiceWINS.StartMode
>> strWINSState = objServiceWINS.State
>> NEXT
>>
>> For Each objServiceRRAS in colServicesRRAS
>> strRRASService = objServiceRRAS.DisplayName
>> strRRASServiceStartMode = objServiceRRAS.StartMode
>> strRRASState = objServiceRRAS.State
>> NEXT
>>
>> For Each objServiceIAS in colServicesIAS
>> strIASService = objServiceIAS.DisplayName
>> strIASServiceStartMode = objServiceIAS.StartMode
>> strIASState = objServiceIAS.State
>> NEXT
>>
>> For Each objServiceIndex in colServicesIndex
>> strIndexService = objServiceIndex.DisplayName
>> strIndexServiceStartMode = objServiceIndex.StartMode
>> strIndexState = objServiceIndex.State
>> NEXT
>>
>>
>> For Each objServiceTSLS in colServicesTSLS
>> strTSLSService = objServiceTSLS.DisplayName
>> strTSLSServiceStartMode = objServiceTSLS.StartMode
>> strTSLSState = objServiceTSLS.State
>> NEXT
>>
>> For Each objServiceBackup in colServicesBackup
>> strBackupService = objServiceBackup.DisplayName
>> strBackupServiceStartMode = objServiceBackup.StartMode
>> strBackupState = objServiceBackup.State
>> NEXT
>>
>>
>> objTS.WriteLine string(50,"=")
>> objTS.WriteLine string(50,"=")
>> objTS.WriteLine "Computer Name: " & strComputer
>> objTS.WriteLine string(50,"=")
>> objTS.WriteLine string(50,"=")
>> objTS.WriteLine "DHCP Service: " & strDHCPService
>> objTS.WriteLine "DHCP Start UP: " & strDHCPServiceStartMode
>> objTS.WriteLine "DHCP Running: " & strDHCPState
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "DNS Service: " & strDNSService
>> objTS.WriteLine "DNS Start Up: " & strDNSServiceStartMode
>> objTS.WriteLine "DNS Running: " & strDNSState
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "WINS Service: " & strWINSService
>> objTS.WriteLine "WINS Start Up: " & strWINSServiceStartMode
>> objTS.WriteLine "WINS Running: " & strWINSState
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "RRAS Service: " & strRRASService
>> objTS.WriteLine "RRAS Start Up: " & strRRASServiceStartMode
>> objTS.WriteLine "RRAS Running: " & strRRASState
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "IAS Service: " & strIASService
>> objTS.WriteLine "IAS Start Up: " & strIASServiceStartMode
>> objTS.WriteLine "IAS Running: " & strIASState
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "Index Service: " & strIndexService
>> objTS.WriteLine "Index Start Up: " & strIndexServiceStartMode
>> objTS.WriteLine "Index Running: " & strIndexState
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "TSLS Server: " & strTSLSService
>> objTS.WriteLine "TSLS Start Up: " & strTSLSServiceStartMode
>> objTS.WriteLine "TSLS Running: " & strTSLSState
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "Backup Server: " & strBackupService
>> objTS.WriteLine "Backup Start Up: " & strBackupServiceStartMode
>> objTS.WriteLine "Backup Running: " & strBackupState
>> objTS.WriteLine()
>> objTS.WriteLine()
>>
>> End If
>>
>> Loop
>>
>>
>> objTextFile.Close
>> objTS.Close
>>
>> Set objTextFile = Nothing
>> Set objTS = Nothing
>> Set objFSO = Nothing
>
> Let's assume that WINS is installed on Server1. You therefore execute this
> loop:
> For Each objServiceWINS in colServicesWINS
> strWINSService = objServiceWINS.DisplayName
> strWINSServiceStartMode = objServiceWINS.StartMode
> strWINSState = objServiceWINS.State
> NEXT
>
> Let's assume that WINS is not installed on Server2. You will now skip the
> above loop - but the values you assigned to your three strings will
> persist because you never cleared them.

Also, you check for errors, but do not disable normal error handling. I
would suggest (in part):
========
Do Until objTextFile.AtEndOfStream
strcomputer = objTextFile.Readline

On Error Resume Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" &
strComputer & "\root\cimv2")

If (Err.Number <> 0) Then
On Error GoTo 0
objTS.WriteLine string(50,".")
objTS.WriteLine string(50,".")
objTS.WriteLine "ERROR: Unable to connect to the WMI NameSpace on " &
strComputer
objTS.WriteLine string(50,".")
objTS.WriteLine string(50,".")
objTS.WriteLine()
Else
On Error GoTo 0
========
Otherwise the script will halt if an error is raised when it attempts to
connect to the remote computer.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 07-06-2009   #4 (permalink)
Pegasus [MVP]


 
 

Re: Can anyone offer assitance with this script?


"Cary Shultz" <cshultz@xxxxxx> wrote in message
news:OZlB2hn$JHA.3612@xxxxxx
Quote:

> Good afternoon!
>
> Please find below the script. It is rather long. Sorry.
>
> This script is doing something funny...when I run it in environments where
> there is but one server I have no issues. However, when I run in it
> environments where there are multiple environments I have issues. It
> seems that the results of the first computer are carried over into the
> results of the succedding computers.
>
> I am using a text file that contains each server in the envioronment for
> the input file (I have verified that the text file is accurate). As a
> test (read: troubleshooting) if I modify this script slight so that I
> simply manually enter in the computer (strComputer = "EXCH01") - thus,
> removing the use of the input file and the "DO Until ... LOOP" - it runs
> fine. However, I really would like to resolve this as some environments
> have some 20 servers (we have about six of those....really do not want to
> have to do this!).
>
> However, I have several other scripts of this nature that work fine! I am
> missing something here!
>
> Thanks!
A couple of additonal thoughts:
- Since your repeatedly executing the code that examines a service, you
could create a subroutine that performs the job. The lines 35..38 in the
code below do this - add further lines to your liking. As a fringe benefit
this method eliminates the need to reset your various strings. You need to
restore your text formatting, of course.
- To deal with machines that are inaccessible, you *must* insert an "on
error resume next" statement as shown in line 20 below.

[01] Option Explicit
[02]
[03] Dim objFSO, objTextFile, objTS
[04] Dim strComputer
[05] Dim strInputFile, strOutputFile
[06]
[07] Const ForReading = 1
[08] Const ForWriting = 2
[09]
[10] strInputFile = "d:\Servers.txt"
[11] strOutputFile = "d:\Output.txt"
[12]
[13] Set objFSO = CreateObject("Scripting.FileSystemObject")
[14] Set objTextFile = objFSO.OpenTextFile(strInputFile,ForReading)
[15] Set objTS = objFSO.CreateTextFile(strOutputFile,ForWriting,False)
[16]
[17] Do Until objTextFile.AtEndOfStream
[18] strComputer = objTextFile.Readline
[19]
[20] On Error Resume Next
[21] Set objWMIService = GetObject("winmgmts:" _
[22] & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
[23] & strComputer & "\root\cimv2")
[24]
[25] If (Err.Number <> 0) Then
[26] objTS.WriteLine String(50,".")
[27] objTS.WriteLine String(50,".")
[28] objTS.WriteLine "ERROR: Unable to connect to the WMI NameSpace on " _
[29] & strComputer
[30] objTS.WriteLine String(50,".")
[31] objTS.WriteLine String(50,".")
[32] objTS.WriteLine()
[33] Err.Clear
[34] Else
[35] objTS.WriteLine strComputer
[36] GetServiceDetails "Windows VNC: ", "'WinVNC'"
[37] GetServiceDetails "DHCP Server: ", "'DHCP'"
[38] GetServiceDetails "RRAS Service: ", "'RRAS'"
[39] End If
[40] On Error Goto 0
[41] Loop
[42] objTextFile.Close
[43] objTS.Close
[44] Set objTextFile = Nothing
[45] Set objTS = Nothing
[46] Set objFSO = Nothing
[47] '------------------------------------
[48] Sub GetServiceDetails (Description, ServiceName)
[49] Dim objWMIService, colServices, objService
[50] Set colServices = objWMIService.ExecQuery("SELECT * FROM Win32_Service
" _
[51] & "WHERE Name = " & ServiceName, , 48)
[52] For Each objService In colServices
[53] objTS.WriteLine Description & objService.DisplayName
[54] objTS.WriteLine "Start Up: " & objService.StartMode
[55] objTS.WriteLine "Running: " & objService.State
[56] objTS.writeline
[57] Next
[58] Set colServices = Nothing
[59] End Sub


My System SpecsSystem Spec
Old 07-06-2009   #5 (permalink)
Cary Shultz


 
 

Re: Can anyone offer assitance with this script?


"Pegasus [MVP]" <news@xxxxxx> wrote in message
news:uWOXLGo$JHA.5780@xxxxxx
Quote:

>
> "Cary Shultz" <cshultz@xxxxxx> wrote in message
> news:OZlB2hn$JHA.3612@xxxxxx
Quote:

>> Good afternoon!
>>
>> Please find below the script. It is rather long. Sorry.
>>
>> This script is doing something funny...when I run it in environments
>> where there is but one server I have no issues. However, when I run in
>> it environments where there are multiple environments I have issues. It
>> seems that the results of the first computer are carried over into the
>> results of the succedding computers.
>>
>> I am using a text file that contains each server in the envioronment for
>> the input file (I have verified that the text file is accurate). As a
>> test (read: troubleshooting) if I modify this script slight so that I
>> simply manually enter in the computer (strComputer = "EXCH01") - thus,
>> removing the use of the input file and the "DO Until ... LOOP" - it runs
>> fine. However, I really would like to resolve this as some environments
>> have some 20 servers (we have about six of those....really do not want to
>> have to do this!).
>>
>> However, I have several other scripts of this nature that work fine! I
>> am missing something here!
>>
>> Thanks!
>>
>>
>> '==================================================================================================
>> '
>> ' VBScript Source File
>> '
>> ' NAME: Query-Specific-Services.VBS
>> ' VERSION: 1.0
>> ' COMPANY: XXX
>> ' AUTHOR: XXX
>> ' CREATE DATE : 07/06/2009
>> ' LAST MODIFIED : n/a
>> '==================================================================================================
>> ' COMMENT: This script will determine if the pre-defined services are
>> running on the servers
>> '==================================================================================================
>>
>>
>> Option Explicit
>>
>> Dim objWMIService, colServices, objService
>> Dim objFSO, objTextFile, objTS
>> Dim strComputer
>> Dim strInputFile, strOutputFile
>> Dim colServicesDHCP, colServicesDNS, colServicesWINS, colServicesRRAS,
>> colServicesIAS, colServicesIndex, colServicesTSLS, colServicesBackup
>> Dim objServiceDHCP, objServiceDNS, objServiceWINS, objServiceRRAS,
>> objServiceIAS, objServiceIndex, objServiceTSLS, objServiceBackup
>> Dim strDHCPService, strDHCPServiceStartMode, strDHCPState
>> Dim strDNSService, strDNSServiceStartMode, strDNSState
>> Dim strWINSService, strWINSServiceStartMode, strWINSState
>> Dim strRRASService, strRRASServiceStartMode, strRRASState
>> Dim strIASService, strIASServiceStartMode, strIASState
>> Dim strIndexService, strIndexServiceStartMode, strIndexState
>> Dim strTSLSService, strTSLSServiceStartMode, strTSLSState
>> Dim strBackupService, strBackupServiceStartMode, strBackupState
>>
>> CONST ForReading = 1
>> CONST ForWriting = 2
>>
>> strInputFile = "C:\Scripts\Servers Info\Servers-TxtFile.txt"
>> strOutputFile = "C:\Scripts\Results\Services-Running.txt"
>>
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> Set objTextFile = objFSO.OpenTextFile(strInputFile,ForReading)
>> Set objTS = objFSO.CreateTextFile(strOutputFile,ForWriting,False)
>>
>> Do Until objTextFile.AtEndOfStream
>> strcomputer = objTextFile.Readline
>>
>> Set objWMIService = GetObject("winmgmts:" _
>> & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" &
>> strComputer & "\root\cimv2")
>>
>>
>> If (Err.Number <> 0) Then
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "ERROR: Unable to connect to the WMI NameSpace on " &
>> strComputer
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine()
>> Err.Clear
>> Else
>>
>> Set colServicesDHCP = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'DHCPServer'",,48)
>> Set colServicesDNS = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'DNS'",,48)
>> Set colServicesWINS = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'WINS'",,48)
>> Set colServicesRRAS = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'RemoteAccess'",,48)
>> Set colServicesIAS = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'IAS'",,48)
>> Set colServicesIndex = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'CiSvc'",,48)
>> Set colServicesTSLS = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'TermServLicensing'",,48)
>> Set colServicesBackUp = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'BackupExecJobEngine'",,48)
>>
>>
>> For Each objServiceDHCP in colServicesDHCP
>> strDHCPService = objServiceDHCP.DisplayName
>> strDHCPServiceStartMode = objServiceDHCP.StartMode
>> strDHCPState = objServiceDHCP.State
>> NEXT
>>
>> For Each objServiceDNS in colServicesDNS
>> strDNSService = objServiceDNS.DisplayName
>> strDNSServiceStartMode = objServiceDNS.StartMode
>> strDNSState = objServiceDNS.State
>> NEXT
>>
>> For Each objServiceWINS in colServicesWINS
>> strWINSService = objServiceWINS.DisplayName
>> strWINSServiceStartMode = objServiceWINS.StartMode
>> strWINSState = objServiceWINS.State
>> NEXT
>>
>> For Each objServiceRRAS in colServicesRRAS
>> strRRASService = objServiceRRAS.DisplayName
>> strRRASServiceStartMode = objServiceRRAS.StartMode
>> strRRASState = objServiceRRAS.State
>> NEXT
>>
>> For Each objServiceIAS in colServicesIAS
>> strIASService = objServiceIAS.DisplayName
>> strIASServiceStartMode = objServiceIAS.StartMode
>> strIASState = objServiceIAS.State
>> NEXT
>>
>> For Each objServiceIndex in colServicesIndex
>> strIndexService = objServiceIndex.DisplayName
>> strIndexServiceStartMode = objServiceIndex.StartMode
>> strIndexState = objServiceIndex.State
>> NEXT
>>
>>
>> For Each objServiceTSLS in colServicesTSLS
>> strTSLSService = objServiceTSLS.DisplayName
>> strTSLSServiceStartMode = objServiceTSLS.StartMode
>> strTSLSState = objServiceTSLS.State
>> NEXT
>>
>> For Each objServiceBackup in colServicesBackup
>> strBackupService = objServiceBackup.DisplayName
>> strBackupServiceStartMode = objServiceBackup.StartMode
>> strBackupState = objServiceBackup.State
>> NEXT
>>
>>
>> objTS.WriteLine string(50,"=")
>> objTS.WriteLine string(50,"=")
>> objTS.WriteLine "Computer Name: " & strComputer
>> objTS.WriteLine string(50,"=")
>> objTS.WriteLine string(50,"=")
>> objTS.WriteLine "DHCP Service: " & strDHCPService
>> objTS.WriteLine "DHCP Start UP: " & strDHCPServiceStartMode
>> objTS.WriteLine "DHCP Running: " & strDHCPState
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "DNS Service: " & strDNSService
>> objTS.WriteLine "DNS Start Up: " & strDNSServiceStartMode
>> objTS.WriteLine "DNS Running: " & strDNSState
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "WINS Service: " & strWINSService
>> objTS.WriteLine "WINS Start Up: " & strWINSServiceStartMode
>> objTS.WriteLine "WINS Running: " & strWINSState
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "RRAS Service: " & strRRASService
>> objTS.WriteLine "RRAS Start Up: " & strRRASServiceStartMode
>> objTS.WriteLine "RRAS Running: " & strRRASState
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "IAS Service: " & strIASService
>> objTS.WriteLine "IAS Start Up: " & strIASServiceStartMode
>> objTS.WriteLine "IAS Running: " & strIASState
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "Index Service: " & strIndexService
>> objTS.WriteLine "Index Start Up: " & strIndexServiceStartMode
>> objTS.WriteLine "Index Running: " & strIndexState
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "TSLS Server: " & strTSLSService
>> objTS.WriteLine "TSLS Start Up: " & strTSLSServiceStartMode
>> objTS.WriteLine "TSLS Running: " & strTSLSState
>> objTS.WriteLine string(50,".")
>> objTS.WriteLine "Backup Server: " & strBackupService
>> objTS.WriteLine "Backup Start Up: " & strBackupServiceStartMode
>> objTS.WriteLine "Backup Running: " & strBackupState
>> objTS.WriteLine()
>> objTS.WriteLine()
>>
>> End If
>>
>> Loop
>>
>>
>> objTextFile.Close
>> objTS.Close
>>
>> Set objTextFile = Nothing
>> Set objTS = Nothing
>> Set objFSO = Nothing
>
> Let's assume that WINS is installed on Server1. You therefore execute this
> loop:
> For Each objServiceWINS in colServicesWINS
> strWINSService = objServiceWINS.DisplayName
> strWINSServiceStartMode = objServiceWINS.StartMode
> strWINSState = objServiceWINS.State
> NEXT
>
> Let's assume that WINS is not installed on Server2. You will now skip the
> above loop - but the values you assigned to your three strings will
> persist because you never cleared them.
>
Pegasus,

Thanks. I kinda figured that is what was going on.....because, for example,
if RRAS is installed on Server1 (Started and Automatic) but not on Server2
and specifically disabled on Server3 and on Server4 it will show as Started
and Automatic on Server2 (where it should be - in my example - blank) but
have the correct "values" on Server3 and on Server4.

So, my second question for you is this.....how do I clear them?

This also means that I need to 'fix' the other scripts....

Thanks,

Cary


My System SpecsSystem Spec
Old 07-06-2009   #6 (permalink)
Cary Shultz


 
 

Re: Can anyone offer assitance with this script?


"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:%23YZBKWo$JHA.1376@xxxxxx
Quote:

>
> "Pegasus [MVP]" <news@xxxxxx> wrote in message
> news:uWOXLGo$JHA.5780@xxxxxx
Quote:

>>
>> "Cary Shultz" <cshultz@xxxxxx> wrote in message
>> news:OZlB2hn$JHA.3612@xxxxxx
Quote:

>>> Good afternoon!
>>>
>>> Please find below the script. It is rather long. Sorry.
>>>
>>> This script is doing something funny...when I run it in environments
>>> where there is but one server I have no issues. However, when I run in
>>> it environments where there are multiple environments I have issues. It
>>> seems that the results of the first computer are carried over into the
>>> results of the succedding computers.
>>>
>>> I am using a text file that contains each server in the envioronment for
>>> the input file (I have verified that the text file is accurate). As a
>>> test (read: troubleshooting) if I modify this script slight so that I
>>> simply manually enter in the computer (strComputer = "EXCH01") - thus,
>>> removing the use of the input file and the "DO Until ... LOOP" - it runs
>>> fine. However, I really would like to resolve this as some environments
>>> have some 20 servers (we have about six of those....really do not want
>>> to have to do this!).
>>>
>>> However, I have several other scripts of this nature that work fine! I
>>> am missing something here!
>>>
>>> Thanks!
>>>
>>>
>>> '==================================================================================================
>>> '
>>> ' VBScript Source File
>>> '
>>> ' NAME: Query-Specific-Services.VBS
>>> ' VERSION: 1.0
>>> ' COMPANY: XXX
>>> ' AUTHOR: XXX
>>> ' CREATE DATE : 07/06/2009
>>> ' LAST MODIFIED : n/a
>>> '==================================================================================================
>>> ' COMMENT: This script will determine if the pre-defined services are
>>> running on the servers
>>> '==================================================================================================
>>>
>>>
>>> Option Explicit
>>>
>>> Dim objWMIService, colServices, objService
>>> Dim objFSO, objTextFile, objTS
>>> Dim strComputer
>>> Dim strInputFile, strOutputFile
>>> Dim colServicesDHCP, colServicesDNS, colServicesWINS, colServicesRRAS,
>>> colServicesIAS, colServicesIndex, colServicesTSLS, colServicesBackup
>>> Dim objServiceDHCP, objServiceDNS, objServiceWINS, objServiceRRAS,
>>> objServiceIAS, objServiceIndex, objServiceTSLS, objServiceBackup
>>> Dim strDHCPService, strDHCPServiceStartMode, strDHCPState
>>> Dim strDNSService, strDNSServiceStartMode, strDNSState
>>> Dim strWINSService, strWINSServiceStartMode, strWINSState
>>> Dim strRRASService, strRRASServiceStartMode, strRRASState
>>> Dim strIASService, strIASServiceStartMode, strIASState
>>> Dim strIndexService, strIndexServiceStartMode, strIndexState
>>> Dim strTSLSService, strTSLSServiceStartMode, strTSLSState
>>> Dim strBackupService, strBackupServiceStartMode, strBackupState
>>>
>>> CONST ForReading = 1
>>> CONST ForWriting = 2
>>>
>>> strInputFile = "C:\Scripts\Servers Info\Servers-TxtFile.txt"
>>> strOutputFile = "C:\Scripts\Results\Services-Running.txt"
>>>
>>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>>> Set objTextFile = objFSO.OpenTextFile(strInputFile,ForReading)
>>> Set objTS = objFSO.CreateTextFile(strOutputFile,ForWriting,False)
>>>
>>> Do Until objTextFile.AtEndOfStream
>>> strcomputer = objTextFile.Readline
>>>
>>> Set objWMIService = GetObject("winmgmts:" _
>>> & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" &
>>> strComputer & "\root\cimv2")
>>>
>>>
>>> If (Err.Number <> 0) Then
>>> objTS.WriteLine string(50,".")
>>> objTS.WriteLine string(50,".")
>>> objTS.WriteLine "ERROR: Unable to connect to the WMI NameSpace on " &
>>> strComputer
>>> objTS.WriteLine string(50,".")
>>> objTS.WriteLine string(50,".")
>>> objTS.WriteLine()
>>> Err.Clear
>>> Else
>>>
>>> Set colServicesDHCP = objWMIService.ExecQuery("SELECT * FROM
>>> Win32_Service WHERE Name = 'DHCPServer'",,48)
>>> Set colServicesDNS = objWMIService.ExecQuery("SELECT * FROM
>>> Win32_Service WHERE Name = 'DNS'",,48)
>>> Set colServicesWINS = objWMIService.ExecQuery("SELECT * FROM
>>> Win32_Service WHERE Name = 'WINS'",,48)
>>> Set colServicesRRAS = objWMIService.ExecQuery("SELECT * FROM
>>> Win32_Service WHERE Name = 'RemoteAccess'",,48)
>>> Set colServicesIAS = objWMIService.ExecQuery("SELECT * FROM
>>> Win32_Service WHERE Name = 'IAS'",,48)
>>> Set colServicesIndex = objWMIService.ExecQuery("SELECT * FROM
>>> Win32_Service WHERE Name = 'CiSvc'",,48)
>>> Set colServicesTSLS = objWMIService.ExecQuery("SELECT * FROM
>>> Win32_Service WHERE Name = 'TermServLicensing'",,48)
>>> Set colServicesBackUp = objWMIService.ExecQuery("SELECT * FROM
>>> Win32_Service WHERE Name = 'BackupExecJobEngine'",,48)
>>>
>>>
>>> For Each objServiceDHCP in colServicesDHCP
>>> strDHCPService = objServiceDHCP.DisplayName
>>> strDHCPServiceStartMode = objServiceDHCP.StartMode
>>> strDHCPState = objServiceDHCP.State
>>> NEXT
>>>
>>> For Each objServiceDNS in colServicesDNS
>>> strDNSService = objServiceDNS.DisplayName
>>> strDNSServiceStartMode = objServiceDNS.StartMode
>>> strDNSState = objServiceDNS.State
>>> NEXT
>>>
>>> For Each objServiceWINS in colServicesWINS
>>> strWINSService = objServiceWINS.DisplayName
>>> strWINSServiceStartMode = objServiceWINS.StartMode
>>> strWINSState = objServiceWINS.State
>>> NEXT
>>>
>>> For Each objServiceRRAS in colServicesRRAS
>>> strRRASService = objServiceRRAS.DisplayName
>>> strRRASServiceStartMode = objServiceRRAS.StartMode
>>> strRRASState = objServiceRRAS.State
>>> NEXT
>>>
>>> For Each objServiceIAS in colServicesIAS
>>> strIASService = objServiceIAS.DisplayName
>>> strIASServiceStartMode = objServiceIAS.StartMode
>>> strIASState = objServiceIAS.State
>>> NEXT
>>>
>>> For Each objServiceIndex in colServicesIndex
>>> strIndexService = objServiceIndex.DisplayName
>>> strIndexServiceStartMode = objServiceIndex.StartMode
>>> strIndexState = objServiceIndex.State
>>> NEXT
>>>
>>>
>>> For Each objServiceTSLS in colServicesTSLS
>>> strTSLSService = objServiceTSLS.DisplayName
>>> strTSLSServiceStartMode = objServiceTSLS.StartMode
>>> strTSLSState = objServiceTSLS.State
>>> NEXT
>>>
>>> For Each objServiceBackup in colServicesBackup
>>> strBackupService = objServiceBackup.DisplayName
>>> strBackupServiceStartMode = objServiceBackup.StartMode
>>> strBackupState = objServiceBackup.State
>>> NEXT
>>>
>>>
>>> objTS.WriteLine string(50,"=")
>>> objTS.WriteLine string(50,"=")
>>> objTS.WriteLine "Computer Name: " & strComputer
>>> objTS.WriteLine string(50,"=")
>>> objTS.WriteLine string(50,"=")
>>> objTS.WriteLine "DHCP Service: " & strDHCPService
>>> objTS.WriteLine "DHCP Start UP: " & strDHCPServiceStartMode
>>> objTS.WriteLine "DHCP Running: " & strDHCPState
>>> objTS.WriteLine string(50,".")
>>> objTS.WriteLine "DNS Service: " & strDNSService
>>> objTS.WriteLine "DNS Start Up: " & strDNSServiceStartMode
>>> objTS.WriteLine "DNS Running: " & strDNSState
>>> objTS.WriteLine string(50,".")
>>> objTS.WriteLine "WINS Service: " & strWINSService
>>> objTS.WriteLine "WINS Start Up: " & strWINSServiceStartMode
>>> objTS.WriteLine "WINS Running: " & strWINSState
>>> objTS.WriteLine string(50,".")
>>> objTS.WriteLine "RRAS Service: " & strRRASService
>>> objTS.WriteLine "RRAS Start Up: " & strRRASServiceStartMode
>>> objTS.WriteLine "RRAS Running: " & strRRASState
>>> objTS.WriteLine string(50,".")
>>> objTS.WriteLine "IAS Service: " & strIASService
>>> objTS.WriteLine "IAS Start Up: " & strIASServiceStartMode
>>> objTS.WriteLine "IAS Running: " & strIASState
>>> objTS.WriteLine string(50,".")
>>> objTS.WriteLine "Index Service: " & strIndexService
>>> objTS.WriteLine "Index Start Up: " & strIndexServiceStartMode
>>> objTS.WriteLine "Index Running: " & strIndexState
>>> objTS.WriteLine string(50,".")
>>> objTS.WriteLine "TSLS Server: " & strTSLSService
>>> objTS.WriteLine "TSLS Start Up: " & strTSLSServiceStartMode
>>> objTS.WriteLine "TSLS Running: " & strTSLSState
>>> objTS.WriteLine string(50,".")
>>> objTS.WriteLine "Backup Server: " & strBackupService
>>> objTS.WriteLine "Backup Start Up: " & strBackupServiceStartMode
>>> objTS.WriteLine "Backup Running: " & strBackupState
>>> objTS.WriteLine()
>>> objTS.WriteLine()
>>>
>>> End If
>>>
>>> Loop
>>>
>>>
>>> objTextFile.Close
>>> objTS.Close
>>>
>>> Set objTextFile = Nothing
>>> Set objTS = Nothing
>>> Set objFSO = Nothing
>>
>> Let's assume that WINS is installed on Server1. You therefore execute
>> this loop:
>> For Each objServiceWINS in colServicesWINS
>> strWINSService = objServiceWINS.DisplayName
>> strWINSServiceStartMode = objServiceWINS.StartMode
>> strWINSState = objServiceWINS.State
>> NEXT
>>
>> Let's assume that WINS is not installed on Server2. You will now skip the
>> above loop - but the values you assigned to your three strings will
>> persist because you never cleared them.
>
>
> Also, you check for errors, but do not disable normal error handling. I
> would suggest (in part):
> ========
> Do Until objTextFile.AtEndOfStream
> strcomputer = objTextFile.Readline
>
> On Error Resume Next
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" &
> strComputer & "\root\cimv2")
>
> If (Err.Number <> 0) Then
> On Error GoTo 0
> objTS.WriteLine string(50,".")
> objTS.WriteLine string(50,".")
> objTS.WriteLine "ERROR: Unable to connect to the WMI NameSpace on " &
> strComputer
> objTS.WriteLine string(50,".")
> objTS.WriteLine string(50,".")
> objTS.WriteLine()
> Else
> On Error GoTo 0
> ========
> Otherwise the script will halt if an error is raised when it attempts to
> connect to the remote computer.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
Richard, as always, I appreciate your input. And, shame on me. This is the
second (at least) time that you have made this suggestion regarding the "On
Error GoTo 0" entry...I guess that I do not understand what that does. I am
thinking that this must be some sort of "trick".....I remeber the GOTO line
from back in the WINNT days (log on scripts....) but there was always a
"real" place where the GOTO pointed. Not sure what the GoTO 0 means....

Thanks,

Cary

PS. I really appreciate all of your help. I am a bit thickheaded with some
of this stuff so I am going to ask frustatingly obvious questions (and,
blissfully ingnorantly so, I might add). I will get this and will then
start answering questions.

My System SpecsSystem Spec
Old 07-06-2009   #7 (permalink)
Cary Shultz


 
 

Re: Can anyone offer assitance with this script?


"Pegasus [MVP]" <news@xxxxxx> wrote in message
news:OBkP5ao$JHA.3732@xxxxxx
Quote:

>
> "Cary Shultz" <cshultz@xxxxxx> wrote in message
> news:OZlB2hn$JHA.3612@xxxxxx
Quote:

>> Good afternoon!
>>
>> Please find below the script. It is rather long. Sorry.
>>
>> This script is doing something funny...when I run it in environments
>> where there is but one server I have no issues. However, when I run in
>> it environments where there are multiple environments I have issues. It
>> seems that the results of the first computer are carried over into the
>> results of the succedding computers.
>>
>> I am using a text file that contains each server in the envioronment for
>> the input file (I have verified that the text file is accurate). As a
>> test (read: troubleshooting) if I modify this script slight so that I
>> simply manually enter in the computer (strComputer = "EXCH01") - thus,
>> removing the use of the input file and the "DO Until ... LOOP" - it runs
>> fine. However, I really would like to resolve this as some environments
>> have some 20 servers (we have about six of those....really do not want to
>> have to do this!).
>>
>> However, I have several other scripts of this nature that work fine! I
>> am missing something here!
>>
>> Thanks!
>
> A couple of additonal thoughts:
> - Since your repeatedly executing the code that examines a service, you
> could create a subroutine that performs the job. The lines 35..38 in the
> code below do this - add further lines to your liking. As a fringe benefit
> this method eliminates the need to reset your various strings. You need to
> restore your text formatting, of course.
> - To deal with machines that are inaccessible, you *must* insert an "on
> error resume next" statement as shown in line 20 below.
>
> [01] Option Explicit
> [02]
> [03] Dim objFSO, objTextFile, objTS
> [04] Dim strComputer
> [05] Dim strInputFile, strOutputFile
> [06]
> [07] Const ForReading = 1
> [08] Const ForWriting = 2
> [09]
> [10] strInputFile = "d:\Servers.txt"
> [11] strOutputFile = "d:\Output.txt"
> [12]
> [13] Set objFSO = CreateObject("Scripting.FileSystemObject")
> [14] Set objTextFile = objFSO.OpenTextFile(strInputFile,ForReading)
> [15] Set objTS = objFSO.CreateTextFile(strOutputFile,ForWriting,False)
> [16]
> [17] Do Until objTextFile.AtEndOfStream
> [18] strComputer = objTextFile.Readline
> [19]
> [20] On Error Resume Next
> [21] Set objWMIService = GetObject("winmgmts:" _
> [22] & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
> [23] & strComputer & "\root\cimv2")
> [24]
> [25] If (Err.Number <> 0) Then
> [26] objTS.WriteLine String(50,".")
> [27] objTS.WriteLine String(50,".")
> [28] objTS.WriteLine "ERROR: Unable to connect to the WMI NameSpace on "
> _
> [29] & strComputer
> [30] objTS.WriteLine String(50,".")
> [31] objTS.WriteLine String(50,".")
> [32] objTS.WriteLine()
> [33] Err.Clear
> [34] Else
> [35] objTS.WriteLine strComputer
> [36] GetServiceDetails "Windows VNC: ", "'WinVNC'"
> [37] GetServiceDetails "DHCP Server: ", "'DHCP'"
> [38] GetServiceDetails "RRAS Service: ", "'RRAS'"
> [39] End If
> [40] On Error Goto 0
> [41] Loop
> [42] objTextFile.Close
> [43] objTS.Close
> [44] Set objTextFile = Nothing
> [45] Set objTS = Nothing
> [46] Set objFSO = Nothing
> [47] '------------------------------------
> [48] Sub GetServiceDetails (Description, ServiceName)
> [49] Dim objWMIService, colServices, objService
> [50] Set colServices = objWMIService.ExecQuery("SELECT * FROM
> Win32_Service " _
> [51] & "WHERE Name = " & ServiceName, , 48)
> [52] For Each objService In colServices
> [53] objTS.WriteLine Description & objService.DisplayName
> [54] objTS.WriteLine "Start Up: " & objService.StartMode
> [55] objTS.WriteLine "Running: " & objService.State
> [56] objTS.writeline
> [57] Next
> [58] Set colServices = Nothing
> [59] End Sub
>
>
Pegasus,

Thanks for your help on this. I will play with this. Thanks again.

Besides your site, can you offer any books for me to buy so that I can get a
"formal education" on this. There are actually quite a lot of really basic
things that I can do (super simple stuff) and I am not getting to the point
where I am trying to do things where I am falling flat on my face because of
a concept here or there that I simply do not know.

I am more into AD (used to be an MVP for AD....never made it to Redmond
because my wife was pregnant the first year and then we had the little one
the second year) but am really becoming interested in WMI and am becoming a
bit frustrated because I want to do more (and am being asked to do more) but
simply do not have the basics down.

Thanks again for your help...

My System SpecsSystem Spec
Old 07-07-2009   #8 (permalink)
Mark D. MacLachlan


 
 

Re: Can anyone offer assitance with this script?

Cary Shultz wrote:
Quote:

>
> "Pegasus [MVP]" <news@xxxxxx> wrote in message
> news:uWOXLGo$JHA.5780@xxxxxx
Quote:

> >
> >"Cary Shultz" <cshultz@xxxxxx> wrote in message
> news:OZlB2hn$JHA.3612@xxxxxx
Quote:
Quote:

> > > Good afternoon!
> > >
> > > Please find below the script. It is rather long. Sorry.
> > >
> > > This script is doing something funny...when I run it in
> > > environments where there is but one server I have no issues.
> > > However, when I run in it environments where there are multiple
> > > environments I have issues. It seems that the results of the
> > > first computer are carried over into the results of the
> > > succedding computers.
> > >
> > > I am using a text file that contains each server in the
> > > envioronment for the input file (I have verified that the text
> > > file is accurate). As a test (read: troubleshooting) if I
> > > modify this script slight so that I simply manually enter in the
> > > computer (strComputer = "EXCH01") - thus, removing the use of
> > > the input file and the "DO Until ... LOOP" - it runs fine.
> > > However, I really would like to resolve this as some environments
> > > have some 20 servers (we have about six of those....really do not
> > > want to have to do this!).
> > >
> > > However, I have several other scripts of this nature that work
> > > fine! I am missing something here!
> > >
> > > Thanks!
> > >
> > >
> > > '=================================================================
> > > ================================= '
> > > ' VBScript Source File
> > > '
> > > ' NAME: Query-Specific-Services.VBS
> > > ' VERSION: 1.0
> > > ' COMPANY: XXX
> > > ' AUTHOR: XXX
> > > ' CREATE DATE : 07/06/2009
> > > ' LAST MODIFIED : n/a
> > > '=================================================================
> > > ================================= ' COMMENT: This script will
> > > determine if the pre-defined services are running on the servers
> > > '=================================================================
> > > =================================
> > >
> > >
> > > Option Explicit
> > >
> > > Dim objWMIService, colServices, objService
> > > Dim objFSO, objTextFile, objTS
> > > Dim strComputer
> > > Dim strInputFile, strOutputFile
> > > Dim colServicesDHCP, colServicesDNS, colServicesWINS,
> > > colServicesRRAS, colServicesIAS, colServicesIndex,
> > > colServicesTSLS, colServicesBackup Dim objServiceDHCP,
> > > objServiceDNS, objServiceWINS, objServiceRRAS, objServiceIAS,
> > > objServiceIndex, objServiceTSLS, objServiceBackup Dim
> > > strDHCPService, strDHCPServiceStartMode, strDHCPState Dim
> > > strDNSService, strDNSServiceStartMode, strDNSState Dim
> > > strWINSService, strWINSServiceStartMode, strWINSState Dim
> > > strRRASService, strRRASServiceStartMode, strRRASState Dim
> > > strIASService, strIASServiceStartMode, strIASState Dim
> > > strIndexService, strIndexServiceStartMode, strIndexState Dim
> > > strTSLSService, strTSLSServiceStartMode, strTSLSState Dim
> > > strBackupService, strBackupServiceStartMode, strBackupState
> > >
> > > CONST ForReading = 1
> > > CONST ForWriting = 2
> > >
> > > strInputFile = "C:\Scripts\Servers Info\Servers-TxtFile.txt"
> > > strOutputFile = "C:\Scripts\Results\Services-Running.txt"
> > >
> > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > Set objTextFile = objFSO.OpenTextFile(strInputFile,ForReading)
> > > Set objTS = objFSO.CreateTextFile(strOutputFile,ForWriting,False)
> > >
> > > Do Until objTextFile.AtEndOfStream
> > > strcomputer = objTextFile.Readline
> > >
> >> Set objWMIService = GetObject("winmgmts:" _
> >> &
> "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" &
> strComputer & "\root\cimv2")
Quote:
Quote:

> > >
> > >
> >> If (Err.Number <> 0) Then
> >> objTS.WriteLine string(50,".")
> >> objTS.WriteLine string(50,".")
> >> objTS.WriteLine "ERROR: Unable to connect to the WMI NameSpace on
> " & strComputer >> objTS.WriteLine string(50,".")
Quote:
Quote:

> >> objTS.WriteLine string(50,".")
> >> objTS.WriteLine()
> >> Err.Clear
> >> Else
> > >
> >> Set colServicesDHCP = objWMIService.ExecQuery("SELECT * FROM
> Win32_Service WHERE Name = 'DHCPServer'",,48) >> Set colServicesDNS =
> objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name =
> 'DNS'",,48) >> Set colServicesWINS = objWMIService.ExecQuery("SELECT
> * FROM Win32_Service WHERE Name = 'WINS'",,48) >> Set
> colServicesRRAS = objWMIService.ExecQuery("SELECT * FROM
> Win32_Service WHERE Name = 'RemoteAccess'",,48) >> Set colServicesIAS
> = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name =
> 'IAS'",,48) >> Set colServicesIndex = objWMIService.ExecQuery("SELECT
> * FROM Win32_Service WHERE Name = 'CiSvc'",,48) >> Set
> colServicesTSLS = objWMIService.ExecQuery("SELECT * FROM
> Win32_Service WHERE Name = 'TermServLicensing'",,48) >> Set
> colServicesBackUp = objWMIService.ExecQuery("SELECT * FROM
> Win32_Service WHERE Name = 'BackupExecJobEngine'",,48)
Quote:
Quote:

> > >
> > >
> >> For Each objServiceDHCP in colServicesDHCP
> >> strDHCPService = objServiceDHCP.DisplayName
> >> strDHCPServiceStartMode = objServiceDHCP.StartMode
> >> strDHCPState = objServiceDHCP.State
> >> NEXT
> > >
> >> For Each objServiceDNS in colServicesDNS
> >> strDNSService = objServiceDNS.DisplayName
> >> strDNSServiceStartMode = objServiceDNS.StartMode
> >> strDNSState = objServiceDNS.State
> >> NEXT
> > >
> >> For Each objServiceWINS in colServicesWINS
> >> strWINSService = objServiceWINS.DisplayName
> >> strWINSServiceStartMode = objServiceWINS.StartMode
> >> strWINSState = objServiceWINS.State
> >> NEXT
> > >
> >> For Each objServiceRRAS in colServicesRRAS
> >> strRRASService = objServiceRRAS.DisplayName
> >> strRRASServiceStartMode = objServiceRRAS.StartMode
> >> strRRASState = objServiceRRAS.State
> >> NEXT
> > >
> >> For Each objServiceIAS in colServicesIAS
> >> strIASService = objServiceIAS.DisplayName
> >> strIASServiceStartMode = objServiceIAS.StartMode
> >> strIASState = objServiceIAS.State
> >> NEXT
> > >
> >> For Each objServiceIndex in colServicesIndex
> >> strIndexService = objServiceIndex.DisplayName
> >> strIndexServiceStartMode = objServiceIndex.StartMode
> >> strIndexState = objServiceIndex.State
> >> NEXT
> > >
> > >
> >> For Each objServiceTSLS in colServicesTSLS
> >> strTSLSService = objServiceTSLS.DisplayName
> >> strTSLSServiceStartMode = objServiceTSLS.StartMode
> >> strTSLSState = objServiceTSLS.State
> >> NEXT
> > >
> >> For Each objServiceBackup in colServicesBackup
> >> strBackupService = objServiceBackup.DisplayName
> >> strBackupServiceStartMode = objServiceBackup.StartMode
> >> strBackupState = objServiceBackup.State
> >> NEXT
> > >
> > >
> >> objTS.WriteLine string(50,"=")
> >> objTS.WriteLine string(50,"=")
> >> objTS.WriteLine "Computer Name: " & strComputer
> >> objTS.WriteLine string(50,"=")
> >> objTS.WriteLine string(50,"=")
> >> objTS.WriteLine "DHCP Service: " & strDHCPService
> >> objTS.WriteLine "DHCP Start UP: " & strDHCPServiceStartMode
> >> objTS.WriteLine "DHCP Running: " & strDHCPState
> >> objTS.WriteLine string(50,".")
> >> objTS.WriteLine "DNS Service: " & strDNSService
> >> objTS.WriteLine "DNS Start Up: " & strDNSServiceStartMode
> >> objTS.WriteLine "DNS Running: " & strDNSState
> >> objTS.WriteLine string(50,".")
> >> objTS.WriteLine "WINS Service: " & strWINSService
> >> objTS.WriteLine "WINS Start Up: " & strWINSServiceStartMode
> >> objTS.WriteLine "WINS Running: " & strWINSState
> >> objTS.WriteLine string(50,".")
> >> objTS.WriteLine "RRAS Service: " & strRRASService
> >> objTS.WriteLine "RRAS Start Up: " & strRRASServiceStartMode
> >> objTS.WriteLine "RRAS Running: " & strRRASState
> >> objTS.WriteLine string(50,".")
> >> objTS.WriteLine "IAS Service: " & strIASService
> >> objTS.WriteLine "IAS Start Up: " & strIASServiceStartMode
> >> objTS.WriteLine "IAS Running: " & strIASState
> >> objTS.WriteLine string(50,".")
> >> objTS.WriteLine "Index Service: " & strIndexService
> >> objTS.WriteLine "Index Start Up: " & strIndexServiceStartMode
> >> objTS.WriteLine "Index Running: " & strIndexState
> >> objTS.WriteLine string(50,".")
> >> objTS.WriteLine "TSLS Server: " & strTSLSService
> >> objTS.WriteLine "TSLS Start Up: " & strTSLSServiceStartMode
> >> objTS.WriteLine "TSLS Running: " & strTSLSState
> >> objTS.WriteLine string(50,".")
> >> objTS.WriteLine "Backup Server: " & strBackupService
> >> objTS.WriteLine "Backup Start Up: " & strBackupServiceStartMode
> >> objTS.WriteLine "Backup Running: " & strBackupState
> >> objTS.WriteLine()
> >> objTS.WriteLine()
> > >
> >> End If
> > >
> > > Loop
> > >
> > >
> > > objTextFile.Close
> > > objTS.Close
> > >
> > > Set objTextFile = Nothing
> > > Set objTS = Nothing
> > > Set objFSO = Nothing
> >
> > Let's assume that WINS is installed on Server1. You therefore
> > execute this loop: For Each objServiceWINS in colServicesWINS
> > strWINSService = objServiceWINS.DisplayName
> > strWINSServiceStartMode = objServiceWINS.StartMode
> > strWINSState = objServiceWINS.State
> > NEXT
> >
> > Let's assume that WINS is not installed on Server2. You will now
> > skip the above loop - but the values you assigned to your three
> > strings will persist because you never cleared them.
> >
> Pegasus,
>
> Thanks. I kinda figured that is what was going on.....because, for
> example, if RRAS is installed on Server1 (Started and Automatic) but
> not on Server2 and specifically disabled on Server3 and on Server4 it
> will show as Started and Automatic on Server2 (where it should be -
> in my example - blank) but have the correct "values" on Server3 and
> on Server4.
>
> So, my second question for you is this.....how do I clear them?
>
> This also means that I need to 'fix' the other scripts....
>
> Thanks,
>
> Cary
On Error Resume Next set the script to continue if an error is
encountered. That allows you to check for the error number.

On Error GoTo 0 turns off that feature.


Before your LOOP you want to clear all the collections/objects so they
can't pass on to the next computer. As an example:

Set colServicesDHCP = Nothing
Set objWMIService = Nothing


Hope that helps,

Mark D. MacLachlan
--

My System SpecsSystem Spec
Old 07-07-2009   #9 (permalink)
Pegasus [MVP]


 
 

Re: Can anyone offer assitance with this script?


"Cary Shultz" <cshultz@xxxxxx> wrote in message
news:uf3choo$JHA.4692@xxxxxx
<snip>
Quote:

>
> Pegasus,
>
> Thanks for your help on this. I will play with this. Thanks again.
>
> Besides your site, can you offer any books for me to buy so that I can get
> a "formal education" on this. There are actually quite a lot of really
> basic things that I can do (super simple stuff) and I am not getting to
> the point where I am trying to do things where I am falling flat on my
> face because of a concept here or there that I simply do not know.
>
> I am more into AD (used to be an MVP for AD....never made it to Redmond
> because my wife was pregnant the first year and then we had the little one
> the second year) but am really becoming interested in WMI and am becoming
> a bit frustrated because I want to do more (and am being asked to do more)
> but simply do not have the basics down.
>
> Thanks again for your help...
It seems much of your expertise is in the field where I'm weak, AD . . .
About your "formal education": I suggest you have a look at the thread
"Newbie: where to start?" that ran in this newsgroup just two weeks ago. It
will probably answer your question.


My System SpecsSystem Spec
Old 07-07-2009   #10 (permalink)
Cary Shultz


 
 

Re: Can anyone offer assitance with this script?


"Mark D. MacLachlan" <markdmac@xxxxxx> wrote in message
news:%23$Wn$6r$JHA.4168@xxxxxx
Quote:

> Cary Shultz wrote:
>
Quote:

>>
>> "Pegasus [MVP]" <news@xxxxxx> wrote in message
>> news:uWOXLGo$JHA.5780@xxxxxx
Quote:

>> >
>> >"Cary Shultz" <cshultz@xxxxxx> wrote in message
>> news:OZlB2hn$JHA.3612@xxxxxx
Quote:

>> > > Good afternoon!
>> > >
>> > > Please find below the script. It is rather long. Sorry.
>> > >
>> > > This script is doing something funny...when I run it in
>> > > environments where there is but one server I have no issues.
>> > > However, when I run in it environments where there are multiple
>> > > environments I have issues. It seems that the results of the
>> > > first computer are carried over into the results of the
>> > > succedding computers.
>> > >
>> > > I am using a text file that contains each server in the
>> > > envioronment for the input file (I have verified that the text
>> > > file is accurate). As a test (read: troubleshooting) if I
>> > > modify this script slight so that I simply manually enter in the
>> > > computer (strComputer = "EXCH01") - thus, removing the use of
>> > > the input file and the "DO Until ... LOOP" - it runs fine.
>> > > However, I really would like to resolve this as some environments
>> > > have some 20 servers (we have about six of those....really do not
>> > > want to have to do this!).
>> > >
>> > > However, I have several other scripts of this nature that work
>> > > fine! I am missing something here!
>> > >
>> > > Thanks!
>> > >
>> > >
>> > > '=================================================================
>> > > ================================= '
>> > > ' VBScript Source File
>> > > '
>> > > ' NAME: Query-Specific-Services.VBS
>> > > ' VERSION: 1.0
>> > > ' COMPANY: XXX
>> > > ' AUTHOR: XXX
>> > > ' CREATE DATE : 07/06/2009
>> > > ' LAST MODIFIED : n/a
>> > > '=================================================================
>> > > ================================= ' COMMENT: This script will
>> > > determine if the pre-defined services are running on the servers
>> > > '=================================================================
>> > > =================================
>> > >
>> > >
>> > > Option Explicit
>> > >
>> > > Dim objWMIService, colServices, objService
>> > > Dim objFSO, objTextFile, objTS
>> > > Dim strComputer
>> > > Dim strInputFile, strOutputFile
>> > > Dim colServicesDHCP, colServicesDNS, colServicesWINS,
>> > > colServicesRRAS, colServicesIAS, colServicesIndex,
>> > > colServicesTSLS, colServicesBackup Dim objServiceDHCP,
>> > > objServiceDNS, objServiceWINS, objServiceRRAS, objServiceIAS,
>> > > objServiceIndex, objServiceTSLS, objServiceBackup Dim
>> > > strDHCPService, strDHCPServiceStartMode, strDHCPState Dim
>> > > strDNSService, strDNSServiceStartMode, strDNSState Dim
>> > > strWINSService, strWINSServiceStartMode, strWINSState Dim
>> > > strRRASService, strRRASServiceStartMode, strRRASState Dim
>> > > strIASService, strIASServiceStartMode, strIASState Dim
>> > > strIndexService, strIndexServiceStartMode, strIndexState Dim
>> > > strTSLSService, strTSLSServiceStartMode, strTSLSState Dim
>> > > strBackupService, strBackupServiceStartMode, strBackupState
>> > >
>> > > CONST ForReading = 1
>> > > CONST ForWriting = 2
>> > >
>> > > strInputFile = "C:\Scripts\Servers Info\Servers-TxtFile.txt"
>> > > strOutputFile = "C:\Scripts\Results\Services-Running.txt"
>> > >
>> > > Set objFSO = CreateObject("Scripting.FileSystemObject")
>> > > Set objTextFile = objFSO.OpenTextFile(strInputFile,ForReading)
>> > > Set objTS = objFSO.CreateTextFile(strOutputFile,ForWriting,False)
>> > >
>> > > Do Until objTextFile.AtEndOfStream
>> > > strcomputer = objTextFile.Readline
>> > >
>> >> Set objWMIService = GetObject("winmgmts:" _
>> >> &
>> "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" &
>> strComputer & "\root\cimv2")
Quote:

>> > >
>> > >
>> >> If (Err.Number <> 0) Then
>> >> objTS.WriteLine string(50,".")
>> >> objTS.WriteLine string(50,".")
>> >> objTS.WriteLine "ERROR: Unable to connect to the WMI NameSpace on
>> " & strComputer >> objTS.WriteLine string(50,".")
Quote:

>> >> objTS.WriteLine string(50,".")
>> >> objTS.WriteLine()
>> >> Err.Clear
>> >> Else
>> > >
>> >> Set colServicesDHCP = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'DHCPServer'",,48) >> Set colServicesDNS =
>> objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name =
>> 'DNS'",,48) >> Set colServicesWINS = objWMIService.ExecQuery("SELECT
>> * FROM Win32_Service WHERE Name = 'WINS'",,48) >> Set
>> colServicesRRAS = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'RemoteAccess'",,48) >> Set colServicesIAS
>> = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name =
>> 'IAS'",,48) >> Set colServicesIndex = objWMIService.ExecQuery("SELECT
>> * FROM Win32_Service WHERE Name = 'CiSvc'",,48) >> Set
>> colServicesTSLS = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'TermServLicensing'",,48) >> Set
>> colServicesBackUp = objWMIService.ExecQuery("SELECT * FROM
>> Win32_Service WHERE Name = 'BackupExecJobEngine'",,48)
Quote:

>> > >
>> > >
>> >> For Each objServiceDHCP in colServicesDHCP
>> >> strDHCPService = objServiceDHCP.DisplayName
>> >> strDHCPServiceStartMode = objServiceDHCP.StartMode
>> >> strDHCPState = objServiceDHCP.State
>> >> NEXT
>> > >
>> >> For Each objServiceDNS in colServicesDNS
>> >> strDNSService = objServiceDNS.DisplayName
>> >> strDNSServiceStartMode = objServiceDNS.StartMode
>> >> strDNSState = objServiceDNS.State
>> >> NEXT
>> > >
>> >> For Each objServiceWINS in colServicesWINS
>> >> strWINSService = objServiceWINS.DisplayName
>> >> strWINSServiceStartMode = objServiceWINS.StartMode
>> >> strWINSState = objServiceWINS.State
>> >> NEXT
>> > >
>> >> For Each objServiceRRAS in colServicesRRAS
>> >> strRRASService = objServiceRRAS.DisplayName
>> >> strRRASServiceStartMode = objServiceRRAS.StartMode
>> >> strRRASState = objServiceRRAS.State
>> >> NEXT
>> > >
>> >> For Each objServiceIAS in colServicesIAS
>> >> strIASService = objServiceIAS.DisplayName
>> >> strIASServiceStartMode = objServiceIAS.StartMode
>> >> strIASState = objServiceIAS.State
>> >> NEXT
>> > >
>> >> For Each objServiceIndex in colServicesIndex
>> >> strIndexService = objServiceIndex.DisplayName
>> >> strIndexServiceStartMode = objServiceIndex.StartMode
>> >> strIndexState = objServiceIndex.State
>> >> NEXT
>> > >
>> > >
>> >> For Each objServiceTSLS in colServicesTSLS
>> >> strTSLSService = objServiceTSLS.DisplayName
>> >> strTSLSServiceStartMode = objServiceTSLS.StartMode
>> >> strTSLSState = objServiceTSLS.State
>> >> NEXT
>> > >
>> >> For Each objServiceBackup in colServicesBackup
>> >> strBackupService = objServiceBackup.DisplayName
>> >> strBackupServiceStartMode = objServiceBackup.StartMode
>> >> strBackupState = objServiceBackup.State
>> >> NEXT
>> > >
>> > >
>> >> objTS.WriteLine string(50,"=")
>> >> objTS.WriteLine string(50,"=")
>> >> objTS.WriteLine "Computer Name: " & strComputer
>> >> objTS.WriteLine string(50,"=")
>> >> objTS.WriteLine string(50,"=")
>> >> objTS.WriteLine "DHCP Service: " & strDHCPService
>> >> objTS.WriteLine "DHCP Start UP: " & strDHCPServiceStartMode
>> >> objTS.WriteLine "DHCP Running: " & strDHCPState
>> >> objTS.WriteLine string(50,".")
>> >> objTS.WriteLine "DNS Service: " & strDNSService
>> >> objTS.WriteLine "DNS Start Up: " & strDNSServiceStartMode
>> >> objTS.WriteLine "DNS Running: " & strDNSState
>> >> objTS.WriteLine string(50,".")
>> >> objTS.WriteLine "WINS Service: " & strWINSService
>> >> objTS.WriteLine "WINS Start Up: " & strWINSServiceStartMode
>> >> objTS.WriteLine "WINS Running: " & strWINSState
>> >> objTS.WriteLine string(50,".")
>> >> objTS.WriteLine "RRAS Service: " & strRRASService
>> >> objTS.WriteLine "RRAS Start Up: " & strRRASServiceStartMode
>> >> objTS.WriteLine "RRAS Running: " & strRRASState
>> >> objTS.WriteLine string(50,".")
>> >> objTS.WriteLine "IAS Service: " & strIASService
>> >> objTS.WriteLine "IAS Start Up: " & strIASServiceStartMode
>> >> objTS.WriteLine "IAS Running: " & strIASState
>> >> objTS.WriteLine string(50,".")
>> >> objTS.WriteLine "Index Service: " & strIndexService
>> >> objTS.WriteLine "Index Start Up: " & strIndexServiceStartMode
>> >> objTS.WriteLine "Index Running: " & strIndexState
>> >> objTS.WriteLine string(50,".")
>> >> objTS.WriteLine "TSLS Server: " & strTSLSService
>> >> objTS.WriteLine "TSLS Start Up: " & strTSLSServiceStartMode
>> >> objTS.WriteLine "TSLS Running: " & strTSLSState
>> >> objTS.WriteLine string(50,".")
>> >> objTS.WriteLine "Backup Server: " & strBackupService
>> >> objTS.WriteLine "Backup Start Up: " & strBackupServiceStartMode
>> >> objTS.WriteLine "Backup Running: " & strBackupState
>> >> objTS.WriteLine()
>> >> objTS.WriteLine()
>> > >
>> >> End If
>> > >
>> > > Loop
>> > >
>> > >
>> > > objTextFile.Close
>> > > objTS.Close
>> > >
>> > > Set objTextFile = Nothing
>> > > Set objTS = Nothing
>> > > Set objFSO = Nothing
>> >
>> > Let's assume that WINS is installed on Server1. You therefore
>> > execute this loop: For Each objServiceWINS in colServicesWINS
>> > strWINSService = objServiceWINS.DisplayName
>> > strWINSServiceStartMode = objServiceWINS.StartMode
>> > strWINSState = objServiceWINS.State
>> > NEXT
>> >
>> > Let's assume that WINS is not installed on Server2. You will now
>> > skip the above loop - but the values you assigned to your three
>> > strings will persist because you never cleared them.
>> >
>> Pegasus,
>>
>> Thanks. I kinda figured that is what was going on.....because, for
>> example, if RRAS is installed on Server1 (Started and Automatic) but
>> not on Server2 and specifically disabled on Server3 and on Server4 it
>> will show as Started and Automatic on Server2 (where it should be -
>> in my example - blank) but have the correct "values" on Server3 and
>> on Server4.
>>
>> So, my second question for you is this.....how do I clear them?
>>
>> This also means that I need to 'fix' the other scripts....
>>
>> Thanks,
>>
>> Cary
>
> On Error Resume Next set the script to continue if an error is
> encountered. That allows you to check for the error number.
>
> On Error GoTo 0 turns off that feature.
>
>
> Before your LOOP you want to clear all the collections/objects so they
> can't pass on to the next computer. As an example:
>
> Set colServicesDHCP = Nothing
> Set objWMIService = Nothing
>
>
> Hope that helps,
>
> Mark D. MacLachlan
> --
>
Ach, Du Lieber......I knew that! Just getting to close...spent a lot of
time on that and was not seeing the forest for the trees. Thanks for the
"DOH!" explanation.....

Cary

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Home Folder Creation and Permission Assitance PowerShell
problem passing args to script 'There is no script engine for file extenstion' VB Script
Assitance to change one setting needed Vista mail
Remote Assitance woes from Vista Vista security
Remote Assitance Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46