UAC is the security foundation of Vista and Win7.
When UAC is enabled, the default configuration information of the form application is read and written, which will cause some errors in the Program Files folder.
Many of my friends have studied how to solve this problem by improving application permissions and requiring users to use software as administrators.
Privilege Escalation to avoid UAC control. This solution is not appropriate.
After several days of research, I switched to the first lap and finally solved the problem. In the middle of the night, I am worried about the solution thoroughly. I hope to solve the problem perfectly.
Bytes -----------------------------------------------------------------------------------------
Code
Public Constructor ()
{
ExeConfigurationFileMap tmp = new ExeConfigurationFileMap ();
Tmp. ExeConfigFilename = ConfigerFile ();
ShiQiangConfiger = ConfigurationManager. OpenMappedExeConfiguration (tmp, ConfigurationUserLevel. None );
}
//-------------------------------------------------------------------//
Private string ConfigerFile ()
{
String rtnValue = string. Empty;
Int targetIndex = Application. ExecutablePath. LastIndexOf (@"\");
If (targetIndex> = 0)
{
If (! System. IO. Directory. Exists (Application. CommonAppDataPath ))
{
System. IO. Directory. CreateDirectory (Application. CommonAppDataPath );
}
RtnValue = System. IO. Path. Combine (Application. CommonAppDataPath, Application. ExecutablePath. Substring (targetIndex + 1) + ". Config ");
If (! System. IO. File. Exists (rtnValue ))
{
// If no file exists, copy app. config and create a new one at CommonAppDataPath.
System. Configuration. Configuration tmp = ConfigurationManager. OpenExeConfiguration (ConfigurationUserLevel. None );
Tmp. SaveAs (rtnValue );
}
}
Return rtnValue;
}
Private System. Configuration. Configuration myConfiguration;
The following uses myConfiguration to perform common configuration file operations.
Original article: http://www.cnblogs.com/sasbya/archive/2010/05/05/1727632.html