How to querry network for machines running the .NET runtime?

  • Thread starter Thread starter Mike S
  • Start date Start date
M

Mike S

I am trying to find out what percentage of machines on my network have the
..NET runtime installed. What would be the best reccomendation for this
(other than SMS)?

Is using WSH & WMI an answer? Can anyone point me in te right direction?
 
I came up with a solution. Whether or not it's the best one, I don't know,
but it works.



Steps:

1) Export list of computer names from a container or query in Active
Directory Users and Computers.

2) Run script

'copy and paste this into the command window and hit enter

'be sure to change the paths if necessary

cscript "<ScriptPath>\<ScriptName>.vbs" "<FilePath>" "<HostFileName>"
"<LogFileName>" 1



3) View Log



The script:



#######################################

Dim strLogMessage

Dim strIpFile

Dim strLogFile

Dim strPath

Dim intExtendedLog

strLogMessage=""

strIpFile=""

strLogFile=""

strPath=""

intExtendedLog=0



On Error Resume Next



' Check Script Engine

If right(ucase(wscript.FullName),11)="WSCRIPT.EXE" Then

strLogMessage = strLogMessage & LogMessage( "ERROR: You must run this
script using cscript, for example 'cscript " & wscript.scriptname & "'.", 1,
1 )

wscript.quit 0

End If



' Check USAGE

If wscript.arguments.count <> 4 Then

strLogMessage = strLogMessage & LogMessage( "Usage: cscript " &
wscript.scriptname & " <Path> <IpFile.txt> <LogFile> <ExtendedLog>" & vbCrLf
& vbCrLf & _

" <Path> must be a full path of a folder that contains all of these
files:" & vbCrLf & _

" " & strIpFile & vbCrLf & _

" " & strLogFile & vbCrLf , 1, 1 )

wscript.quit

End If



' Set Command Switch Variables

strPath = wscript.arguments(0)

strIpFile = wscript.arguments(1)

strLogFile = wscript.arguments(2)

intExtendedLog = wscript.arguments(3)



If intExtendedLog<>"0" Then

intExtendedLog=1

Else

intExtendedLog=0

End If





' Verify that ipfile is accessible.

Set onet = createobject("wscript.network")

Set ofs = createobject("scripting.filesystemobject")

Set oipFile = ofs.opentextfile(strIpFile, 1, false)



If (Err.Number <> 0) Then

strLogMessage = strLogMessage & LogMessage( "Cannot open " & strIpFile,
1, 1 )

wscript.quit

End If





' Make sure to end with a \ character.

If Right(strPath, 1) <> "\" Then

strPath = strPath & "\"

End If





Set osvcLocal = getobject("winmgmts:root\cimv2")



'The error-handling code is below the function that may throw one - execute
it.

On Error Resume Next



While Not oipFile.atEndOfStream

ip = oipFile.ReadLine()

ip = Trim( ip )

strLogMessage = strLogMessage & LogMessage( "Connecting to " & ip &
"...", 0, intExtendedLog )



Err.Clear

Set osvcRemote =
GetObject("winmgmts:{impersonationLevel=impersonate}\\" & ip &
"\root\cimv2")



If (Err.Number <> 0) Then

strLogMessage = strLogMessage & LogMessage( "Failed to connect to
" & ip & ".", 1, intExtendedLog )

Else

'exeCorrectPatch = detectOSVersion( osvcRemote )

'if (exeCorrectPatch <> "") then

' Lay the bits on the remote computer.

strLogMessage = strLogMessage & LogMessage( "Checking for
..NET Runtime " & exeCorrectPatch & "...", 0, intExtendedLog )



strLogMessage = strLogMessage &
LogMessage( ip & vbtab & FindTheRuntime( osvcRemote, ip ), 1,
intExtendedLog )



strLogMessage = strLogMessage &
LogMessage( "Check Complete.", 0, intExtendedLog )

'End If

End If ' Do the next IP address, then the next IP address...



'short delay

wscript.Sleep 500 ' Sleep one half second.

Wend



oipFile.close()

Set oipFile = Nothing



strLogMessage = strLogMessage & LogMessage( "Script complete. Exiting.", 0,
intExtendedLog )





'commit the log info to a file

Set logFile = CreateObject("scripting.filesystemobject")

Set oFileStream = logFile.CreateTextFile( strPath & strLogFile, True )

oFileStream.Write( strLogMessage )

oFileStream.Close()

Set oFileStream = Nothing

Set logFile = Nothing



Function FindTheRuntime( osvcRemote, ip )

strRuntime="Microsoft .NET Framework"

bFound=False



For Each Process In osvcRemote.InstancesOf("Win32_product")

If InStr( 1, Process.Name, strRuntime, 1 )>0 Then

bFound=True

Exit For

End If

Next



FindTheRuntime = bFound

End Function



Function detectOSVersion( osvcRemote )

Dim systemType

systemType="do it"

set oOSInfo = osvcRemote.InstancesOf("Win32_OperatingSystem")



'Only one instance is ever returned (the currently active OS), even
though the following is a foreach.

For Each objOperatingSystem In oOSInfo



If (objOperatingSystem.OSType <> 18) Then

' Make sure that this computer is Windows NT-based.

strLogMessage = strLogMessage & LogMessage( ip & " is not a
Windows XP, Windows 2000, or Windows 2003 Server computer.", 0,
intExtendedLog )

Else

systemType = objOperatingSystem.Version

End If



Next



detectOSPatch = systemType

End Function



Function LogMessage( theMessage, isMandatoryMessage, useExtendedLog )

If isMandatoryMessage=1 OR useExtendedLog=1 Then

wscript.echo theMessage

LogMessage = vbcrlf & theMessage

Else

wscript.echo theMessage

LogMessage = ""

End If

End Function



#######################################
 
Back
Top