Results 1 to 4 of 4

Thread: [RESOLVED] Checking the os

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,394

    Resolved [RESOLVED] Checking the os

    I'm building a website blocker, and it reads/writes the HOST file. I have it built for windows xp. I'm wanting to check the OS the person's using so that it can run the write code properly(b/c each OS the host file is in a different location). I was thinking about using
    Code:
    Environment.OSVersion.ToString()
    in an if statement sorta like this:
    Code:
    If Environment.OSVersion.ToString() = "OS" Then
                'the code that works for the OS in the = ""
            End If
    my problem is that I don't know how to set my .ToString() = "" any thoughts?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  2. #2
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Checking the os

    Use:

    Environment.OSVersion.Version.ToString

    That will give you Version.Subversion.Build.SomethingIDon'tKnow

    But for XP, you'll get 5.1.xxxx.xxxx
    for Vista you should get 6.0.xxxx.xxxx
    for windows 7 you should get 6.1.xxxx.xxxx

    Next you can just get the first three digits and compare then to a list:

    vb.net Code:
    1. Dim Version as String = Environment.OSVersion.Version.Tostring
    2. Dim ShortVersion as String = Version.SubString(0, 3)
    3. Dim VersionName as String
    4.  
    5. Select Case ShortVersion
    6.     Case "5.0"
    7.         VersionName = "Windows 2000"
    8.         'Do Other Stuff Here
    9.     Case "5.1"
    10.         VersionName = "Windows XP"
    11.     Case "6.0"
    12.         VersionName = "Windows Vista"
    13.     Case "6.1"
    14.         VersionName = "Windows 7"
    15. End Select

    A full list of windows versions can be found here:
    http://www.msigeek.com/442/windows-os-version-numbers

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  3. #3
    Member cowboycoding's Avatar
    Join Date
    Jun 2011
    Posts
    34

    Re: Checking the os

    Cool!
    http://openexpressions.sourceforge.net
    http://www.cowboycomputers.TK
    I appreciate helping when my helping is appreciated.
    I always appreciate your help as well.

  4. #4

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,394

    Re: Checking the os

    Dude, I'm sorry when I went to look up where the host file is, it was the same in xp as it is in vista in 7. Thanks for the help though.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width