473,411 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Check if SP2 of windows is installed

Hello

How can I check what is the Windows version and if it is Windows XP, is SP2
of Windows XP installed?

Regards
Hamed
May 22 '06 #1
3 4608
Hi Hamed,
How can I check what is the Windows version and if it is Windows XP, is
SP2 of Windows XP installed?


To do this, you would use the System.Environment class and it's OSVersion
property. Assuming you are using .NET 2.0, here's the C# code you need:

------------------------
OperatingSystem os = System.Environment.OSVersion;
if ((os.Platform == PlatformID.Win32NT) &&
(os.Version.Major == 5) &&
(os.Version.Minor == 1))
{
// this is Windows NT 5.1, or Windows XP
string sp = os.ServicePack;
if (sp == "Service Pack 2")
{
MessageBox.Show("This is Windows XP with SP2!");
}
}
------------------------

Warning: This kind of code is bad code. You should never hardcode your
application so that it only works with certain operating system version or
service pack. For example, Windows Vista is soon here, or there might be
Windows XP SP3. Your application must run under Vista and other future
operating systems.

Hope this helps!

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/
May 22 '06 #2
Thanks Jani for your help.

Regards
"Jani Järvinen [MVP]" <ja***@removethis.dystopia.fi> wrote in message
news:uS**************@TK2MSFTNGP03.phx.gbl...
Hi Hamed,
How can I check what is the Windows version and if it is Windows XP, is
SP2 of Windows XP installed?


To do this, you would use the System.Environment class and it's OSVersion
property. Assuming you are using .NET 2.0, here's the C# code you need:

------------------------
OperatingSystem os = System.Environment.OSVersion;
if ((os.Platform == PlatformID.Win32NT) &&
(os.Version.Major == 5) &&
(os.Version.Minor == 1))
{
// this is Windows NT 5.1, or Windows XP
string sp = os.ServicePack;
if (sp == "Service Pack 2")
{
MessageBox.Show("This is Windows XP with SP2!");
}
}
------------------------

Warning: This kind of code is bad code. You should never hardcode your
application so that it only works with certain operating system version or
service pack. For example, Windows Vista is soon here, or there might be
Windows XP SP3. Your application must run under Vista and other future
operating systems.

Hope this helps!

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/

May 22 '06 #3
What is the solution if I use .NET Framework 1.1.4?
"Jani Järvinen [MVP]" <ja***@removethis.dystopia.fi> wrote in message
news:uS**************@TK2MSFTNGP03.phx.gbl...
Hi Hamed,
How can I check what is the Windows version and if it is Windows XP, is
SP2 of Windows XP installed?


To do this, you would use the System.Environment class and it's OSVersion
property. Assuming you are using .NET 2.0, here's the C# code you need:

------------------------
OperatingSystem os = System.Environment.OSVersion;
if ((os.Platform == PlatformID.Win32NT) &&
(os.Version.Major == 5) &&
(os.Version.Minor == 1))
{
// this is Windows NT 5.1, or Windows XP
string sp = os.ServicePack;
if (sp == "Service Pack 2")
{
MessageBox.Show("This is Windows XP with SP2!");
}
}
------------------------

Warning: This kind of code is bad code. You should never hardcode your
application so that it only works with certain operating system version or
service pack. For example, Windows Vista is soon here, or there might be
Windows XP SP3. Your application must run under Vista and other future
operating systems.

Hope this helps!

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/

May 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
by: deko | last post by:
I'm trying to create an MSI in VS.NET that will check for installed Office System components - so my MDE will only install if requirements are met. I'm thinking about using VBScript to inspect...
2
by: Jak Sparrow | last post by:
What are some good ways to programmatically check for software already installed on a computer? For example, to check a version of Internet Explorer, a program can check the registry for the...
1
by: James Tsao | last post by:
is it possible to see whether or not a program is installed on a machine? for example, i'd like to check if winzip is installed and if it is installed, the location of the executable. thanks. ...
5
by: zimmy | last post by:
Hi, Is it possible to check whether ASP.NET is installed on a machine, within a program that I'm writing in C#? And if it's installed, can I check if it is enabled? How? Thanks
8
by: typingcat | last post by:
Microsoft Internet Explorer sends a user agent string contains .NET Framework version if it is installed. But not all the users use MSIE. Some people use FireFox or Opera. Is there any way to check...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
10
by: Dieter Pelz | last post by:
Hallo, what is the best way to check the installation of mfc80 and vcrt sidebyside assemblies? Best Regards, Dieter Pelz
0
by: Ralf Abramowitsch | last post by:
Hi, I'm writing a trouble shooting utility that checks my assembly references. It creates a report for the support. Now I want to add some routines to check for installed runtimes. Ok, the...
12
by: Shadlan | last post by:
Hi. I need to know if a service is running on my server. Is there any PHP instruction that I can use to do this?
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.