My program need to be run in XP compatible mode. I need A way to check if is running in XP compatible mode. If not tell the user to run it in compatible mode. I have searched but found no answer. I have tried this this.Text = System.Environment.OSVersion.VersionString;
but it returns Microsoft Windows NT 6.1.7601 Service Pack 1 not the emulated XP.
(Edit)
After more searches and dll imports nothing worked right it would always returns Microsoft Windows NT 6.1.7601 Service Pack 1. So I created A console loaded to handle registry then run my program.
using System;
using System.Security.Permissions;
using Microsoft.Win32;
[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, ViewAndModify = "HKEY_CURRENT_USER")]
class RegKey
{
static void Main()
{
int Major = Environment.OSVersion.Version.Major;
int Minor = Environment.OSVersion.Version.Minor;
if (Major == 5 && Minor == 1)
{
System.Diagnostics.Process.Start(System.IO.Directory.GetCurrentDirectory() + "\\MyApp.exe");
}
else if (Major > 5)
{
if (System.IO.File.Exists(System.IO.Directory.GetCurrentDirectory() + "\\MyApp.exe"))
{
RegistryKey Rkey = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers");
//Creates Name And Value
Rkey.SetValue(System.IO.Directory.GetCurrentDirectory() + "\\MyApp.exe", "WINXPSP3");
//Starts App.
System.Diagnostics.Process.Start(System.IO.Directory.GetCurrentDirectory() + "\\MyApp.exe", "Load");
//Waites 500 milliseconds so my program can get the registry info
//(Not needed any more)
//System.Threading.Thread.Sleep(500);
//Deletes Name And Value
//(Handled by MyApp.exe to increase load time)
//Rkey.DeleteValue(System.IO.Directory.GetCurrentDirectory() + "\\MyApp.exe");
}
else
{
Console.WriteLine("File Not Found!!!");
Console.WriteLine("( MyApp.exe ) Must Be In Same Directory As The Loader.exe.");
Console.ReadLine();
}
}
}
}
I handle registry in this way so my program can be portable and prevent registry entries that point to nothing. I am shore that they are better ways to get the results I was looking for.
(Edit 2)
After more checking I only have to run XP compatible mode on 64 bit systems. 32 bit systems do not need to run in XP compatible mode. I compiled my app with platform x86. So it must has something to do with the way 64 bit systems read the registry.