Link to home
Start Free TrialLog in
Avatar of blahblah777
blahblah777

asked on

software on domain

Hi I need a vb script to run as part of the domain login script that will basically populate an excel spreadsheet with a list of all software install on each machine on the network.

is such a thing possible, does anyone have code for this already.
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image


It's quite a heavy task, and Excel isn't an ideal target because it just adds to that.

But...

Installed Software is exposed under the Win32_Product class in WMI. Writing that back to a CSV file isn't such a bother. I take it we're not trying to write to the same document / file?

I'll throw something together in the meantime.

Chris

Here you go, this sample will give you everything useful from that WMI class and write it to a file called Software.txt.

Chris

Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.OpenTextFile("Software.txt", 2, True, 0)
 
Set objWMIService = GetObject("winmgmts://./root/cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Product")
 
For Each objItem in colItems
  On Error Resume Next
  strID = "" : strID = objItem.IdentifyingNumber
  strName = "" : strName = objItem.Name
  strVersion = "" : strVersion = objItem.Version
  strCaption = "" : strCaption = objItem.Caption
 
  objFile.WriteLine strID & ",""" & strName & """," & strVersion & ",""" & strCaption & """"
Next
 
Set colItems = Nothing
Set objWMIService = Nothing
 
Set objFile = Nothing
Set objFileSystem = Nothing

Open in new window

You may like to check out this inventory script as well, similar to WildBoy's very good approach, but writes to Excel or CSV instead:
https://www.experts-exchange.com/questions/23143400/Script-that-queries-the-registry-for-all-the-applications-that-are-installed-on-a-domain-member-pc.html

Regards,

Rob.
Avatar of blahblah777
blahblah777

ASKER

This script is almost perfect, but is it possible to have it scan the domain for pcs rather then having to input a text file with computers?
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or, to get a list of computers from a specific OU only, you can use this.

Regards,

Rob.
On Error Resume Next
 
Const ADS_SCOPE_SUBTREE = 2
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
 
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
 
strOU = "OU=Computers,OU=Main Site,"
If Trim(strOU) <> "" Then
	If Right(strOU, 1) <> "," Then strOU = strOU & ","
Else
	strOU = ""
End If
 
objCommand.CommandText = _
    "SELECT Name FROM 'LDAP://" & strOU & strDNSDomain & "' WHERE objectCategory='computer'"
Set objRecordSet = objCommand.Execute
 
strResults = ""
Do Until objRecordSet.EOF
	If strResults = "" Then
		strResults = objRecordSet.Fields("Name").Value
	Else
		strResults = strResults & VbCrLf & objRecordSet.Fields("Name").Value
	End IF
    objRecordSet.MoveNext
Loop
 
Set objFile = objFSO.CreateTextFile("computers.txt", True)
objFile.Write strResults
objFile.Close
Set objFile = Nothing
MsgBox "Done"

Open in new window

bad Rob!

your ldap scan include the computers that are offline, it is bad

here is a scirpt that ping them to be sure they are online:
(note: i did not clean this script, i use it to detect bad process or files in my network)



' cscript GetListofComputers.vbs //nologo > computers.txt
' This script outputs a list of all the computers in your domain.
' The only thing you need to modify is the value of yourDomain.
' Replace LDAP://DC=montereytechgroup,DC=com with the 
' LDAP name of your domain.
 
Set objFSO = wscript.CreateObject("Scripting.FileSystemObject")
Set objshe = WScript.CreateObject("WScript.Shell")
 
thepath=WScript.ScriptFullName
p = instrRev(thepath,"\")
basedir  = left(thepath,p)
 
a = "zz_log_fini_TOUT_comp" & basename & ".txt"
 
Set objFil02 = objFso.OpenTextFile(basedir & a, 2, true)
If Err.number <> 0 Then
   Set objFil02 = objfso.OpenTextFile("c:\_stas\logs\" & a, 2, true)
end if
 
objFil02.WriteLine date & " " & time & " === log ldap start"
 
Set oRootDSE = GetObject("LDAP://RootDSE")
Set oDomain = GetObject("LDAP://" & oRootDSE.Get("DefaultNamingContext"))
'yourDomain="'LDAP://DC=domain,DC=company,DC=com'"
yourDomain="'" & cstr(oDomain.ADsPath) & "'"
 
'msgbox(yourdomain)
 
Const ADS_SCOPE_SUBTREE = 2
 
'=== Connect to Active Directory.
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
 
'=== Create a query for all computers in the domain.
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select cn from " & yourDomain & " where objectClass='computer'" 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
'wscript.echo objCommand.CommandText
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
 
'=== Loop though all computers in the domain.
 
i2=0
i3=0
tag01 = 0
 
Do Until objRecordSet.EOF
 
   '=== Write each computer name out to the file.
 
   strcomputer = objRecordSet.Fields("cn").Value
   a = FastPing(strComputer)
 
   '=== start wmi on the computer we found
 
if a=1 and _ 
strcomputer <> "LTCS418871" and _ 
strcomputer <> "LTID00010" and _ 
strcomputer <> "VMSEF20081114" then
   i3=i3+1
 
   pro01 = 0   '=== scan for process
   fil01 = 1   '=== scan for files by admin share
   
   if pro01=1 then
   
      on error resume next
      Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
      
      if err=0 then
      
         'objFil02.WriteLine date & " " & time & " " & i3 & " " & strcomputer & " scanning"
 
         '=== list all process of this pc
         '=== find certains program that are used to slow down internet connection
      
      
      
         bad = array( _ 
         "emule.exe", _ 
         "kazaa.exe", _ 
         "utorrent.exe", _ 
         "soulseek.exe", _
         "bittorrent.exe", _ 
         "bitcomet.exe", _ 
         "napster.exe", _ 
         "cuteftp.exe", _ 
         "mirc.exe", _ 
         "msnmsgr.exe", _ 
         "limewire.exe")
      
         i=0
         for each abad in bad
            'objFil02.WriteLine date & " " & time & " " & strcomputer & " scanning for: " & abad
         
            strQuery = "Select * from Win32_Process Where Name = '" & abad & "'"
      
            Set colProcesses = objWMIService.ExecQuery(strQuery)
            For Each objProcess In colProcesses
               If lCase(objProcess.Name) = abad Then
                  objFil02.WriteLine date & " " & time & " " & i3 & " " & strcomputer & "      " & abad & " running"
               End If
            Next
            i=i+1
         next
         'objFil02.WriteLine date & " " & time & " " & strcomputer & " " & a & " " & B
         'On Error Resume Next
         Set objWMIService = nothing
      else
         '=== error getting object
         err.clear
         objFil02.WriteLine date & " " & time & " " & strcomputer & " no answer from WMI"      
      end if
   end if
 
   if fil01=1 then
      'C:\WINDOWS\system32\mujemele.dll (Trojan.Vundo.H) -> Quarantined and deleted successfully.
      'C:\WINDOWS\system32\elemejum.ini (Trojan.Vundo.H) -> Quarantined and deleted successfully.
      'c:\WINDOWS\system32\hovolile.dll (Trojan.Vundo.H) -> Delete on reboot.
      'C:\WINDOWS\system32\zipubara.dll (Trojan.Vundo.H) -> Delete on reboot.
      'C:\WINDOWS\system32\diwikewo.dll (Trojan.Vundo.H) -> Delete on reboot.
      'C:\WINDOWS\system32\werenago.dll (Trojan.Vundo.H) -> Delete on reboot.
      'C:\WINDOWS\system32\POSP70US.DLL (Trojan.Agent) -> Delete on reboot.
      'C:\WINDOWS\system32\POSP70FR.DLL (Trojan.Agent) -> Quarantined and deleted successfully.
 
      fil02 = array( _ 
      "\WINDOWS\system32\mujemele.dll", _ 
      "\WINDOWS\system32\elemejum.ini", _ 
      "\WINDOWS\system32\hovolile.dll", _ 
      "\WINDOWS\system32\zipubara.dll", _ 
      "\WINDOWS\system32\diwikewo.dll", _ 
      "\WINDOWS\system32\werenago.dll", _ 
      "\WINDOWS\system32\POSP70US.DLL", _ 
      "\WINDOWS\system32\msnbw.exe", _ 
      "\WINDOWS\system32\formatsys.exe", _ 
      "\WINDOWS\system32\serbw.exe", _ 
      "\WINDOWS\sysinfomgr.exe", _ 
      "\WINDOWS\system32\POSP70FR.DLL")
      
      for each des in fil02
         a = "\\" & strcomputer & "\c$" & des
         if tag01=0 then
            tag01=1
            objFil02.WriteLine date & " " & time & " " & i3 & " " & "      " & a & "   TEST LINE to see if path is OK"
            objFil02.WriteLine date & " " & time & " " & i3 & " " & "------------------------------------------------"
         end if
         '\\ltid00008\c$
         if objFSO.fileEXISTS(a) then
            objFil02.WriteLine date & " " & time & " " & i3 & " " & strcomputer & "      " & a & " exist"
         end if
      next
   end if
 
end if
   objRecordSet.MoveNext
   i2=i2+1
Loop
objFil02.WriteLine date & " " & time & " total computers scanned: " & i3
objFil02.WriteLine date & " " & time & " fini tout"
 
'---------------------------------------
 
'My fast ping function
Function FastPing(strComputer)
   
   return = objshe.Run("ping "&strComputer&" -n 1 -w 500", 0, true)
   
   if return = 0 then 
      return = 1
   Else 
      return = 0
   End if
   fastping = return
End function
'---------------------------------------
 
function slowping(strComputer)
 
'=== IP address or hostname
strTarget = strcomputer
 
ON ERROR RESUME NEXT
 
Set colPings = objWMIService.ExecQuery ("Select * From Win32_PingStatus where Address = '" & strTarget & "'")
 
If Err = 0 Then
  Err.Clear
  For Each objPing in colPings
    If Err = 0 Then
      Err.Clear
      If objPing.StatusCode = 0 Then
        aa = aa & strTarget & " responded to ping."
        aa = aa & "Responding Address: " & objPing.ProtocolAddress
        aa = aa & "Responding Name: " & objPing.ProtocolAddressResolved
        aa = aa & "Bytes Sent: " & objPing.BufferSize
        aa = aa & "Time: " & objPing.ResponseTime & " ms"
        aa = aa & "TTL: " & objPing.ResponseTimeToLive & " seconds"
      Else
        aa = aa & strTarget & " did not respond to ping."
        aa = aa & "Status Code: " & objPing.StatusCode
      End If
    Else
      Err.Clear
      aa = aa & "Unable to call Win32_PingStatus on " & strComputer & "."      
    End If
  Next
Else
  Err.Clear
  aa = aa & "Unable to call Win32_PingStatus on " & strComputer & "."
End If
slowping = aa
 
end function
'--------------------------------------
 
function finip(strcomputer)
 
Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
'objFil02.WriteLine VbCrLf & "Computer Name: " & strComputer
'objFil02.WriteLine " IP Addresses & Subnet Masks"
 
For Each objNicConfig In colNicConfigs
  'WScript.Echo VbCrLf & "  Network Adapter " & objNicConfig.Index
  'WScript.Echo "    " & objNicConfig.Description & VbCrLf 
  'objFil02.WriteLine " IP Address(es): "
  For Each strIPAddress In objNicConfig.IPAddress
    objFil02.WriteLine " ip address: " & strIPAddress
  Next
  'WScript.Echo "    Subnet Mask(s):"
  For Each strIPSubnet In objNicConfig.IPSubnet
  '  WScript.Echo "        " & strIPSubnet
  Next
Next
 
end function
'-------------------------------------------

Open in new window

LOL!

Aw, I took a lashing.....

>> your ldap scan include the computers that are offline, it is bad

Not quite....the LDAP scan I provided dumps *all* computer names to a text file, nothing more.

Then, this file can be fed into the script I posted the link to.  *That* script will then check whether the machines are online or not......this script doesn't need to do that....

Regards,

Rob.
Thanks for the grade.

Regards,

Rob.
ah

sry then :)