Member_2_1242703
asked on
Find .NET version through script
Does anyone have a script that I could run to tell me what version of .NET framework is installed on a client machine?
ASKER
Here's what i've got...
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
WScript.Echo " ========================== ========== ======"
WScript.Echo "Computer: " & strComputer
WScript.Echo " ========================== ========== ======"
strExecQuery = "SELECT * FROM Win32_SoftwareElement where Manufacturer = 'Microsoft'"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery(st rExecQuery , "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
If InStr(1, objItem.Path, "Microsoft.NET\Framework", 1) <> 0 And InStr(1, objItem.Path, "mscoree", 1) <> 0 Then
WScript.Echo "Dot.Net Framework Version: " & objItem.Version
End If
Next
It's skipping over the .NET part for some reason
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
WScript.Echo " ==========================
WScript.Echo "Computer: " & strComputer
WScript.Echo " ==========================
strExecQuery = "SELECT * FROM Win32_SoftwareElement where Manufacturer = 'Microsoft'"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery(st
For Each objItem In colItems
If InStr(1, objItem.Path, "Microsoft.NET\Framework",
WScript.Echo "Dot.Net Framework Version: " & objItem.Version
End If
Next
It's skipping over the .NET part for some reason
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok here's what I've got now...
Dim OutPutFile
Dim FileSystem
Set FileSystem = WScript.CreateObject("Scri pting.File SystemObje ct")
Set OutPutFile = FileSystem.CreateTextFile( "dotnet.tx t", True)
OutPutFile.WriteLine ".NET Framework 2.0 Version " & GetDotNet("2.0")
OutPutFile.WriteLine ".NET Framework 1.1 Version " & GetDotNet("1.1")
OutPutFile.WriteLine ".NET Framework 1.0 Version " & GetDotNet("1.0")
Function GetDotNet(dnVer)
'Requires Function CompareVersion
Dim Fso : Set Fso = CreateObject("Scripting.Fi leSystemOb ject")
Dim frameWorkFolder
frameWorkFolder = fso.GetSpecialFolder(0) & "\Microsoft.NET\Framework" '0=WindowsFolder
If dnVer = "2.0" Then
If fso.FolderExists(frameWork Folder & "\v2.0.50727") AND fso.FileExists(frameWorkFo lder & "\v2.0.50727\Mscorlib.dll" ) Then
If CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v2.0.50727\Mscorlib.dll" ),"2.0.507 27.42") = 0 Then
GetDotNet = "RTM is installed on machine "
Else
GetDotNet = "- unknown is installed on machine "
End If
Else
GetDotNet = "is not installed on machine "
End If
End If
If dnVer = "1.1" Then
If fso.FolderExists(frameWork Folder & "\v1.1.4322") And Fso.FileExists(frameWorkFo lder & "\v1.1.4322\Mscorlib.dll") Then
If CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v1.1.4322\Mscorlib.dll") ,"1.1.4322 .573") = 0 Then
GetDotNet = "RTM"
ElseIf CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v1.1.4322\Mscorlib.dll") ,"1.1.4322 .2032") = 0 Or _
CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v1.1.4322\Mscorlib.dll") ,"1.1.4322 .2300") = 0 Then
GetDotNet = "SP1 is installed on machine "
Else
GetDotNet = "- unknown is installed on machine "
End If
Else
GetDotNet = "is not installed on machine "
End If
End If
If dnVer = "1.0" then
If fso.FolderExists(frameWork Folder & "\v1.0.03705") AND fso.FileExists(frameWorkFo lder & "\v1.0.03705\Mscorlib.dll" ) Then
If CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v1.0.03705\Mscorlib.dll" ),"1.0.370 5.0") = 0 Then
GetDotNet = "RTM"
ElseIf CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v1.0.03705\Mscorlib.dll" ),"1.0.370 5.209") = 0 Then
GetDotNet = "SP1"
ElseIf CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v1.0.03705\Mscorlib.dll" ),"1.0.370 5.288") = 0 Then
GetDotNet = "SP2"
ElseIf CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v1.0.03705\Mscorlib.dll" ),"1.0.370 5.6018") = 0 Then
GetDotNet = "SP3 is installed on machine "
Else
GetDotNet = "- unknown is installed on machine "
End If
Else
GetDotNet = "is not installed on machine "
End If
End If
End Function
Function CompareVersion(ByVal strVersion1, ByVal strVersion2)
Dim v1, v2, t1, t2
'Returns -1 if strVersion1<strVersion2
'Returns 1 if strVersion1>strVersion2
'Returns 0 if strVersion1=strVersion2
CompareVersion = 0
If strVersion1="" Or strVersion2="" Then
If strVersion1<strVersion2 Then
CompareVersion = -1
Exit Function
Else
If v1>v2 Then
CompareVersion = 1
Exit Function
Else
CompareVersion = 0
Exit Function
End If
End If
End If
t1 = Instr(strVersion1, ".")
If t1 = 0 Then t1 = Len(strVersion1)+1
t2 = Instr(strVersion2, ".")
If t2 = 0 Then t2 = Len(strVersion2)+1
Do While True
v1 = CLng(Left(strVersion1,t1-1 ))
v2 = CLng(Left(strVersion2,t2-1 ))
If v1<v2 Then
CompareVersion = -1
Exit Function
Else
If v1>v2 Then
CompareVersion = 1
Exit Function
End If
End iF
strVersion1 = Mid(strVersion1,t1+1)
strVersion2 = Mid(strVersion2,t2+1)
If strVersion1="" Or strVersion2="" Then
If strVersion1<strVersion2 Then
CompareVersion = -1
Exit Function
Else
If v1>v2 Then
CompareVersion = 1
Exit Function
Else
CompareVersion = 0
Exit Function
End If
End If
End iF
t1 = Instr(strVersion1, ".")
If t1 = 0 Then t1 = Len(strVersion1)+1
t2 = Instr(strVersion2, ".")
If t2 = 0 Then t2 = Len(strVersion2)+1
Loop
End Function
It works fine. I've been playing around with it a bit. I'd like to be able to have it look at AD and run this script on the machines from that list. I can't get anything to
work though. So basically I want to use the code above to check all the computers on a network.
Dim OutPutFile
Dim FileSystem
Set FileSystem = WScript.CreateObject("Scri
Set OutPutFile = FileSystem.CreateTextFile(
OutPutFile.WriteLine ".NET Framework 2.0 Version " & GetDotNet("2.0")
OutPutFile.WriteLine ".NET Framework 1.1 Version " & GetDotNet("1.1")
OutPutFile.WriteLine ".NET Framework 1.0 Version " & GetDotNet("1.0")
Function GetDotNet(dnVer)
'Requires Function CompareVersion
Dim Fso : Set Fso = CreateObject("Scripting.Fi
Dim frameWorkFolder
frameWorkFolder = fso.GetSpecialFolder(0) & "\Microsoft.NET\Framework"
If dnVer = "2.0" Then
If fso.FolderExists(frameWork
If CompareVersion(fso.GetFile
GetDotNet = "RTM is installed on machine "
Else
GetDotNet = "- unknown is installed on machine "
End If
Else
GetDotNet = "is not installed on machine "
End If
End If
If dnVer = "1.1" Then
If fso.FolderExists(frameWork
If CompareVersion(fso.GetFile
GetDotNet = "RTM"
ElseIf CompareVersion(fso.GetFile
CompareVersion(fso.GetFile
GetDotNet = "SP1 is installed on machine "
Else
GetDotNet = "- unknown is installed on machine "
End If
Else
GetDotNet = "is not installed on machine "
End If
End If
If dnVer = "1.0" then
If fso.FolderExists(frameWork
If CompareVersion(fso.GetFile
GetDotNet = "RTM"
ElseIf CompareVersion(fso.GetFile
GetDotNet = "SP1"
ElseIf CompareVersion(fso.GetFile
GetDotNet = "SP2"
ElseIf CompareVersion(fso.GetFile
GetDotNet = "SP3 is installed on machine "
Else
GetDotNet = "- unknown is installed on machine "
End If
Else
GetDotNet = "is not installed on machine "
End If
End If
End Function
Function CompareVersion(ByVal strVersion1, ByVal strVersion2)
Dim v1, v2, t1, t2
'Returns -1 if strVersion1<strVersion2
'Returns 1 if strVersion1>strVersion2
'Returns 0 if strVersion1=strVersion2
CompareVersion = 0
If strVersion1="" Or strVersion2="" Then
If strVersion1<strVersion2 Then
CompareVersion = -1
Exit Function
Else
If v1>v2 Then
CompareVersion = 1
Exit Function
Else
CompareVersion = 0
Exit Function
End If
End If
End If
t1 = Instr(strVersion1, ".")
If t1 = 0 Then t1 = Len(strVersion1)+1
t2 = Instr(strVersion2, ".")
If t2 = 0 Then t2 = Len(strVersion2)+1
Do While True
v1 = CLng(Left(strVersion1,t1-1
v2 = CLng(Left(strVersion2,t2-1
If v1<v2 Then
CompareVersion = -1
Exit Function
Else
If v1>v2 Then
CompareVersion = 1
Exit Function
End If
End iF
strVersion1 = Mid(strVersion1,t1+1)
strVersion2 = Mid(strVersion2,t2+1)
If strVersion1="" Or strVersion2="" Then
If strVersion1<strVersion2 Then
CompareVersion = -1
Exit Function
Else
If v1>v2 Then
CompareVersion = 1
Exit Function
Else
CompareVersion = 0
Exit Function
End If
End If
End iF
t1 = Instr(strVersion1, ".")
If t1 = 0 Then t1 = Len(strVersion1)+1
t2 = Instr(strVersion2, ".")
If t2 = 0 Then t2 = Len(strVersion2)+1
Loop
End Function
It works fine. I've been playing around with it a bit. I'd like to be able to have it look at AD and run this script on the machines from that list. I can't get anything to
work though. So basically I want to use the code above to check all the computers on a network.
ASKER
Sorry! I did end up getting thatscript to work. Thanks!
ASKER
If anyone cares, here's the final product. Works great!
Dim OutPutFile
Dim FileSystem
Set FileSystem = WScript.CreateObject("Scri pting.File SystemObje ct")
Set OutPutFile = FileSystem.CreateTextFile( "dotnet.tx t", True)
OutPutFile.WriteLine ".NET Framework 2.0 Version " & GetDotNet("2.0")
OutPutFile.WriteLine ".NET Framework 1.1 Version " & GetDotNet("1.1")
OutPutFile.WriteLine ".NET Framework 1.0 Version " & GetDotNet("1.0")
Function GetDotNet(dnVer)
'Requires Function CompareVersion
Dim Fso : Set Fso = CreateObject("Scripting.Fi leSystemOb ject")
Dim frameWorkFolder
frameWorkFolder = fso.GetSpecialFolder(0) & "\Microsoft.NET\Framework" '0=WindowsFolder
If dnVer = "2.0" Then
If fso.FolderExists(frameWork Folder & "\v2.0.50727") AND fso.FileExists(frameWorkFo lder & "\v2.0.50727\Mscorlib.dll" ) Then
If CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v2.0.50727\Mscorlib.dll" ),"2.0.507 27.42") = 0 Then
GetDotNet = "RTM is installed on machine "
Else
GetDotNet = "- unknown is installed on machine "
End If
Else
GetDotNet = "is not installed on machine "
End If
End If
If dnVer = "1.1" Then
If fso.FolderExists(frameWork Folder & "\v1.1.4322") And Fso.FileExists(frameWorkFo lder & "\v1.1.4322\Mscorlib.dll") Then
If CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v1.1.4322\Mscorlib.dll") ,"1.1.4322 .573") = 0 Then
GetDotNet = "RTM"
ElseIf CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v1.1.4322\Mscorlib.dll") ,"1.1.4322 .2032") = 0 Or _
CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v1.1.4322\Mscorlib.dll") ,"1.1.4322 .2300") = 0 Then
GetDotNet = "SP1 is installed on machine "
Else
GetDotNet = "- unknown is installed on machine "
End If
Else
GetDotNet = "is not installed on machine "
End If
End If
If dnVer = "1.0" then
If fso.FolderExists(frameWork Folder & "\v1.0.03705") AND fso.FileExists(frameWorkFo lder & "\v1.0.03705\Mscorlib.dll" ) Then
If CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v1.0.03705\Mscorlib.dll" ),"1.0.370 5.0") = 0 Then
GetDotNet = "RTM"
ElseIf CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v1.0.03705\Mscorlib.dll" ),"1.0.370 5.209") = 0 Then
GetDotNet = "SP1"
ElseIf CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v1.0.03705\Mscorlib.dll" ),"1.0.370 5.288") = 0 Then
GetDotNet = "SP2"
ElseIf CompareVersion(fso.GetFile Version(fr ameWorkFol der & "\v1.0.03705\Mscorlib.dll" ),"1.0.370 5.6018") = 0 Then
GetDotNet = "SP3 is installed on machine "
Else
GetDotNet = "- unknown is installed on machine "
End If
Else
GetDotNet = "is not installed on machine "
End If
End If
End Function
Function CompareVersion(ByVal strVersion1, ByVal strVersion2)
Dim v1, v2, t1, t2
'Returns -1 if strVersion1<strVersion2
'Returns 1 if strVersion1>strVersion2
'Returns 0 if strVersion1=strVersion2
CompareVersion = 0
If strVersion1="" Or strVersion2="" Then
If strVersion1<strVersion2 Then
CompareVersion = -1
Exit Function
Else
If v1>v2 Then
CompareVersion = 1
Exit Function
Else
CompareVersion = 0
Exit Function
End If
End If
End If
t1 = Instr(strVersion1, ".")
If t1 = 0 Then t1 = Len(strVersion1)+1
t2 = Instr(strVersion2, ".")
If t2 = 0 Then t2 = Len(strVersion2)+1
Do While True
v1 = CLng(Left(strVersion1,t1-1 ))
v2 = CLng(Left(strVersion2,t2-1 ))
If v1<v2 Then
CompareVersion = -1
Exit Function
Else
If v1>v2 Then
CompareVersion = 1
Exit Function
End If
End iF
strVersion1 = Mid(strVersion1,t1+1)
strVersion2 = Mid(strVersion2,t2+1)
If strVersion1="" Or strVersion2="" Then
If strVersion1<strVersion2 Then
CompareVersion = -1
Exit Function
Else
If v1>v2 Then
CompareVersion = 1
Exit Function
Else
CompareVersion = 0
Exit Function
End If
End If
End iF
t1 = Instr(strVersion1, ".")
If t1 = 0 Then t1 = Len(strVersion1)+1
t2 = Instr(strVersion2, ".")
If t2 = 0 Then t2 = Len(strVersion2)+1
Loop
End Function
Dim OutPutFile
Dim FileSystem
Set FileSystem = WScript.CreateObject("Scri
Set OutPutFile = FileSystem.CreateTextFile(
OutPutFile.WriteLine ".NET Framework 2.0 Version " & GetDotNet("2.0")
OutPutFile.WriteLine ".NET Framework 1.1 Version " & GetDotNet("1.1")
OutPutFile.WriteLine ".NET Framework 1.0 Version " & GetDotNet("1.0")
Function GetDotNet(dnVer)
'Requires Function CompareVersion
Dim Fso : Set Fso = CreateObject("Scripting.Fi
Dim frameWorkFolder
frameWorkFolder = fso.GetSpecialFolder(0) & "\Microsoft.NET\Framework"
If dnVer = "2.0" Then
If fso.FolderExists(frameWork
If CompareVersion(fso.GetFile
GetDotNet = "RTM is installed on machine "
Else
GetDotNet = "- unknown is installed on machine "
End If
Else
GetDotNet = "is not installed on machine "
End If
End If
If dnVer = "1.1" Then
If fso.FolderExists(frameWork
If CompareVersion(fso.GetFile
GetDotNet = "RTM"
ElseIf CompareVersion(fso.GetFile
CompareVersion(fso.GetFile
GetDotNet = "SP1 is installed on machine "
Else
GetDotNet = "- unknown is installed on machine "
End If
Else
GetDotNet = "is not installed on machine "
End If
End If
If dnVer = "1.0" then
If fso.FolderExists(frameWork
If CompareVersion(fso.GetFile
GetDotNet = "RTM"
ElseIf CompareVersion(fso.GetFile
GetDotNet = "SP1"
ElseIf CompareVersion(fso.GetFile
GetDotNet = "SP2"
ElseIf CompareVersion(fso.GetFile
GetDotNet = "SP3 is installed on machine "
Else
GetDotNet = "- unknown is installed on machine "
End If
Else
GetDotNet = "is not installed on machine "
End If
End If
End Function
Function CompareVersion(ByVal strVersion1, ByVal strVersion2)
Dim v1, v2, t1, t2
'Returns -1 if strVersion1<strVersion2
'Returns 1 if strVersion1>strVersion2
'Returns 0 if strVersion1=strVersion2
CompareVersion = 0
If strVersion1="" Or strVersion2="" Then
If strVersion1<strVersion2 Then
CompareVersion = -1
Exit Function
Else
If v1>v2 Then
CompareVersion = 1
Exit Function
Else
CompareVersion = 0
Exit Function
End If
End If
End If
t1 = Instr(strVersion1, ".")
If t1 = 0 Then t1 = Len(strVersion1)+1
t2 = Instr(strVersion2, ".")
If t2 = 0 Then t2 = Len(strVersion2)+1
Do While True
v1 = CLng(Left(strVersion1,t1-1
v2 = CLng(Left(strVersion2,t2-1
If v1<v2 Then
CompareVersion = -1
Exit Function
Else
If v1>v2 Then
CompareVersion = 1
Exit Function
End If
End iF
strVersion1 = Mid(strVersion1,t1+1)
strVersion2 = Mid(strVersion2,t2+1)
If strVersion1="" Or strVersion2="" Then
If strVersion1<strVersion2 Then
CompareVersion = -1
Exit Function
Else
If v1>v2 Then
CompareVersion = 1
Exit Function
Else
CompareVersion = 0
Exit Function
End If
End If
End iF
t1 = Instr(strVersion1, ".")
If t1 = 0 Then t1 = Len(strVersion1)+1
t2 = Instr(strVersion2, ".")
If t2 = 0 Then t2 = Len(strVersion2)+1
Loop
End Function
----------
there is a script posted here
http://66.249.93.104/search?q=cache:0cI8uxtfW7UJ:www.codecomments.com/archive299-2005-10-658987.html
----------
bruintje
share what you know, learn what you don't