1
管理者アカウントで作成されたアセンブリ構成ファイル(Program.config)。ユーザーアカウント(管理者ではない)に切り替えると、このファイルに構成セクションを書き込むことができません。具体的には、コードは次のようになります。アセンブリ構成ファイルへのアクセス
//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
どのアカウントでも設定を読み書きするにはどのような方法が最適ですか?
それは(Properties.Settings.Default.SomeSetting)が動作しません。一方のアカウントの下に書かれた値は、別のアカウントの下ではアクセスできない。これらはユーザースコープの設定ですが、私は別のアカウントで同じ値を読み書きする必要があります。 – R0nin
理由を説明してください。正しい方法を提案することができます。 –