how to check operating system in c#..?
-
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
-
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
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 theSystem.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]
-
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
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.
-
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
-
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
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... -
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
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).
-
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).
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.
-
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.
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).
-
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).
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.
-
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
I think this code help you. RegistryKey KEY = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"); string version= KEY.GetValue("ProductName").ToString();
-
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.
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... -
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... -
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...