locked
Where Settings are saved RRS feed

  • Question

  •   Hello.

      Why when a program is using 1 Setting, when it is published as an executable file, creates a file for default value in the same .exe directory and saves its values to another place in the computer*?? That makes no sense for me, because I think default values should be inside the executable and they should be saved in that file (in the same .exe directory).

      *Where's that place?

      Note: I've also asked this here: https://social.msdn.microsoft.com/Forums/.../what-an-executable-exe-file-contains?...

      Thanks!


    Greetings


    • Edited by Benur21 Friday, July 22, 2016 2:21 PM
    Friday, July 22, 2016 2:21 PM

Answers

  • See the below link:

    http://stackoverflow.com/questions/469742/where-are-user-mode-net-settings-stored

    Given the security of Windows (specifically the Program Files folder) no user settings or data should be saved to an application folder or subfolder. This is old way of doing things and is considered a security risk. In most instances, the data that legacy applications write to the application folder will be written to their virtual store instead.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Marked as answer by Benur21 Saturday, July 23, 2016 1:36 PM
    Friday, July 22, 2016 4:03 PM
  • Settings are either user scoped or application scoped.

    User scoped settings on windows 7 are located in the below location. The second line explains the first line. User scoped settings are for each user that uses the app. Two different users on the same PC may want different settings therefore they will each have their own settings file. The User.Config file is an XML file and looks like the bottom code window.

    I don't know where application scoped settings config file is located for an app. I suspect that would be what the app.config file is for. I've never set an application scoped setting to find out.

    Just because you believe something should be one way doesn't really mean much since things may not be that way. If things are not what you want then figure out your own way of doing things.

    Some people may buy a computer and then think it shouldn't have a keyboard and they should only have to talk to it to get it to do something like on Star Trek. And you probably could do that nowadays with the right capabilities provided to a computer. But just cause somebody thinks that way doesn't really mean anything.

    You can compile an executable with information but the information in the executable can not then be altered and the executable store the altered information within its compile source. Resources in the applications properties window is where you add a resource that gets compiled into the executable. If you want to compile some style of settings information into an app then create a delimited text file such that you can retrieve information from it to provide default settings somehow to controls. However if a user wants different settings then you shouldn't disallow their settings from being saved and automatically used the next time the app runs.

    C:\Users\John\AppData\Local\Test442\Test442.exe_Url_jxg1fra4st2w1r2gxoajhco0f45f2qnl\1.0.0.0\User.Config
    
    SystemRootDirectory:\Users\UserName\AppData\Local\ApplicationName\AppNameFollowedBySomeURL\AppVersionNumber\User.Config

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <configSections>
            <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
                <section name="Test442.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
            </sectionGroup>
        </configSections>
        <userSettings>
            <Test442.My.MySettings>
                <setting name="FileNr" serializeAs="String">
                    <value>4</value>
                </setting>
            </Test442.My.MySettings>
        </userSettings>
    </configuration>


    La vida loca

    • Edited by Mr. Monkeyboy Friday, July 22, 2016 5:14 PM
    • Marked as answer by Benur21 Friday, July 22, 2016 7:01 PM
    Friday, July 22, 2016 5:06 PM

