开发者

access to assembly configuration file

开发者 https://www.devze.com 2023-02-17 09:32 出处:网络
Assembly configuration file (Program.config) created under administrator account. When I switch to user account (not administrator), I cannot write configuration开发者_如何学Python section to this fil

Assembly configuration file (Program.config) created under administrator account. When I switch to user account (not administrator), I cannot write configuration开发者_如何学Python section to this file. Specifically, code looks like this:

//creating section (and file) with administrator access
UserInfoConfigurationSection user_conf = new UserInfoConfigurationSection();
Configuration conf = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
conf.Sections.Add("userInfo", user_conf);
conf.Save(ConfigurationSaveMode.Full);


//trying to write to section under user account
Configuration conf = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
UserInfoConfigurationSection user_conf = (UserInfoConfigurationSection)conf.Sections["userInfo"];
user_conf.SerialKey = textBoxSerial.Text;
user_conf.UserCompany = textBoxCompany.Text;
user_conf.UserName = textBoxUser.Text;
conf.Save(ConfigurationSaveMode.Full);//getting exception

What is the best option to write and read settings under any account?


Use the right tool for the job and create the settings you want to be changed at runtime with the user scope: http://msdn.microsoft.com/en-us/library/aa730869%28v=vs.80%29.aspx#settingscs_topic2

0

精彩评论

暂无评论...
验证码 换一张
取 消