Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to check operating system in c#..?

how to check operating system in c#..?

Scheduled Pinned Locked Moved C#
csharpdotnettestingbeta-testingtutorial
13 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NetMan2012
    wrote on last edited by
    #1

    hello, I have developed an desktop application in C#.NET Framework(3.5). My client is using the application on different OS like(Xp, Seven, Vista). I have developed the app and did over all testing on XP. Now some features of app are not working on Seven and Vista for which i need to do some extra work. Is there any piece of code in c# by which i can check which operating system is installed and them my app according to that OS. Thanks in Advance, Asfand

    T P J D L 6 Replies Last reply
    0
    • N NetMan2012

      hello, I have developed an desktop application in C#.NET Framework(3.5). My client is using the application on different OS like(Xp, Seven, Vista). I have developed the app and did over all testing on XP. Now some features of app are not working on Seven and Vista for which i need to do some extra work. Is there any piece of code in c# by which i can check which operating system is installed and them my app according to that OS. Thanks in Advance, Asfand

      T Offline
      T Offline
      The Man from U N C L E
      wrote on last edited by
      #2

      Take a look at System.Environment.OSVersion. System.Environment.OSVersion.Version.Major will return one of the following: 4 = Windows 95, 98, ME or NT 4.0 5 = Windows 2000, XP or 2003 Server 6 = Vista, Windows 7 or 2008 Server Then query the System.Environment.OSVersion.Version.Minor See the following for detailed break down of version numbers of Windows OS. Life Rocks 2.0[^] MSDN[^]

      If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

      1 Reply Last reply
      0
      • N NetMan2012

        hello, I have developed an desktop application in C#.NET Framework(3.5). My client is using the application on different OS like(Xp, Seven, Vista). I have developed the app and did over all testing on XP. Now some features of app are not working on Seven and Vista for which i need to do some extra work. Is there any piece of code in c# by which i can check which operating system is installed and them my app according to that OS. Thanks in Advance, Asfand

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        You can use Environment.OSVersion to get the OperatingSystem back. From this you can determine whether or not it's a Vista+ system with a simple check:

        public bool IsVistaOrHigher
        {
        get { return OSVersion.Version.Major >= 6);
        }

        If the application can run in compatibility mode though, this is potentially unreliable. Another way to do this is to use a method that only exists in a Vista (or greater) OS to determine it. Here's another example that demonstrates it:

        public bool IsVistaOrHigher
        {
        get
        {
        return IsVistaOrHigherHelper();
        }
        }

        private bool IsVistaOrHigherHelper()
        {
        IntPtr hModule = LoadLibrary("Kernel32.dll");
        if (hModule != null)
        {
        IntPtr proc = GetProcAddress(hModule, "MoveFileTransactedA");
        return proc.ToInt32() != 0;
        }
        return false;
        }

        I used part of the Kernel Transaction Manager (KTM) to do this - you can use any new API to accomplish the same.

        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

        As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

        My blog | My articles | MoXAML PowerToys | Onyx

        1 Reply Last reply
        0
        • N NetMan2012

          hello, I have developed an desktop application in C#.NET Framework(3.5). My client is using the application on different OS like(Xp, Seven, Vista). I have developed the app and did over all testing on XP. Now some features of app are not working on Seven and Vista for which i need to do some extra work. Is there any piece of code in c# by which i can check which operating system is installed and them my app according to that OS. Thanks in Advance, Asfand

          J Offline
          J Offline
          Johnny J
          wrote on last edited by
          #4

          Try using the CodeProject search box. Then you might have gotten this link: Getting operating system version info - Even for Windows 7![^]

          1 Reply Last reply
          0
          • N NetMan2012

            hello, I have developed an desktop application in C#.NET Framework(3.5). My client is using the application on different OS like(Xp, Seven, Vista). I have developed the app and did over all testing on XP. Now some features of app are not working on Seven and Vista for which i need to do some extra work. Is there any piece of code in c# by which i can check which operating system is installed and them my app according to that OS. Thanks in Advance, Asfand

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            What you change depends on what your app is doing. If properly written, you shouldn't need to check the O/S version to modify the apps behavior.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008
            But no longer in 2009...

            1 Reply Last reply
            0
            • N NetMan2012

              hello, I have developed an desktop application in C#.NET Framework(3.5). My client is using the application on different OS like(Xp, Seven, Vista). I have developed the app and did over all testing on XP. Now some features of app are not working on Seven and Vista for which i need to do some extra work. Is there any piece of code in c# by which i can check which operating system is installed and them my app according to that OS. Thanks in Advance, Asfand

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Dave is absolutely right. First make sure you have to know which OS version your app is running on. Oftentimes people think they need to know while they really don't. A typical example would be the use of special folders, such as "My Documents", which seems to be located at different locations on different Windows versions. However there is a simple way to get that path without worrying about the OS version at all; that too is inside the Environment class. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read formatted code with indentation, so please use PRE tags for code snippets.


              I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


              P 1 Reply Last reply
              0
              • L Luc Pattyn

                Dave is absolutely right. First make sure you have to know which OS version your app is running on. Oftentimes people think they need to know while they really don't. A typical example would be the use of special folders, such as "My Documents", which seems to be located at different locations on different Windows versions. However there is a simple way to get that path without worrying about the OS version at all; that too is inside the Environment class. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                I only read formatted code with indentation, so please use PRE tags for code snippets.


                I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                While this is good advice, there are certain occassions where this check does count. Suppose you want to use the Kernel Transaction Manager, for instance. If your application runs on Vista+ it will work, but it won't on XP. You should be able to provide a graceful degrade mechanism at this point.

                "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                My blog | My articles | MoXAML PowerToys | Onyx

                L D 2 Replies Last reply
                0
                • P Pete OHanlon

                  While this is good advice, there are certain occassions where this check does count. Suppose you want to use the Kernel Transaction Manager, for instance. If your application runs on Vista+ it will work, but it won't on XP. You should be able to provide a graceful degrade mechanism at this point.

                  "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                  As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                  My blog | My articles | MoXAML PowerToys | Onyx

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  I fully agree, feature detection is part of, well, decent behavior. But it is Microsoft's duty to hide those tiny changes that don't bring much, and make things needlessly hard, and sometimes they do provide a solution, with people not always aware of it. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  I only read formatted code with indentation, so please use PRE tags for code snippets.


                  I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                  P 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    I fully agree, feature detection is part of, well, decent behavior. But it is Microsoft's duty to hide those tiny changes that don't bring much, and make things needlessly hard, and sometimes they do provide a solution, with people not always aware of it. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                    I only read formatted code with indentation, so please use PRE tags for code snippets.


                    I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #9

                    Luc Pattyn wrote:

                    make things needlessly hard

                    :laugh: A perfect description.

                    "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                    As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                    My blog | My articles | MoXAML PowerToys | Onyx

                    1 Reply Last reply
                    0
                    • N NetMan2012

                      hello, I have developed an desktop application in C#.NET Framework(3.5). My client is using the application on different OS like(Xp, Seven, Vista). I have developed the app and did over all testing on XP. Now some features of app are not working on Seven and Vista for which i need to do some extra work. Is there any piece of code in c# by which i can check which operating system is installed and them my app according to that OS. Thanks in Advance, Asfand

                      C Offline
                      C Offline
                      canangirgin
                      wrote on last edited by
                      #10

                      I think this code help you. RegistryKey KEY = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"); string version= KEY.GetValue("ProductName").ToString();

                      1 Reply Last reply
                      0
                      • P Pete OHanlon

                        While this is good advice, there are certain occassions where this check does count. Suppose you want to use the Kernel Transaction Manager, for instance. If your application runs on Vista+ it will work, but it won't on XP. You should be able to provide a graceful degrade mechanism at this point.

                        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                        As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                        My blog | My articles | MoXAML PowerToys | Onyx

                        D Offline
                        D Offline
                        Dave Kreskowiak
                        wrote on last edited by
                        #11

                        Very true, but I don't think the OP is using anything platform specific.

                        A guide to posting questions on CodeProject[^]
                        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                             2006, 2007, 2008
                        But no longer in 2009...

                        J 1 Reply Last reply
                        0
                        • D Dave Kreskowiak

                          Very true, but I don't think the OP is using anything platform specific.

                          A guide to posting questions on CodeProject[^]
                          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                               2006, 2007, 2008
                          But no longer in 2009...

                          J Offline
                          J Offline
                          Johnny J
                          wrote on last edited by
                          #12

                          Why do you make that assumption? The OP has not posted anything about that...

                          D 1 Reply Last reply
                          0
                          • J Johnny J

                            Why do you make that assumption? The OP has not posted anything about that...

                            D Offline
                            D Offline
                            Dave Kreskowiak
                            wrote on last edited by
                            #13

                            Call it an "educated guess".

                            A guide to posting questions on CodeProject[^]
                            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                                 2006, 2007, 2008
                            But no longer in 2009...

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups