Question : get a remote windows server OS version and IP address without access permission on that server

Is it possible to get a remote windows server OS version and IP address without access permission on that server?

I know VBScript (  Set colGroups = GetObject("WinNT://" & strComputer & "")      colGroups.Filter = Array("group")  ) can get remote windows server groups information. Is there similar way to get server OS, IP address information.

When I use Windows Management Instrumentation (WMI) query, do I must have access permission on that server?

Thanks in advance.

Answer : get a remote windows server OS version and IP address without access permission on that server

Hi howruaz9,

Below is a script that should return all what you want.  You will recognize some of the script as I just added to what you already had.

I have also added in the IP Address part - But this slows down the query considerably.  I can't think of a faster way to get the IP address other than an effective ping of the computername (without permissions to query the server directly that is).

Anyway, see how you go!

Regards,
Daz.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
Dim var1
Dim var2
Dim strComputer
Dim dicCompOS

'on error resume next

Set dicCompOS = CreateObject("Scripting.Dictionary")
GetOSs()   '# Load Dictionary with all Domain Computers' Operating Systems

Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.OpenTextFile("PC_Info.txt",2,true)

'### Set Computer Here ###
strComputer = "YOUR_SRV"



tf.write("Server;IP Address;OS Name;OS Service Pack;Group(s);Member(s);Display Name;")
tf.writeline("AdsPath")

Set objComputer = GetObject("WinNT://" & strComputer)

objComputer.Filter = Array("group")

strIPAddress = fResolveIP(strComputer)

For Each objGroup In objComputer
    For Each objMember in objGroup.Members
        var1 = objMember.Name
        If objMember.Class <> "Group" And Err.Number = 0 Then
            var2 = ""
            On Error Resume Next
            var2 = objMember.FullName
            On Error Goto 0
            OSName = Split(dicCompOS(UCase(strComputer)), "¶")(0)
            OSSP   = Split(dicCompOS(UCase(strComputer)), "¶")(1)
            tf.writeline(strComputer & ";" & strIPAddress & ";" & OSName & ";" & OSSP & ";" & objGroup.Name & ";" & var1 & ";" & chr(34) & var2 & chr(34) & ";" & objMember.AdsPath)
        Else
            tf.writeline(strComputer & ";" & strIPAddress & ";" & OSName & ";" & OSSP & ";" & objGroup.Name & ";" & var1 & ";" & Chr(34) & chr(34) & ";" & objMember.AdsPath)
            Err.Clear
        End If
        var1 = ""
        var2 = ""
     Next
Next 
tf.close()

MsgBox "Done!"

Wscript.quit




Sub GetOSs()

    '# ADO Init
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("defaultNamingContext")
    strConfig = objRootDSE.Get("configurationNamingContext")
    Set objCommand = CreateObject("ADODB.Command")
    Set objConnection = CreateObject("ADODB.Connection")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open = "ADProvider"
    objCommand.ActiveConnection = objConnection
    objCommand.Properties("Page Size") = 100
    objCommand.Properties("Timeout") = 900
    '#

    '### LDAP Filter ###
    strFilter = "(&(objectClass=computer))"

    '### Attributes to retrieve ###
    strAttributes = "sAMAccountName,operatingSystem,operatingSystemServicePack"

    '### Execute LDAP Query ###
    strBase = "<LDAP://" & strDNSDomain & ">"'
    strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
    objCommand.CommandText = strQuery
    'On Error Resume Next
    Set objRecordSet = objCommand.Execute

    '### Go through records returned and store info ###
    Do Until objRecordSet.EOF
        dicCompOS(UCase(Replace(objRecordSet.Fields("sAMAccountName"), "$", ""))) = objRecordSet.Fields("operatingSystem") & "¶" & objRecordSet.Fields("operatingSystemServicePack")
        'MsgBox dicCompOS(objRecordSet.Fields("sAMAccountName")),,objRecordSet.Fields("sAMAccountName")
        objRecordSet.MoveNext
    Loop

End Sub

Function fResolveIP(strComputer)
    Dim wmiQuery, objWMIService, objPing, objStatus
    
    wmiQuery = "Select * From Win32_PingStatus Where " & _
    "Address = '" & strComputer & "'"
    
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set objPing = objWMIService.ExecQuery(wmiQuery)
    
    For Each objStatus in objPing
        If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
            fResolveIP = "Unknown"
        Else
            fResolveIP = objStatus.ProtocolAddress
        End If
    Next
End Function
Random Solutions  
 
programming4us programming4us