It's easy to read registry, but how to read registry on remote PC without
installing any ActiveX?
Thank you
If your remote PCs are all Windows 2000 or later, you can use WMI to access
their registries remotely without needing to install anything on them.
There is a very simple example of using WMI to read a remote registry at
http://desktopengineer.com/article.php?story=20020620003018212
Here is some sample WMI code to do exactly what you want to do (collect
software inventory) except that this sample uses full VB so you will need to
rewrite a few lines if you want to use VBScript:
http://gethelp.devx.com/techtips/nt_pro/10_minute_solutions/10minNT0702/10minNT0702.asp
"Sergiy Kravchenko" <s_kravtchenko@_yahoo_.com> wrote in message
news:ODVbMMtzCHA.1672@TK2MSFTNGP09...
Hi
For Win2k and WinXP (and NT 4.0/Win9x if you have installed WMI):
Here is a script that gets all computer names defined in AD (easily rewritten to
work in a NT 4.0 domain), pings them to see if they are online, and if they are,
uses WMI to enumerate the "Add/Remove Programs" list in registry.
It also get information about the OS version and the IP configuration.
Two files are created, one with a list of offline computers, and the other with
the result from the online computers.
The script can be run from any domain computer with a user that has access to
the remote computers.
' ****** Script start ******
' List of SW in ARP on all connectable computers as well as
' OS version and IP information saved here
' (you can use an UNC path also):
sInstalledSW = "c:\Inst.log"
' List of all computers that could not be connected
' saved here (you can use an UNC path also):
sNotConnected = "c:\NotConnected.log"
' Connect to the LDAP server's root object
Set oADsRootDSE = GetObject("LDAP://RootDSE")
sADsDefName = oADsRootDSE.Get("defaultNamingContext")
' if you want to start in a specific OU
'sTarget = "LDAP://OU=Laptops, " & sADsDefName
' The whole domain
sTarget = "LDAP://" & sADsDefName
MsgBox "Starting search from " & sTarget
Const ADS_SCOPE_ONELEVEL = 1
Const ADS_SCOPE_SUBTREE = 2
Const adVariant = 12
Set oConnection = CreateObject("ADODB.Connection")
Set oCommand = CreateObject("ADODB.Command")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "Active Directory Provider"
Set oCommand.ActiveConnection = oConnection
oCommand.CommandText = _
"SELECT Name, ADsPath FROM '" _
& sTarget _
& "' WHERE objectCategory = 'computer'"
oCommand.Properties("Page Size") = 100
oCommand.Properties("Timeout") = 30
oCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
oCommand.Properties("Cache Results") = False
Set oRecordSet = oCommand.Execute
' Iterate through the results
If oRecordset.Eof and oRecordSet.Bof Then
MsgBox "No records were found"
Else
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set fInstalledSW = oFSO.CreateTextFile(sInstalledSW, True)
Set fNotConnected = oFSO.CreateTextFile(sNotConnected, True)
oRecordSet.MoveFirst
Do Until oRecordSet.EOF
sComputerName = oRecordSet.Fields("Name")
If IsConnectible(sComputerName, "", "") Then
fInstalledSW.WriteLine "Information for: " & sComputerName
fInstalledSW.WriteLine oRecordSet.Fields("ADsPath") & vbCrLf
fInstalledSW.WriteLine vbCrLf
' get OS version and IP information
fInstalledSW.WriteLine GetInfo(sComputerName)
fInstalledSW.WriteLine "SW installed:"
fInstalledSW.WriteLine InstalledApplications(sComputerName)
fInstalledSW.WriteLine vbCrLf
Else
fNotConnected.WriteLine sComputerName
fNotConnected.WriteLine oRecordSet.Fields("ADsPath") & vbCrLf
End If
oRecordSet.MoveNext
Loop
fInstalledSW.Close
fNotConnected.Close
End If
MsgBox "Finished"
Function IsConnectible(sHost, iPings, iTO)
' Returns True or False based on the output from ping.exe
'
' Author: Alex Angelopoulos/Torgeir Bakken
' Works an "all" WSH versions
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used
If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
sTempFile = sTemp & "\runresult.tmp"
oShell.Run "%comspec% /c ping -n " & iPings & " -w " & iTO _
& " " & sHost & ">" & sTempFile, 0 , True
Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
FailIfNotExist, OpenAsDefault)
sResults = fFile.ReadAll
fFile.Close
oFSO.DeleteFile(sTempFile)
Select Case InStr(sResults,"TTL=")
Case 0 IsConnectible = False
Case Else IsConnectible = True
End Select
End Function
Function GetInfo(sNode)
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sNode & "\root\cimv2")
' get OS info
Set oOSset = oWMI.ExecQuery _
("Select Caption, Version, ServicePackMajorVersion " _
& "from Win32_OperatingSystem",,48)
For Each oOS in oOSset
sOSinfo = sOSinfo & "OS: " & oOS.Caption & vbCrLf
sOSinfo = sOSinfo & "OS version: " & oOS.Version & vbCrLf
sOSinfo = sOSinfo & "OS Service Pack: " _
& oOS.ServicePackMajorVersion & vbCrLf
Next
' get IP info
Set oNICset = oWMI.ExecQuery _
("select IPAddress, MACAddress, Description " _
& "from Win32_NetworkAdapterConfiguration " _
& "where IPEnabled=True",,48)
' create a MAC address container to search for duplicates
sMACAddrAll = ""
For Each oNIC In oNICset
' search for duplicates
If Not InStr(1, sMACAddrAll, oNIC.MACAddress, vbTextCompare) >0 Then
For Each sIPAddress In oNIC.IPAddress
' Discard NIC's without an active IP address
If Not Trim(sIPAddress) = "" Then
sIPinfo = sIPinfo & "NIC Description: " & oNIC.Description & vbCrLf
sIPinfo = sIPinfo & "NIC IP Address: " & sIPAddress & vbCrLf
sIPinfo = sIPinfo & "NIC MAC Address: " & oNIC.MACAddress & vbCrLf
End If
Exit For
Next
End If
sMACAddrAll = sMACAddrAll & oNIC.MACAddress & ","
Next
GetInfo = sOSinfo & vbCrLf & sIPinfo
End Function
Function InstalledApplications(node)
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Set oRegistry = _
GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& node & "/root/default:StdRegProv")
sBaseKey = _
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys)
For Each sKey In arSubKeys
iRC = oRegistry.GetStringValue( _
HKLM, sBaseKey & sKey, "DisplayName", sValue)
If iRC <> 0 Then
oRegistry.GetStringValue _
HKLM, sBaseKey & sKey, "QuietDisplayName", sValue
End If
If sValue <> "" Then
InstalledApplications = _
InstalledApplications & sValue & vbCrLf
End If
Next
End Function
--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and a ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter
Have a peak at this project:
http://poormanssms.sourceforge.net
On a down side - it requires WMI on *all* systems, and
only Win2K and WinXP come with it 'out of the box' (on
WinNT and Win9* this is separate install).
Branimir