How can i detect witch frameworks are installed in a machine
-
Friday, February 12, 2010 6:17 PMHi,
I'm looking on the Internet but not found anything about how to detect what the frameworks are installed. Someone I can provide that code to VB. Net?
TcoUpLoad (work with Vb6 and VbNet)
Answers
-
Friday, February 12, 2010 6:36 PM
Hi,
I'm looking on the Internet but not found anything about how to detect what the frameworks are installed. Someone I can provide that code to VB. Net?
TcoUpLoad (work with Vb6 and VbNet)
There is a code written in C Sharp, how to detect what frameworks are installed in your machine.
the project is here: http://www.codeproject.com/KB/dotnet/frameworkversiondetection.aspx
For you to convert: http://www.developerfusion.com/tools/convert/csharp-to-vb/
Just Be Humble Malange!- Marked As Answer by Martin_XieModerator Friday, February 19, 2010 4:26 AM
-
Friday, February 12, 2010 10:00 PM
See if the below code works for you. I converted it and made some mods from the below link:
http://www.agusblog.com/wordpress/c-code-to-determine-which-version-of-the-net-framework-is-installed-177.htm
Dim DotNetFrameworkInfo As New DotNetFramework.SystemInfo Console.WriteLine(DotNetFrameworkInfo.HighestFrameworkVersion) Console.WriteLine(DotNetFrameworkInfo.NetFrameworkInstallationPath) Dim FrameworkVersionCollection As New Collection FrameworkVersionCollection = DotNetFrameworkInfo.FrameworkVersions For Each FrameworkVersion As String In FrameworkVersionCollection Console.WriteLine(FrameworkVersion) Next Imports System Imports System.IO Imports System.Security Imports System.Text.RegularExpressions Namespace DotNetFramework Public Class SystemInfo Private Const FRAMEWORK_PATH As String = "\Microsoft.NET\Framework" Private Const WINDIR1 As String = "windir" Private Const WINDIR2 As String = "SystemRoot" Private _versions As New Collection Public ReadOnly Property FrameworkVersions() As Collection Get Try GetVersions(NetFrameworkInstallationPath) Catch e1 As SecurityException Return Nothing End Try Return _versions End Get End Property Public ReadOnly Property HighestFrameworkVersion() As String Get Try Return GetHighestVersion(NetFrameworkInstallationPath) Catch e1 As SecurityException Return "Unknown" End Try End Get End Property Private Sub GetVersions(ByVal installationPath As String) Dim versions() As String = Directory.GetDirectories(installationPath, "v*") Dim VersionNumber As String _versions.Clear() For i As Integer = versions.Length - 1 To 0 Step -1 VersionNumber = ExtractVersion(versions(i)) If IsFrameworkVersionFormat(VersionNumber) Then _versions.Add(VersionNumber) End If Next i End Sub Private Function GetHighestVersion(ByVal installationPath As String) As String Dim versions() As String = Directory.GetDirectories(installationPath, "v*") Dim version As String = "Unknown" For i As Integer = versions.Length - 1 To 0 Step -1 version = ExtractVersion(versions(i)) If IsFrameworkVersionFormat(version) Then Return version End If Next i Return version End Function Private Function ExtractVersion(ByVal directory As String) As String Dim startIndex As Integer = directory.LastIndexOf("\") + 2 Return directory.Substring(startIndex, directory.Length - startIndex) End Function Private Shared Function IsFrameworkVersionFormat(ByVal str As String) As Boolean Return New Regex("^[0-9]+\.?[0-9]+\.?[0-9]*$").IsMatch(str) End Function Public ReadOnly Property NetFrameworkInstallationPath() As String Get Return WindowsPath & FRAMEWORK_PATH End Get End Property Public ReadOnly Property WindowsPath() As String Get Dim winDir As String = Environment.GetEnvironmentVariable(WINDIR1) If String.IsNullOrEmpty(winDir) Then winDir = Environment.GetEnvironmentVariable(WINDIR2) End If Return winDir End Get End Property End Class End Namespace
Paul ~~~~ Microsoft MVP (Visual Basic)- Marked As Answer by Martin_XieModerator Friday, February 19, 2010 4:26 AM
-
Saturday, February 13, 2010 9:21 AM
Hi Malange,
Take This very simple code:
"C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\vbc.exe") = True Then 'write here the code when the program found the frame work v1.0 Else 'write here the code when the program didn't find the frame work v1.0 End If If My.Computer.FileSystem.FileExists("C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\vbc.exe") = True Then 'write here the code when the program found the frame work v1.1 Else 'write here the code when the program didn't find the frame work v1.1 End If If My.Computer.FileSystem.FileExists("C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\vbc.exe") = True Then 'write here the code when the program found the frame work v2.0 Else 'write here the code when the program didn't find the frame work v2.0 End If If My.Computer.FileSystem.FileExists("C:\WINDOWS\Microsoft.NET\Framework\v3.0\vbc.exe") = True Then 'write here the code when the program found the frame work v3.0 Else 'write here the code when the program didn't find the frame work v3.0 End If If My.Computer.FileSystem.FileExists("C:\WINDOWS\Microsoft.NET\Framework\v3.5\vbc.exe") = True Then 'write here the code when the program found the frame work v3.5 Else 'write here the code when the program didn't find the frame work v3.5 End IfYou can change the path of the place that's the program search in by changing "c:\windows" to another path or to "%windir%"
Don't forget to mark this post as answer if this post help you
Mohamed Elghamry
- Marked As Answer by Martin_XieModerator Friday, February 19, 2010 4:26 AM
All Replies
-
Friday, February 12, 2010 6:36 PM
Hi,
I'm looking on the Internet but not found anything about how to detect what the frameworks are installed. Someone I can provide that code to VB. Net?
TcoUpLoad (work with Vb6 and VbNet)
There is a code written in C Sharp, how to detect what frameworks are installed in your machine.
the project is here: http://www.codeproject.com/KB/dotnet/frameworkversiondetection.aspx
For you to convert: http://www.developerfusion.com/tools/convert/csharp-to-vb/
Just Be Humble Malange!- Marked As Answer by Martin_XieModerator Friday, February 19, 2010 4:26 AM
-
Friday, February 12, 2010 10:00 PM
See if the below code works for you. I converted it and made some mods from the below link:
http://www.agusblog.com/wordpress/c-code-to-determine-which-version-of-the-net-framework-is-installed-177.htm
Dim DotNetFrameworkInfo As New DotNetFramework.SystemInfo Console.WriteLine(DotNetFrameworkInfo.HighestFrameworkVersion) Console.WriteLine(DotNetFrameworkInfo.NetFrameworkInstallationPath) Dim FrameworkVersionCollection As New Collection FrameworkVersionCollection = DotNetFrameworkInfo.FrameworkVersions For Each FrameworkVersion As String In FrameworkVersionCollection Console.WriteLine(FrameworkVersion) Next Imports System Imports System.IO Imports System.Security Imports System.Text.RegularExpressions Namespace DotNetFramework Public Class SystemInfo Private Const FRAMEWORK_PATH As String = "\Microsoft.NET\Framework" Private Const WINDIR1 As String = "windir" Private Const WINDIR2 As String = "SystemRoot" Private _versions As New Collection Public ReadOnly Property FrameworkVersions() As Collection Get Try GetVersions(NetFrameworkInstallationPath) Catch e1 As SecurityException Return Nothing End Try Return _versions End Get End Property Public ReadOnly Property HighestFrameworkVersion() As String Get Try Return GetHighestVersion(NetFrameworkInstallationPath) Catch e1 As SecurityException Return "Unknown" End Try End Get End Property Private Sub GetVersions(ByVal installationPath As String) Dim versions() As String = Directory.GetDirectories(installationPath, "v*") Dim VersionNumber As String _versions.Clear() For i As Integer = versions.Length - 1 To 0 Step -1 VersionNumber = ExtractVersion(versions(i)) If IsFrameworkVersionFormat(VersionNumber) Then _versions.Add(VersionNumber) End If Next i End Sub Private Function GetHighestVersion(ByVal installationPath As String) As String Dim versions() As String = Directory.GetDirectories(installationPath, "v*") Dim version As String = "Unknown" For i As Integer = versions.Length - 1 To 0 Step -1 version = ExtractVersion(versions(i)) If IsFrameworkVersionFormat(version) Then Return version End If Next i Return version End Function Private Function ExtractVersion(ByVal directory As String) As String Dim startIndex As Integer = directory.LastIndexOf("\") + 2 Return directory.Substring(startIndex, directory.Length - startIndex) End Function Private Shared Function IsFrameworkVersionFormat(ByVal str As String) As Boolean Return New Regex("^[0-9]+\.?[0-9]+\.?[0-9]*$").IsMatch(str) End Function Public ReadOnly Property NetFrameworkInstallationPath() As String Get Return WindowsPath & FRAMEWORK_PATH End Get End Property Public ReadOnly Property WindowsPath() As String Get Dim winDir As String = Environment.GetEnvironmentVariable(WINDIR1) If String.IsNullOrEmpty(winDir) Then winDir = Environment.GetEnvironmentVariable(WINDIR2) End If Return winDir End Get End Property End Class End Namespace
Paul ~~~~ Microsoft MVP (Visual Basic)- Marked As Answer by Martin_XieModerator Friday, February 19, 2010 4:26 AM
-
Saturday, February 13, 2010 9:21 AM
Hi Malange,
Take This very simple code:
"C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\vbc.exe") = True Then 'write here the code when the program found the frame work v1.0 Else 'write here the code when the program didn't find the frame work v1.0 End If If My.Computer.FileSystem.FileExists("C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\vbc.exe") = True Then 'write here the code when the program found the frame work v1.1 Else 'write here the code when the program didn't find the frame work v1.1 End If If My.Computer.FileSystem.FileExists("C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\vbc.exe") = True Then 'write here the code when the program found the frame work v2.0 Else 'write here the code when the program didn't find the frame work v2.0 End If If My.Computer.FileSystem.FileExists("C:\WINDOWS\Microsoft.NET\Framework\v3.0\vbc.exe") = True Then 'write here the code when the program found the frame work v3.0 Else 'write here the code when the program didn't find the frame work v3.0 End If If My.Computer.FileSystem.FileExists("C:\WINDOWS\Microsoft.NET\Framework\v3.5\vbc.exe") = True Then 'write here the code when the program found the frame work v3.5 Else 'write here the code when the program didn't find the frame work v3.5 End IfYou can change the path of the place that's the program search in by changing "c:\windows" to another path or to "%windir%"
Don't forget to mark this post as answer if this post help you
Mohamed Elghamry
- Marked As Answer by Martin_XieModerator Friday, February 19, 2010 4:26 AM