Original http://www.cnblogs.com/feiyangqingyun/archive/2013/05/29/3106238.html
Previously developed in XP, all recently moved to win7, and foundProgramThere will be a small problem during the operation, that is, when you get whether the system is currently mute or not, it used to run well under XP, but it won't work when it comes to Windows 7. Later I thought of running it as an administrator, but it still won't work, when I was installing some software in win7, I was prompted that the software could not be installed in the program file directory, the solution is to right-click the attribute and select compatible mode to run. Inspired by this, I also right-click to set the compatible mode to run and wipe it. It's okay!
Therefore, you can encapsulate the win7 system and set the registry to the method and call it at startup.
// Make sure to run in compatible mode
If (myhelper. iswindows7)
Myhelper. setruninwinxp (MyApp. apppath + "\ myalarmsystem.exe ");
Encapsulation Method:
# Region Win7 operating system processing (compatible mode) Public Static Bool Iswindows7 { Get { Return (Environment. osversion. Platform = platformid. win32nt) & (environment. osversion. version. Major = 6 ) & (Environment. osversion. version. Minor = 1 );}} Public Static Void Setruninwinxp ( String Exename) {registrykey key = Registry. currentuser. opensubkey (" Software \ Microsoft \ Windows NT \ CurrentVersion \ appcompatflags \ Layers " , True ); // Open Registry subitem If (Key = Null ) // If this item does not exist, this subitem is created. Key = registry. localmachine. createsubkey ( " Software \ Microsoft \ Windows NT \ CurrentVersion \ appcompatflags \ Layers " ); // If this value does not exist, set this value and restart the application. If (Key. getvalue (exename) = Null ) {Key. setvalue (exename, " Winxpsp3 " ); Application. exitthread (); application. Exit (); application. Restart (); system. Diagnostics. process. getcurrentprocess (). Kill ();}} # Endregion
This is a perfect solution ever since!
I used to develop it in XP and recently moved it all to Windows 7. I found that there was a small problem with the program running, that is, when I got the current mute of the system, I used to run well under Windows XP, when I got to win7, I couldn't do it. I thought I could run it as an administrator, but I still couldn't do it. I suddenly thought that there was a compatibility mode. When I installed some software under Windows 7, the system prompts that the program cannot be installed in the program file directory. The solution is to right-click the properties and select compatible mode to run the program. Inspired by this, I can also right-click and set the compatible mode to run the program!
Therefore, you can encapsulate the win7 system and set the registry to the method and call it at startup.
// Make sure to run in compatible mode
If (myhelper. iswindows7)
Myhelper. setruninwinxp (MyApp. apppath + "\ myalarmsystem.exe ");
Encapsulation Method:
# Region Win7 operating system processing (compatible mode) Public Static Bool Iswindows7 { Get { Return (Environment. osversion. Platform = platformid. win32nt) & (environment. osversion. version. Major = 6 ) & (Environment. osversion. version. Minor = 1 );}} Public Static Void Setruninwinxp ( String Exename) {registrykey key = Registry. currentuser. opensubkey ( " Software \ Microsoft \ Windows NT \ CurrentVersion \ appcompatflags \ Layers " , True ); // Open Registry subitem If (Key = Null ) // If this item does not exist, this subitem is created. Key = registry. localmachine. createsubkey ( " Software \ Microsoft \ Windows NT \ CurrentVersion \ appcompatflags \ Layers " ); // If this value does not exist, set this value and restart the application. If (Key. getvalue (exename) = Null ) {Key. setvalue (exename, " Winxpsp3 " ); Application. exitthread (); application. Exit (); application. Restart (); system. Diagnostics. process. getcurrentprocess (). Kill ();}} # Endregion
This is a perfect solution!