Targeting application to Windows 8 and more


Recently I'm faced one big problem while display my system OS information, while execute command in command prompt it returns different windows version at the same time when I do some code logic using C# it give different Windows version, After seen the result I shocked and try to find the solution how it's possible why it's showing like this. In this article I'm going to explain how to targeting application to specific windows.

Targeting application to Windows:



Recently I'm faced one big problem while display my system OS information, while execute command in command prompt it returns different windows version at the same time when I do some code logic using C# it give different Windows version, After seen the result I shocked and try to find the solution how it's possible why it's showing like this. In this article I'm going to explain how to targeting application to specific windows.

Difference between Command and C# version:



Before going to solution first let us see the problem, how it's reproduced and what are all the steps I done to resolve this.

Execute the command:

First I run the below command using command prompt.

C:\>systeminfo | findstr /B /C:"OS Name" /C:"OS Version"

After execute the above command the output result like below,

OS Name: Microsoft Windows 8.1 Pro
OS Version : 6.3.9600 N/A Build 9600


cmd

Run C# code:

Then after I'm trying to get my system OS information without using command, instead of that directly getting OS information using C# code. I used below code for that,

//Get Operating system information.
OperatingSystem os = Environment.OSVersion;
//Get version information about the os.
Version vs = os.Version;


Using above code, I'm trying to get the current OS based on Windows Version, but the output likes below

C#

Difference between Command result and C# Code:

After execute the above both statements there is difference between windows version generated by command as well as C# code. Using Command the version is "6.3.9600" at the same time using C# code the version is "6.2.9200".

See the below image for your easy understanding,

Capture

How to resolve this problem:



After I Googled and read some posts, one of the post is Microsoft blog there they clearly mentioned that " The OSVersion property reports the same version 6.2.0.0 for both Windows 8 and windows 8.1", now what Is the solution to resolve this, after I read the below MSDN article I got clear picture for resolving this.

Refer below link

https://msdn.microsoft.com/en-us/library/windows/desktop/dn481241(v=vs.85).aspx

In that they are saying that, In order to target windows 8.1 and windows 10 we need to include manifest to the project and add below lines of code in that.



<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on and is
is designed to work with. Uncomment the appropriate elements and Windows will
automatically selected the most compatible environment. -->

<!--Windows Vista-->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />

<!--Windows 7-->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />

<!--Windows 8-->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />

<!--Windows 8.1-->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />

<!--Windows 10-->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />

</application>
</compatibility>



After I include those lines of code in manifest file, for testing I re run my application again, now I got my Windows Version perfectly as expected.

final

Conclusion:

I Hope this article will help you those who are facing the similar problem while they are generating the windows version with different approaches.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: