Detecting Windows and .NET version

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

    Detecting Windows and .NET version

    Hi,

    How to detect Windows version and .NET version? I mean I want to know if
    user is using Windows 2000, XP, Vista and which Service Pack and version (XP
    Home, XP Pro, Vista Home Basic, Vista Premium, etc.). Is there any easy way
    to retrive this information?
    I'm wondering if all modern Windows version (2000, XP, 2003, Vista) has .NET
    installed by default or do I need to implement such a feature in Win32
    instead of .NET?

    Thanks,
    Arek

  • Willy Denoyette [MVP]

    #2
    Re: Detecting Windows and .NET version

    "Arek" <zoomee@nospam. comwrote in message
    news:uLkcIcidIH A.4588@TK2MSFTN GP06.phx.gbl...
    Hi,
    >
    How to detect Windows version and .NET version? I mean I want to know if
    user is using Windows 2000, XP, Vista and which Service Pack and version
    (XP Home, XP Pro, Vista Home Basic, Vista Premium, etc.). Is there any
    easy way to retrive this information?
    I'm wondering if all modern Windows version (2000, XP, 2003, Vista) has
    .NET installed by default or do I need to implement such a feature in
    Win32 instead of .NET?
    >
    Thanks,
    Arek
    >
    ..NET comes with WS2003 (v1.x), Vista (v1.x, v2) (V3 optional feature) and
    WS2008 (v1.x, v2 SP1) (v3 SP1 optional feature).
    v1.x = v1.0 & v1.1
    None come with v3.5.
    Downlevel OSses come without .NET.

    You can't run managed code if .NET is not installed, so there is no reliable
    way to get at this using C# (or other managed code).

    The easiest to get at this info is to run a simple (VB) script like this:

    On Error Resume Next
    ' Get OS Version
    For Each os in GetObject("winm gmts:").Instanc esOf ("Win32_Operati ngSystem")
    WScript.Echo "OS = " & os.Caption & " ,Version = " & os.Version & "
    ,Service Pack = " & os.ServicePackM ajorVersion
    Next

    'Get .NET Framework versions
    const HKLM = &H80000002
    Set
    objReg=GetObjec t("winmgmts:{im personationLeve l=impersonate}! \\.\root\defaul t:StdRegProv")

    regPath = "SOFTWARE\Micro soft\.NetFramew ork"
    objReg.EnumKey HKLM, regPath, subKeys
    If Err = 0 Then
    For Each subkey In subKeys
    if(Instr(1, subkey, "v")) Then
    WScript.Echo subkey
    End If
    Next
    Else
    WScript.Echo ".NET not available"
    End if

    Willy.




    Comment

    • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

      #3
      Re: Detecting Windows and .NET version

      Cowboy (Gregory A. Beamer) wrote:
      For .NET, the easiest way is the registry. While it is not C# (it is C++),
      here is a detection script:
      http://astebner.sts.winisp.net/Tools/detectFX.cpp.txt
      Environment.Ver ison must be easier.

      Arne

      Comment

      • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

        #4
        Re: Detecting Windows and .NET version

        Arne Vajhøj wrote:
        Cowboy (Gregory A. Beamer) wrote:
        >For .NET, the easiest way is the registry. While it is not C# (it is
        >C++), here is a detection script:
        >http://astebner.sts.winisp.net/Tools/detectFX.cpp.txt
        >
        Environment.Ver ison must be easier.
        At least if one unlike me can spell to Version ...

        :-)

        Arne

        Comment

        • Willy Denoyette [MVP]

          #5
          Re: Detecting Windows and .NET version

          "Willy Denoyette [MVP]" <willy.denoyett e@telenet.bewro te in message
          news:ONUzhLjdIH A.3940@TK2MSFTN GP05.phx.gbl...
          "Arek" <zoomee@nospam. comwrote in message
          news:uLkcIcidIH A.4588@TK2MSFTN GP06.phx.gbl...
          >Hi,
          >>
          >How to detect Windows version and .NET version? I mean I want to know if
          >user is using Windows 2000, XP, Vista and which Service Pack and version
          >(XP Home, XP Pro, Vista Home Basic, Vista Premium, etc.). Is there any
          >easy way to retrive this information?
          >I'm wondering if all modern Windows version (2000, XP, 2003, Vista) has
          >.NET installed by default or do I need to implement such a feature in
          >Win32 instead of .NET?
          >>
          >Thanks,
          >Arek
          >>
          >
          .NET comes with WS2003 (v1.x), Vista (v1.x, v2) (V3 optional feature) and
          WS2008 (v1.x, v2 SP1) (v3 SP1 optional feature).
          v1.x = v1.0 & v1.1
          None come with v3.5.
          Downlevel OSses come without .NET.
          >
          You can't run managed code if .NET is not installed, so there is no
          reliable way to get at this using C# (or other managed code).
          >
          The easiest to get at this info is to run a simple (VB) script like this:
          >
          On Error Resume Next
          ' Get OS Version
          For Each os in GetObject("winm gmts:").Instanc esOf
          ("Win32_Operati ngSystem")
          WScript.Echo "OS = " & os.Caption & " ,Version = " & os.Version & "
          ,Service Pack = " & os.ServicePackM ajorVersion
          Next
          >
          'Get .NET Framework versions
          const HKLM = &H80000002
          Set
          objReg=GetObjec t("winmgmts:{im personationLeve l=impersonate}! \\.\root\defaul t:StdRegProv")
          >
          regPath = "SOFTWARE\Micro soft\.NetFramew ork"
          objReg.EnumKey HKLM, regPath, subKeys
          If Err = 0 Then
          For Each subkey In subKeys
          if(Instr(1, subkey, "v")) Then
          WScript.Echo subkey
          End If
          Next
          Else
          WScript.Echo ".NET not available"
          End if
          >
          Willy.
          >
          >
          Or better, use the .NET setup path in the HKLM hive.

          'file: frameworkver.vb s
          '
          On Error Resume Next

          'Get installed .NET Framework versions
          const HKLM = &H80000002
          const REG_SZ = 1
          const REG_EXPAND_SZ = 2
          const REG_BINARY = 3
          const REG_DWORD = 4
          const REG_MULTI_SZ = 7

          Set registry =
          GetObject("winm gmts:{impersona tionLevel=imper sonate}!\\.\roo t\default:StdRe gProv")

          netRegPath = "SOFTWARE\Micro soft\NET Framework Setup\NDP"
          'frameworkPath
          dim sValue
          registry.EnumKe y HKLM, netRegPath, subKeys
          If Err = 0 Then
          For Each subkey In subKeys
          WScript.Echo subkey
          if(Instr(1, subkey, "v")) Then
          frameworkPath = netRegPath & "\" & subkey
          registry.EnumVa lues HKLM, frameworkPath, valueNames, valueTypes
          For inx = 0 To UBound(valueNam es)
          Select Case valueTypes(inx)
          Case REG_SZ
          registry.GetStr ingValue HKLM, frameworkPath, valueNames(inx) , sValue
          WScript.Echo VbTab & valueNames(inx) &": " & sValue
          Case REG_DWORD
          registry.GetDWO RDValue HKLM, frameworkPath, valueNames(inx) , dValue
          WScript.Echo VbTab & valueNames(inx) &": " & dValue
          End Select
          Next
          End If
          Next
          Else
          WScript.Echo ".NET not installed!?"
          Err.Clear
          End if

          Willy.

          Comment

          Working...