Jump to content

Services Windows 2003


Recommended Posts

Posted

Is there a command line in Windows 2003 resource kit to run a report on all

the services on your domain and the log on as account it is running under or

software that can do this?

 

Thanks in Advanced.

  • Replies 2
  • Created
  • Last Reply

Popular Days

Guest Mathieu CHATEAU
Posted

Re: Services Windows 2003

 

Hello,

 

there is no builtin command to automatically do that against many computers.

But thanks to vbscript, dreams become reality !

 

You may use this script:

 

Option Explicit

 

Const ForReading = 1

 

Dim objFS, objFileIn, iCount, iError, iComment, iAdminCount, iTot

Dim strRemoteComputer

 

Sub e (str)

WScript.Echo str

End Sub

 

Function ErrorReport (str)

If Err.Number Then

iError = iError + 1

ErrorReport = True

e "Error 0x" & CStr (Hex (Err.Number)) & " occurred " & str

If Err.Description <> "" Then

e "Error description: " & Err.Description & "."

End If

Err.Clear

Else

ErrorReport = False

End If

End Function

 

Sub Startup

If Wscript.Arguments.Count <> 1 Then

e "Usage: Check-Services.vbs listofcomputers.txt"

e " "

e "'listofcomputers.txt' contains a list of the computers"

e "that will be checked for services that do not contain"

e "default accounts."

e " "

wscript.quit 1

End If

 

On Error Resume Next

 

Set objFS = CreateObject ("Scripting.FileSystemObject")

If ErrorReport ("while creating Scripting.FileSystemObject") Then

wscript.quit 1

End If

 

Set objFileIn = objFS.OpenTextFile (wscript.arguments (0), ForReading)

If ErrorReport ("while opening " & wscript.arguments (0)) Then

Set objFS = Nothing

wscript.quit 1

End If

 

iTot = 0

iCount = 0

iError = 0

iComment = 0

iAdminCount = 0

End Sub

 

Sub Shutdown

objFileIn.Close

Set objFileIn = Nothing

 

Set objFS = Nothing

End Sub

 

' Constants we need for WBEM calls

Const wbemFlagReturnImmediately = &H10

Const wbemFlagForwardOnly = &H20

 

Dim arrExclude

 

arrExclude = Array ("NT AUTHORITY\LocalService", _

"LocalSystem", _

".\ASPNET", _

"NT AUTHORITY\NETWORK SERVICE", _

"NT AUTHORITY\NetworkService")

 

Function CheckExclusions (ByVal strVal)

Dim i

 

For i = LBound (arrExclude) To UBound (arrExclude)

If LCase (strVal) = LCase (arrExclude (i)) Then

CheckExclusions = True

Exit Function

End If

Next

 

CheckExclusions = False

End Function

 

Sub CheckServicesOnComputer (ByVal strComputer)

Dim objWMIService

Dim colItems, objItem

Dim iExcluded, iIncluded

 

iExcluded = 0

iIncluded = 0

 

WScript.Echo ""

WScript.Echo "Checking computer " & strComputer

 

On Error Resume Next

Set objWMIService = GetObject ("winmgmts:\\" & strComputer & "\root\CIMV2")

If ErrorReport ("opening CIMv2") Then Exit Sub

Set colItems = objWMIService.ExecQuery ("SELECT name,startname,caption FROM

Win32_Service", "WQL", _

wbemFlagReturnImmediately + wbemFlagForwardOnly)

If ErrorReport ("on ExecQuery") Then Exit Sub

On Error Goto 0

 

' if we get any items returned, it's installed

For Each objItem In colItems

If CheckExclusions (objItem.StartName) Then

iExcluded = iExcluded + 1

Else

iIncluded = iIncluded + 1

If Right (LCase (objItem.StartName), Len ("\Administrator")) =

"\administrator" Then iAdminCount = iAdminCount + 1

'wscript.echo "name = " & objItem.Name & " startname = " &

objItem.StartName & " caption = " & objItem.Caption

e " startname = " & objItem.StartName & " caption = " & objItem.Caption

End If

Next

 

Set colItems = Nothing

Set objWMIService = Nothing

 

Wscript.echo "Included items = " & iIncluded & " excluded items = " &

iExcluded & " for computer " & strComputer

iTot = iTot + iIncluded

End Sub

 

' Main

 

Call Startup

Do Until objFileIn.AtEndOfStream

strRemoteComputer = objFileIn.ReadLine

If ErrorReport ("while reading input line") Then

Exit Do

End If

 

' If the first character is a "#", then the line is a comment

If Left (strRemoteComputer, 1) <> "#" Then

Call CheckServicesOnComputer (strRemoteComputer)

iCount = iCount + 1

Else

iComment = iComment + 1

End If

Loop

 

Call Shutdown

 

e " "

e "Processing complete"

e "Total computers processed: " & iCount

e "Total Administrator services: " & iAdminCount

e "Total special services: " & iTot

e "Total errors: " & iError

e "Total comment lines: " & iComment

 

 

 

--

Cordialement,

Mathieu CHATEAU

English blog: http://lordoftheping.blogspot.com

French blog: http://www.lotp.fr

 

 

"Dumas" <Dumas@discussions.microsoft.com> wrote in message

news:C6FE4F70-24C5-44A2-93F3-2D49F420FED6@microsoft.com...

> Is there a command line in Windows 2003 resource kit to run a report on

> all

> the services on your domain and the log on as account it is running under

> or

> software that can do this?

>

> Thanks in Advanced.

Guest Ryan Hanisco
Posted

Re: Services Windows 2003

 

You can also use the service account tool in ADMT v2 to generate a report

across many servers. I have used this as a shortcut.

 

<G>

--

Ryan Hanisco