All replies

  • See the below link:

    http://stackoverflow.com/questions/469742/where-are-user-mode-net-settings-stored

    Given the security of Windows (specifically the Program Files folder) no user settings or data should be saved to an application folder or subfolder. This is old way of doing things and is considered a security risk. In most instances, the data that legacy applications write to the application folder will be written to their virtual store instead.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Marked as answer by Benur21 Saturday, July 23, 2016 1:36 PM
    Friday, July 22, 2016 4:03 PM
  • Settings are either user scoped or application scoped.

    User scoped settings on windows 7 are located in the below location. The second line explains the first line. User scoped settings are for each user that uses the app. Two different users on the same PC may want different settings therefore they will each have their own settings file. The User.Config file is an XML file and looks like the bottom code window.

    I don't know where application scoped settings config file is located for an app. I suspect that would be what the app.config file is for. I've never set an application scoped setting to find out.

    Just because you believe something should be one way doesn't really mean much since things may not be that way. If things are not what you want then figure out your own way of doing things.

    Some people may buy a computer and then think it shouldn't have a keyboard and they should only have to talk to it to get it to do something like on Star Trek. And you probably could do that nowadays with the right capabilities provided to a computer. But just cause somebody thinks that way doesn't really mean anything.

    You can compile an executable with information but the information in the executable can not then be altered and the executable store the altered information within its compile source. Resources in the applications properties window is where you add a resource that gets compiled into the executable. If you want to compile some style of settings information into an app then create a delimited text file such that you can retrieve information from it to provide default settings somehow to controls. However if a user wants different settings then you shouldn't disallow their settings from being saved and automatically used the next time the app runs.

    C:\Users\John\AppData\Local\Test442\Test442.exe_Url_jxg1fra4st2w1r2gxoajhco0f45f2qnl\1.0.0.0\User.Config
    
    SystemRootDirectory:\Users\UserName\AppData\Local\ApplicationName\AppNameFollowedBySomeURL\AppVersionNumber\User.Config

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <configSections>
            <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
                <section name="Test442.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
            </sectionGroup>
        </configSections>
        <userSettings>
            <Test442.My.MySettings>
                <setting name="FileNr" serializeAs="String">
                    <value>4</value>
                </setting>
            </Test442.My.MySettings>
        </userSettings>
    </configuration>


    La vida loca

    • Edited by Mr. Monkeyboy Friday, July 22, 2016 5:14 PM
    • Marked as answer by Benur21 Friday, July 22, 2016 7:01 PM
    Friday, July 22, 2016 5:06 PM
  • C:\Users\John\AppData\Local\Test442\Test442.exe_Url_jxg1fra4st2w1r2gxoajhco0f45f2qnl\1.0.0.0\User.Config
    
    SystemRootDirectory:\Users\UserName\AppData\Local\ApplicationName\AppNameFollowedBySomeURL\AppVersionNumber\User.Config

    <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > <section name="Test442.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> </sectionGroup> </configSections> <userSettings> <Test442.My.MySettings> <setting name="FileNr" serializeAs="String"> <value>4</value> </setting> </Test442.My.MySettings> </userSettings> </configuration>

      Thanks I found where the settings are saved.

    Greetings

    Friday, July 22, 2016 7:02 PM
  •   Thanks, and why do it need a file for default setting values close to the .exe? Why do it need a default value? For when there's nothing saved, right? Then I would just write

    If String.IsNullOrWhiteSpace(My.Settings.settingtest) Then
    
      My.Settings.settingtest = 'Default value
    
    End If

     This don't need a file to tell the application what's the default value.. just write it and if you don't write then the application could use an invalid value until some exception happens (something that the programmer needs to fix).

      Also: Why do it makes config files with all that xml and tag things like

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <userSettings>
            <SettingsFileTest.My.MySettings>
                <setting name="SettingTest" serializeAs="String">
                    <value>test1</value>
                </setting>
            </SettingsFileTest.My.MySettings>
        </userSettings>
    </configuration>

    instead of how i would easily save like

    SettingTest=test1
    where the value type is already known on the application (I had no reason to change the value type yet)?

    Thanks A LOT!!!


    • Edited by Benur21 Saturday, July 23, 2016 1:38 PM
    Saturday, July 23, 2016 1:33 PM
  • Thnks, and why do it need a file for default setting values close to the .exe? Why do it need a default value? For when there's nothing saved, right? Then I would just write

    If String.IsNullOrWhiteSpace(My.Settings.settingtest) Then
    
      My.Settings.settingtest = 'Default value
    
    End If

    It needs a default value so it knows what to write to the actual file when it creates that file when the application runs for the first time, or when it needs to recreate it if it gets deleted. With a default value, you don't need to write that code at all, and most defaults aren't nothing or blank.   You would only write that code if the default value was needed to be changed.   In practice, many settings variables never change their values from the default.

      Also: Why do it makes config files with all that xml and tag things like

    XML provides a standardized, formalized way of storing data.  Using XML means that the application does not have to worry about details of structuring that data. The alternative you describe was the way it used to be done.  See: https://en.wikipedia.org/wiki/INI_file

    It worked, but had all sorts of problems.  In particular, it could not cope with things like images, lists, or other objects.

    Saturday, July 23, 2016 10:25 PM