Default Configuration Information read/write for UAC form applications

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.