MCSE, MCTS: SQL 2005, Project+

http://www.techsterity.com

Chicago, IL

 

Remember: Marking helpful answers helps everyone find the info they need

quickly.

 

 

"Mathieu CHATEAU" wrote:

> Hello,

>

> there is no builtin command to automatically do that against many computers.

> But thanks to vbscript, dreams become reality !

>

> You may use this script:

>

> Option Explicit

>

> Const ForReading = 1

>

> Dim objFS, objFileIn, iCount, iError, iComment, iAdminCount, iTot

> Dim strRemoteComputer

>

> Sub e (str)

> WScript.Echo str

> End Sub

>

> Function ErrorReport (str)

> If Err.Number Then

> iError = iError + 1

> ErrorReport = True

> e "Error 0x" & CStr (Hex (Err.Number)) & " occurred " & str

> If Err.Description <> "" Then

> e "Error description: " & Err.Description & "."

> End If

> Err.Clear

> Else

> ErrorReport = False

> End If

> End Function

>

> Sub Startup

> If Wscript.Arguments.Count <> 1 Then

> e "Usage: Check-Services.vbs listofcomputers.txt"

> e " "

> e "'listofcomputers.txt' contains a list of the computers"

> e "that will be checked for services that do not contain"

> e "default accounts."

> e " "

> wscript.quit 1

> End If

>

> On Error Resume Next

>

> Set objFS = CreateObject ("Scripting.FileSystemObject")

> If ErrorReport ("while creating Scripting.FileSystemObject") Then

> wscript.quit 1

> End If

>

> Set objFileIn = objFS.OpenTextFile (wscript.arguments (0), ForReading)

> If ErrorReport ("while opening " & wscript.arguments (0)) Then

> Set objFS = Nothing

> wscript.quit 1

> End If

>

> iTot = 0

> iCount = 0

> iError = 0

> iComment = 0

> iAdminCount = 0

> End Sub

>

> Sub Shutdown

> objFileIn.Close

> Set objFileIn = Nothing

>

> Set objFS = Nothing

> End Sub

>

> ' Constants we need for WBEM calls

> Const wbemFlagReturnImmediately = &H10

> Const wbemFlagForwardOnly = &H20

>

> Dim arrExclude

>

> arrExclude = Array ("NT AUTHORITY\LocalService", _

> "LocalSystem", _

> ".\ASPNET", _

> "NT AUTHORITY\NETWORK SERVICE", _

> "NT AUTHORITY\NetworkService")

>

> Function CheckExclusions (ByVal strVal)

> Dim i

>

> For i = LBound (arrExclude) To UBound (arrExclude)

> If LCase (strVal) = LCase (arrExclude (i)) Then

> CheckExclusions = True

> Exit Function

> End If

> Next

>

> CheckExclusions = False

> End Function

>

> Sub CheckServicesOnComputer (ByVal strComputer)

> Dim objWMIService

> Dim colItems, objItem

> Dim iExcluded, iIncluded

>

> iExcluded = 0

> iIncluded = 0

>

> WScript.Echo ""

> WScript.Echo "Checking computer " & strComputer

>

> On Error Resume Next

> Set objWMIService = GetObject ("winmgmts:\\" & strComputer & "\root\CIMV2")

> If ErrorReport ("opening CIMv2") Then Exit Sub

> Set colItems = objWMIService.ExecQuery ("SELECT name,startname,caption FROM

> Win32_Service", "WQL", _

> wbemFlagReturnImmediately + wbemFlagForwardOnly)

> If ErrorReport ("on ExecQuery") Then Exit Sub

> On Error Goto 0

>

> ' if we get any items returned, it's installed

> For Each objItem In colItems

> If CheckExclusions (objItem.StartName) Then

> iExcluded = iExcluded + 1

> Else

> iIncluded = iIncluded + 1

> If Right (LCase (objItem.StartName), Len ("\Administrator")) =

> "\administrator" Then iAdminCount = iAdminCount + 1

> 'wscript.echo "name = " & objItem.Name & " startname = " &

> objItem.StartName & " caption = " & objItem.Caption

> e " startname = " & objItem.StartName & " caption = " & objItem.Caption

> End If

> Next

>

> Set colItems = Nothing

> Set objWMIService = Nothing

>

> Wscript.echo "Included items = " & iIncluded & " excluded items = " &

> iExcluded & " for computer " & strComputer

> iTot = iTot + iIncluded

> End Sub

>

> ' Main

>

> Call Startup

> Do Until objFileIn.AtEndOfStream

> strRemoteComputer = objFileIn.ReadLine

> If ErrorReport ("while reading input line") Then

> Exit Do

> End If

>

> ' If the first character is a "#", then the line is a comment

> If Left (strRemoteComputer, 1) <> "#" Then

> Call CheckServicesOnComputer (strRemoteComputer)

> iCount = iCount + 1

> Else

> iComment = iComment + 1

> End If

> Loop

>

> Call Shutdown

>

> e " "

> e "Processing complete"

> e "Total computers processed: " & iCount

> e "Total Administrator services: " & iAdminCount

> e "Total special services: " & iTot

> e "Total errors: " & iError

> e "Total comment lines: " & iComment

>

>

>

> --

> Cordialement,

> Mathieu CHATEAU

> English blog: http://lordoftheping.blogspot.com

> French blog: http://www.lotp.fr

>

>

> "Dumas" <Dumas@discussions.microsoft.com> wrote in message

> news:C6FE4F70-24C5-44A2-93F3-2D49F420FED6@microsoft.com...

> > Is there a command line in Windows 2003 resource kit to run a report on

> > all

> > the services on your domain and the log on as account it is running under

> > or

> > software that can do this?

> >

> > Thanks in Advanced.

>

>


×
×
  • Create New...