Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

Any logon script that can record the services that are specified

Hi,

I want to find all machines that has Logmein service installed in any machines in the domain.Is there a logon script that finds if the software or services are running and record.

Regards
Sharath
0
bsharath
Asked:
bsharath
  • 4
  • 3
1 Solution
 
ChizlCommented:
From VBS Script or really any scripting language that I can think of, there is no way for it, without use of a com object, to query services.    However, you create a COM object and in your language of choice create a COM object.   Then within the script, register the COM object, search, then unregister.

I have a C++ Class that does this already, that I can drop into a C++ COM DLL which can be used within VBS.

Another solution:
If you know where the file is on the computer, you can look to see if it exists within VBS with only the use of FileSystemObject which already exists on most all Win32 machines unless it was removed.
0
 
RobSampsonCommented:
See if this works for you:

'============
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

strComputer = "."
strService = "Print Spooler"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Service " & _
       "WHERE DisplayName = '" & strService & "' OR Name = '" & strService & "'", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

On Error Resume Next
boolFound = False
For Each objItem In colItems
      If Err.Number = 0 Then
            boolFound = True
            WScript.Echo "DisplayName: " & objItem.DisplayName & VbCrLf & _
                  "Name: " & objItem.Name & VbCrLf & _
                  "Status: " & objItem.Status
      End If
Next

If boolFound = False Then WScript.Echo "There is no service called " & strService & " on this computer."
'============

Regards,

Rob.
0
 
bsharathAuthor Commented:
I get this...

---------------------------
Windows Script Host
---------------------------
DisplayName: Print Spooler

Name: Spooler

Status: OK
---------------------------
OK  
---------------------------
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
bsharathAuthor Commented:
I even checked with logmein service and works fine.
Need to remove the popup and need to record all machines that has it in a csv file.Only names of machines that has logmein installed in the machine...
Any way to specify more that 1 service in 1 single script.And the results to be machinename and the found service in the results file.
0
 
RobSampsonCommented:
OK, try this:

'=============
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

strInputFile = "computers.txt"
strOutputFile = "Service_Results.csv"

strServices = "Print Spooler;logmein;Fast User Switching Compatibility"
arrServices = Split(strServices, ";")

strDetails = """Computer"",""Installed Service"""

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
While Not objInputFile.AtEndOfStream
      strComputer = objInputFile.ReadLine
      If Ping(strComputer) = True Then
            Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
            
            For Each strService In arrServices
                  Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Service " & _
                         "WHERE DisplayName = '" & strService & "' OR Name = '" & strService & "'", "WQL", _
                                                            wbemFlagReturnImmediately + wbemFlagForwardOnly)
                  
                  On Error Resume Next
                  boolFound = False
                  For Each objItem In colItems
                        If Err.Number = 0 Then
                              boolFound = True
                              'WScript.Echo "DisplayName: " & objItem.DisplayName & VbCrLf & _
                              '      "Name: " & objItem.Name & VbCrLf & _
                              '      "Status: " & objItem.Status
                              strDetails = strDetails & VbCrLf & """" & strComputer & """,""" & objItem.DisplayName & """"
                        End If
                  Next
                  
                  If boolFound = False Then
                        'WScript.Echo "There is no service called " & strService & " on this computer."
                  End If
            Next
      Else
            'WScript.Echo strComputer & " could not be pinged."
      End If
Wend

Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strDetails
objOutputFile.Close
Set objOutputFile = Nothing

MsgBox "Done"

Function Ping(strComputer)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
      If boolCode = 0 Then
            Ping = True
      Else
            Ping = False
      End If
End Function
'=============

Regards,

Rob.
0
 
bsharathAuthor Commented:
Thanks a lot Rob...\What are the changes i need to do if i need to run as logon script...
0
 
RobSampsonCommented:
Try this as a login script, just change
strOutputFile = "\\server\share\" & objNetwork.ComputerName & "_Service_Results.csv"

so that \\server\share\ becomes the file share you want to save the files to.

'=============
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

Set objNetwork = CreateObject("WScript.Network")
strOutputFile = "\\server\share\" & objNetwork.ComputerName & "_Service_Results.csv"

strServices = "Print Spooler;logmein;Fast User Switching Compatibility"
arrServices = Split(strServices, ";")

strDetails = """Computer"",""Installed Service"""

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

For Each strService In arrServices
      Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Service " & _
             "WHERE DisplayName = '" & strService & "' OR Name = '" & strService & "'", "WQL", _
                                                wbemFlagReturnImmediately + wbemFlagForwardOnly)
     
      On Error Resume Next
      boolFound = False
      For Each objItem In colItems
            If Err.Number = 0 Then
                  boolFound = True
                  'WScript.Echo "DisplayName: " & objItem.DisplayName & VbCrLf & _
                  '      "Name: " & objItem.Name & VbCrLf & _
                  '      "Status: " & objItem.Status
                  strDetails = strDetails & VbCrLf & """" & strComputer & """,""" & objItem.DisplayName & """"
            End If
      Next
     
      If boolFound = False Then
            'WScript.Echo "There is no service called " & strService & " on this computer."
      End If
Next

Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strDetails
objOutputFile.Close
Set objOutputFile = Nothing

'MsgBox "Done"
'=============

Regards,

Rob.
0
 
bsharathAuthor Commented:
Thanks a lot Rob....
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now