home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / free_security / languard / languardnss7.exe / lpsc_check_report.vbs19 < prev    next >
Encoding:
Text File  |  2005-07-25  |  6.1 KB  |  174 lines

  1. Function CreateDir(Directory)
  2.     Dim fl As Object
  3.     Set fl = file.connect("127.0.0.1")
  4.     If Not fl is Nothing Then
  5.         If fl.open(Directory, Generic_read,open_existing) Then
  6.         Else
  7.             fl.createfolder(Directory)
  8.         End If 
  9.     End If
  10.     fl.close
  11. End Function
  12.  
  13. Function WriteToLocalFile(filenm,message)
  14.     Dim fl As Object
  15.     Dim filename As String
  16.     filename = filenm
  17.     Set fl = file.connect("127.0.0.1")
  18.     
  19.     If fl is Nothing Then
  20.         
  21.     Else
  22.         
  23.         If fl.open(filename, GENERIC_write, Open_always) = true  Then
  24.             
  25.               If fl.size < 2 Then 
  26.                   
  27.                 fl.write(Chr(34) &"Date" & Chr(34) & "," & Chr(34) &"Computer IP" & Chr(34) & "," & Chr(34) & "Computer Name" & Chr(34))
  28.                 fl.write(","  & Chr(34) & "Configuration Installed" & Chr(34)& ","  & Chr(34) & "Configuration Build No" & Chr(34) & ","  & Chr(34) & "Agent Installed")  
  29.                 fl.write(Chr(34) & ","  & Chr(34) & "Agent Build No" & Chr(34) & ","  & Chr(34) & "Agent Running" & Chr(34)& "," & Chr(34) & "Status")
  30.                 fl.write(Chr(34) & "," & Chr(34) & "Configuration Path")
  31.                 fl.writeline(Chr(34) &  ","  & Chr(34) & "Agent Path"& Chr(34))
  32.               End If
  33.               
  34.               fl.seek 0,2
  35.               
  36.               fl.writeline(message)
  37.         End If
  38.         
  39.         fl.close
  40.     End If
  41.     
  42. End Function
  43.  
  44. Function buildreport(ComputerIP,ComputerName,ServiceStatus, Agent, Full, AgentBuild,MainBuild,ServiceRuns,AgentPath,MainPath)
  45.     Dim report As String
  46.     Dim Status As String
  47.     If servicestatus = 0 Then
  48.         Status = "Agent Not installed, Computer is unprotected"
  49.     End If
  50.     If servicestatus = 1 Then
  51.         Status = "Agent installed and running"
  52.     End If
  53.     If servicestatus = 2 Then
  54.         Status = "Agent installed but is currently Stopped, Agent might have been tempered with"
  55.     End If
  56.     If servicestatus = 3 Then
  57.         Status = "Agent installed but is DISABLED, Agent has most likely been tempered"
  58.     End If
  59.     If servicestatus = 4 Then
  60.         Status = "Agent installed but is set to Manual start, Agent has most likely been tempered"
  61.     End If
  62.     report = Chr(34) & Now & Chr(34) & "," & Chr(34) & ComputerIP  & Chr(34) & "," & Chr(34) &  ComputerName & Chr(34)
  63.     report = report &  "," & Chr(34) & full & Chr(34) & "," & Chr(34) & MainBuild & Chr(34) & ","
  64.     report = report & Chr(34) & Agent & Chr(34) & "," & Chr(34) & AgentBuild & Chr(34) & "," & Chr(34) & ServiceRuns & Chr(34) & ","
  65.     report = report & Chr(34) & Status & Chr(34) & "," & Chr(34) & MainPath & Chr(34) & "," & Chr(34) & AgentPath & Chr(34)
  66.     buildreport = report
  67. End Function
  68.  
  69.  
  70. Function main
  71.     Dim strip, strcompip, strcompname, struser, strpasswd As String
  72.     Dim wmiinst As Object
  73.     Dim reg As Object
  74.     Dim locreg As Object
  75.     Dim objs As Object
  76.     Dim foundpsc As Boolean
  77.     Dim agent As Boolean
  78.     Dim Full As Boolean
  79.     Dim AgentPath As String
  80.     Dim AgentBuild As Long
  81.     Dim FullBuild As Long
  82.     Dim FullPath As String
  83.     Dim HomePath As String
  84.     Dim SaveFile As String
  85.     Dim Build
  86.     Dim filecheck As Object
  87.     Dim servicestatus As Integer '0 - not installed 1 - running 2 - stopped - 3 disabled - 4 manual
  88.     Dim serviceruns As Boolean
  89.     Dim objSWbemLocator As Object
  90.     Dim objSWbemServices As Object
  91.     foundpsc = false    
  92.     
  93.     strcompip = GetParameter("ComputerIP")
  94.     strcompname=GetParameter("Computername")
  95.     struser = GetParameter("User")
  96.     strpasswd = GetParameter("Password")
  97.     Set locreg = Registry.Connect("127.0.0.1")
  98.     If Not locreg is Nothing Then
  99.         HomeDir = locreg.read("SOFTWARE\GFI\LNSS7","Path")
  100.         SaveFile = HomeDir & "Data\Reports\LPMC-Network-Report.csv"            
  101.     End If
  102.     If struser = "" Then
  103. '        echo("This script must run under alternative credentials")
  104.         WriteToLocalFile HomeDir & "Data\Reports\Error.txt","Currently Logged-On user detected. This script must run under alternative credentials "
  105. '    Exit Sub
  106.     End If
  107.     'Socket.SetTimeout 1000,1000
  108.     strip = Socket.DnsLookup(Socket.ReverseDnsLookup("127.0.0.1"))
  109.     If strip = strcompip Then
  110.         struser = "" 'localhost
  111.         strpasswd = ""
  112.     End If
  113.  
  114.         cr = Chr(13) +  Chr(10)    'carriage return
  115.         Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
  116.         Set objSWbemServices = objSWbemLocator.ConnectServer(strcompip, "root/cimv2", struser, strpasswd)
  117.         Set wmiinst = objSWbemServices.execquery("Select * from Win32_service")
  118.         If wmiinst is Nothing Then 
  119.             WriteToLocalFile "Data\Reports\Error.txt","Error Retrieving services information instances from WMI on the target machine " & strcompip
  120.             ' check to see if that instance is available
  121.         Else
  122.             For Each objs In wmiinst        ' loop through each instance
  123.                 If objs.DisplayName = "GFI LANguard P.S.C. 2.0 agent service" Then
  124.                     servicestatus = 1
  125.                     foundpsc = true
  126.                     Agent = True
  127.                     If objs.State = "Running" Then 
  128.                         servicestatus = 1
  129.                         serviceruns = true
  130.                     Else
  131.                         serviceruns = false
  132.                     End If
  133.                     If objs.State = "Stopped" Then servicestatus = 2
  134.                     If objs.StartMode = "Disabled" Then servicestatus = 3
  135.                     If objs.StartMode = "Manual" Then servicestatus = 4                    
  136.                 End If
  137.             Next
  138.  
  139.             Set reg = Registry.Connect(strcompip)
  140.             If Not reg is Nothing Then 'Detecting Full installation information
  141.                 FullPath = reg.read("SOFTWARE\GFI\LPSC2","Path")
  142.                 FullBuild = reg.read("SOFTWARE\GFI\LPSC2","Build")
  143. '                CreateDir(HomeDir & "Reports")
  144.                 If Fullpath <> "" Then                    
  145.                     Set filecheck = file.connect(strcompip)
  146.                     If Not filecheck is Nothing Then
  147.                         If filecheck.open(Fullpath & "lpsc.exe", GENERIC_READ,OPEN_EXISTING) Then
  148.                             full = true
  149.                         Else
  150.                             full = false
  151.                         End If
  152.                     End If 
  153.                 End If
  154.             Else
  155.                 WriteToLocalFile "Error.txt","Unable to connect to registry on remote computer:" & strcompip
  156.             End If 
  157.  
  158.             If Agent = true Then ' Agent Information detection
  159.                 AgentPath = reg.read("SOFTWARE\GFI\LPSC2\AgentSettings","Path")
  160.                 AgentBuild = reg.read("SOFTWARE\GFI\LPSC2\AgentSettings","Build")
  161.             End If 
  162.             If foundpsc = false Then 
  163.                 servicestatus=0
  164.                 WriteToLocalFile SaveFile,buildreport(strcompip,strcompname,ServiceStatus, Agent, full, AgentBuild,FullBuild,ServiceRuns,AgentPath,FullPath)
  165.  
  166.             Else
  167.                 WriteToLocalFile SaveFile,buildreport(strcompip,strcompname,ServiceStatus, Agent, full, AgentBuild,FullBuild,ServiceRuns,AgentPath,FullPath)
  168.  
  169.             End If
  170.             
  171.     
  172. End If 
  173. End Function
  174.