Results 1 to 14 of 14

Thread: Va 2017 change exe. Config

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    10

    Va 2017 change exe. Config

    Hi,
    I need modify file exe. Config there is a way without use XML class.
    I try to use my.Setting.Save but it doesn't modify file..
    Could you help me?
    Thanks

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Va 2017 change exe. Config

    The config file stored with the executable file is for the default settings, and is not supposed to change.

    When you change settings within your program (and use My.Settings.Save etc) they are stored to the users copy of the config file, which will be used next time the user runs the program.

    If you are running your application in Visual Studio then it might not seem like the settings are saved, but that is because you are actually running a different program each time you re-compile (such as after making any code changes). If you run the program in Visual Studio and it saves settings, then close the program and re-run it (without making any changes to code etc) then you should see that the settings were saved.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Va 2017 change exe. Config

    You can't modify anything in the primary config file using My.Settings. Settings can be either Application- or User-scoped. Application-scoped settings are stored in the primary config file only and are read-only via My.Settings. User-scoped settings have their default value stored in the primary config file and their current value stored in the user config file, meaning that each Windows user that runs the app has their own value. Modifying and saving settings can only affect User-scoped settings and can only save to the user config file.

    What exactly are you trying to modify? If it's User-scoped settings then I have to ask why, given that the whole idea is that each user has their own value in their own config file. If it's anything else then there is a way, but you'll need to be logged into Windows as an administrator to do it if your app is installed under Program Files. To learn how to do that, follow the CodeBank link in my signature below and check out my thread on Protected Configuration. That thread is intended to demonstrate encrypting config files but you can just ignore that part. Apart from the encryption, it shows how to make changes to the <appSettings> and <connectionStrings> sections, but you can access any section in a similar manner.
    Last edited by jmcilhinney; Dec 18th, 2017 at 09:28 PM. Reason: Fixed spelling mistake ("won" should have been "own").

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Va 2017 change exe. Config

    Further to what si said, it's also worth noting that the App.config file in your project is copied and renamed when you build, so even if you do make changes to the primary config file at run time, those changes may still be lost the next time you build, depending on your project settings.

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    10

    Re: Va 2017 change exe. Config

    My target is,
    Modify or save a copy of config.Exe programmatically for example i have a collettiction setting but i don't want change manual i need add string from a code becouse the string always change

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    10

    Re: Va 2017 change exe. Config

    For ne should be enough modify config and save to some folder.. Example c:temp, let me known when i do save setting where it stored?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Va 2017 change exe. Config

    I still don't see why you aren't just using a User-scoped setting.

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    10

    Re: Va 2017 change exe. Config

    What do you suggest me?
    I can use application setting for me its indifferent.
    My target is modify file config by a program without use XML class

  9. #9

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    10

    Re: Va 2017 change exe. Config

    this my example:
    <setting name="filetoanalize" serializeAs="Xml">
    <value>
    <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <string>\newpos61\bin;\newpos61\bin;;</string>
    <string>\newpos61\Posdata;\newpos61\Posdata;.xml;</string>
    <string>\newpos61\Posdata\images;\newpos61\Posdata\images;;</string>
    <string>\newpos61\Posdata\NPS;\newpos61\Posdata\NPS;;</string>
    <string>\newpos61\Posdata\i18n;\newpos61\Posdata\i18n;;</string>
    </ArrayOfString>
    </value>


    I have to programmatically add string this program, it's console program and should be run on multiple device and file to analyze must change time after time..
    So my target is first time i lunch console and modify config with a program after modify with add new file to check i copy config to all computer and run on it...

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Va 2017 change exe. Config

    Quote Originally Posted by termi_80 View Post
    I can use application setting for me its indifferent.
    And yet you refuse to explain why.
    Quote Originally Posted by termi_80 View Post
    What do you suggest me?
    ...
    My target is modify file config by a program without use XML class
    I've already made my suggestion. If you ask for help and then ignore it when it's provided then that's on you.

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Va 2017 change exe. Config

    Quote Originally Posted by termi_80 View Post
    this my example:
    <setting name="filetoanalize" serializeAs="Xml">
    <value>
    <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <string>\newpos61\bin;\newpos61\bin;;</string>
    <string>\newpos61\Posdata;\newpos61\Posdata;.xml;</string>
    <string>\newpos61\Posdata\images;\newpos61\Posdata\images;;</string>
    <string>\newpos61\Posdata\NPS;\newpos61\Posdata\NPS;;</string>
    <string>\newpos61\Posdata\i18n;\newpos61\Posdata\i18n;;</string>
    </ArrayOfString>
    </value>


    I have to programmatically add string this program, it's console program and should be run on multiple device and file to analyze must change time after time..
    So my target is first time i lunch console and modify config with a program after modify with add new file to check i copy config to all computer and run on it...
    And why exactly can't you use a User-scoped setting and simply add an item to the StringCollection in code?

  12. #12

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    10

    Re: Va 2017 change exe. Config

    i try to do this but the config.exe doesn't change....
    My.Settings.filetoanalize.Add("prova")
    My.Settings.Save()

    I don't understand where i wrong..
    Last edited by termi_80; Dec 18th, 2017 at 07:45 PM.

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Va 2017 change exe. Config

    Quote Originally Posted by termi_80 View Post
    i try to do this but the config.exe doesn't change....
    My.Settings.filetoanalize.Add("prova")
    My.Settings.Save()

    I don't understand where i wrong..
    I already explained that in post #3. One thing that really bugs me is when people ask for help and then ignore it when it's provided. I'm done here.

  14. #14

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    10

    Re: Va 2017 change exe. Config

    Now i read better your post.. Thanks for the Patience..

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width