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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike S

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

    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?


  • Mike S

    #2
    Re: How to querry network for machines running the .NET runtime?

    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> "
    "<LogFileNa me>" 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(wsc ript.FullName), 11)="WSCRIPT.EX E" Then

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

    wscript.quit 0

    End If



    ' Check USAGE

    If wscript.argumen ts.count <> 4 Then

    strLogMessage = strLogMessage & LogMessage( "Usage: cscript " &
    wscript.scriptn ame & " <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.argumen ts(0)

    strIpFile = wscript.argumen ts(1)

    strLogFile = wscript.argumen ts(2)

    intExtendedLog = wscript.argumen ts(3)



    If intExtendedLog< >"0" Then

    intExtendedLog= 1

    Else

    intExtendedLog= 0

    End If





    ' Verify that ipfile is accessible.

    Set onet = createobject("w script.network" )

    Set ofs = createobject("s cripting.filesy stemobject")

    Set oipFile = ofs.opentextfil e(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("winm gmts:root\cimv2 ")



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

    On Error Resume Next



    While Not oipFile.atEndOf Stream

    ip = oipFile.ReadLin e()

    ip = Trim( ip )

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



    Err.Clear

    Set osvcRemote =
    GetObject("winm gmts:{impersona tionLevel=imper sonate}\\" & ip &
    "\root\cimv 2")



    If (Err.Number <> 0) Then

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

    Else

    'exeCorrectPatc h = detectOSVersion ( osvcRemote )

    'if (exeCorrectPatc h <> "") 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("s cripting.filesy stemobject")

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

    oFileStream.Wri te( strLogMessage )

    oFileStream.Clo se()

    Set oFileStream = Nothing

    Set logFile = Nothing



    Function FindTheRuntime( osvcRemote, ip )

    strRuntime="Mic rosoft .NET Framework"

    bFound=False



    For Each Process In osvcRemote.Inst ancesOf("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.Inst ancesOf("Win32_ OperatingSystem ")



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

    For Each objOperatingSys tem In oOSInfo



    If (objOperatingSy stem.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 = objOperatingSys tem.Version

    End If



    Next



    detectOSPatch = systemType

    End Function



    Function LogMessage( theMessage, isMandatoryMess age, useExtendedLog )

    If isMandatoryMess age=1 OR useExtendedLog= 1 Then

    wscript.echo theMessage

    LogMessage = vbcrlf & theMessage

    Else

    wscript.echo theMessage

    LogMessage = ""

    End If

    End Function



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




    "Mike S" <mshaw@pac.oded odea.edu> wrote in message
    news:%23OfA41qk DHA.3504@TK2MSF TNGP11.phx.gbl. ..[color=blue]
    > 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?
    >
    >[/color]


    Comment

    Working...