editing resource files

I am using a ResourceManager to retrieve values from a .resource file. I would like to be able to update the values in the file from within the application. Can this be done How

Thanks.



Answer this question

editing resource files

  • Gamb

    If you still want to change resource add runtime, take a look at the ResXResourceWriter if you want to change XML formatted files; otherwise, use the ResourceWriter class to write in binairy format.


  • Ramadan

    So are you saying that resource files should only be used for static / non-changing values

    Since the config files I would have in mind would be very similar to a resource file (ie. containins a list of key value pairs) is there a mechanism / class in place for handling config files as ResourceManager handles resource files


  • Brant E

    Aren't resource files part of the "file system " When you say "file system" are you suggesting something like an XML file that has tags for the fields I am interested in
  • sgudavalli

    I still don't understand why you want to change a resource. Resource must stay static, it only has side effects.

    Why do you want to do this


  • Evan_Chang

    Don't save setting in you own exe! Virus scanners won't love it and will warn all the time and you can't hash you exe and compaire this with a other hash to lookup updates for example.

    Use the registry or file system to save settings.


  • Guy C.

    Ok. That tells me where to place the data, but is there a ResourceManager like class for dealing with config files
  • Chikodef

    Use the Resource editor Lutz Roeder has writen, you can find it here.


  • JLuis

    The problem with a ResourceWriter is that it does not have a method to change the value of a resource entry. It only allows you to "Add" a resource and if that resource already exists it throws an exception. It seems that ResourceWriter is designed to create new resource file instead of editing an existing one.

    Am I incorrect


  • mklee

    There are so much alertnatives with have other roamings, the registery can have Machine roamings, version roamings, user roamings and so does the filesystem when you look at direcoties like Application Data and User Settings. This are good places to store a config file.

    I can't find the article about Winforms, but here is a quote for the Microsoft Direct X Logo:

    3.0 Data and Settings Management: Requirements Summary

    Windows XP provides an infrastructure that supports state separation of user data, user settings, and computer settings. Applications that use this infrastructure correctly offer the following benefits:

    • Applications do not fail when run by Limited Users (non-Administrator), allowing family or friends to share a computer safely and easily.
    • Parents can allow children to use the computer without giving them administrative privileges, which would give the child unrestricted access to modify the computer.
    • Users can back up their individual documents and settings easily without needing to back up application and operating system files.
    • Multiple users can share a single computer, each with their own preferences and settings.
    • Applications are less likely to prevent Fast User Switching from operating correctly and efficiently.

    3.1 Default to the Correct Location for Storing User-Created Data

    If files generated by the application are meant to be viewed and/or altered by the user outside of the application then they must be stored in the My Documents (or descendant) folder and a file association must be made. Do not use hard-coded paths to determine the location:

    • If you are using the Windows Installer, these folders are represented by the System Folder Properties.
    • If you are not using the Windows Installer, the recommended method is to use SHGetFolderPath API to retrieve the string represented by the CSIDL_PERSONAL and CSIDL_COMMON_DOCUMENTS values as determined by whether only this user or all users should access these files.

    Application data, such as application state, temporary files, and so on, must not be stored within My Documents.

    The benefits of using the My Documents folder as the default for data storage are:

    • All users (including those with restricted account types) have write access to this location.
    • Users have one familiar place to organize and store all their data.
    • Data sharing is facilitated between applications because all applications using Common File Open can easily access the My Documents folder.
    • My Documents is an abstracted location and can be redirected to the network transparently by an administrator.
    • My Documents is available on the Start menu.

    3.2 Classify and Store Application Data Correctly

    If files generated by the application are NOT meant to be viewed and/or altered by the user outside of the application then they must be stored appropriately. Do not use hard-coded paths to determine these locations.

    It is recommended to store application data files appropriately as either common or per-user. That is:

    • In a subfolder of either the common application folder (identified by CSIDL_COMMON_APPDATA).
    • In the user profile folders: application data (CSIDL_APPDATA) or local application data (CSIDL_LOCAL_APPDATA).

    Application data, such as application state, temporary files, and so on, must not be stored within My Documents.

    Using the Registry

    Applications may also use the registry to store read/write application data and configuration files.

    • The HKCU registry hive is appropriate for storing small amounts of data (approximately 64K) and for per-user policy settings.
    • Avoid writing to HKLM during runtime, because limited users have read-only access to the entire HKLM tree by default. In addition, HKLM does not support roaming.
    • Larger, file-based data should be placed in the Application Data folder. For example, caches must be stored within the user profile and not in the registry.
    • At installation time, the application must not store more than a total of 128K across HKCU and HKLM.
    • Note that HKEY_CLASSES_ROOT is excluded.

    Classifying and storing application data according to the guidelines in this requirement provides these benefits:

    • It enables multiple family members to share a machine and helps enable Fast User Switching and Limited Users.
    • It enables business-related operations such as roaming, offline storage, and allowing the operating system and its applications to be secured.
    • It ensures a consistent and abstracted location for user data, enforces per-user separation of application data.
    • It is one of the key factors in enabling remote use of the application.

    3.3 Deal Gracefully with Access-Denied Scenarios

    By default on Windows XP, restricted user accounts (for example, Limited Users on Home Edition) cannot write to per-computer locations such as HKLM and the Windows directory. Only applications that classify and store data correctly, as described earlier, will be able to avoid access-denied errors and run successfully in this secure environment.

    There are, however, legitimate scenarios in which access-denied errors are encountered by applications that classify and store data correctly, for example:

    • An unprivileged user may run an application that allows users to modify objects based on permissions. In this case, a user is allowed to modify objects that he or she owns, but not objects owned by the administrator or other users.
    • An unprivileged user may attempt to install the application. If a limited user cannot install the application, the installation must degrade gracefully.

    In these cases, the application must degrade gracefully when the access-denied error is encountered. Graceful handling can be accomplished by displaying an appropriate error message. For example:

    • You must be an administrator to perform this operation
    • You have permissions only to view the properties of this object
    • You must have X privilege to perform this operation

    Test Cases-3.3

    As defined in Designed for Microsoft Windows XP Application Test Framework (see Application Test Framework):

    • TC3.3.2 Does application prevent User1 from modifying user-generated data owned by User2
    • TC3.3.3 Does application prevent User1 from modifying system-wide settings
    • TC3.3.4 Does application's installer either allow User1 to install application or degrade gracefully if the installation fails

    3.4 Support Running as a Limited User

    Applications must not require users to have unrestricted access (for example, Administrator privileges) to run. In other words, the application must function properly in a secure Windows environment. Complying with the previous requirements in this section will help to ensure that the application meets this requirement.

    An application that does not install (that is: executes without installing any components) must still support use by a Limited User.

    A secure Windows environment is defined as the environment exposed to a Limited (non-Administrator) user by default on a clean-installed NTFS system. In this environment, users can write only to these specific locations on a local machine:

    • Their own portions of the registry (HKEY_CURRENT_USER)
    • Their own user profile directories (CSIDL_PROFILE)
    • A Shared Documents location (CSIDL_COMMON_DOCUMENTS)
    • A folder that the user creates from the system drive root

    However, applications defaulting to use of these folders do not comply with the other requirements of this section.

    Users can also write to subkeys and subdirectories of these locations. For example, users can write to CSIDL_PERSONAL (My Documents) because it is a subdirectory of CSIDL_PROFILE. Users have read-only access to the rest of the system.

    When the major features of the application can be successfully run by a non-privileged user, minor features are allowed to fail gracefully. These minor features must not be installed by any default mechanism (for example, a minimal or typical install) other than a complete install and must not be considered important for the operation of the program. Examples of such minor features include components necessary to support legacy file formats.



  • ippy04

    I mean a XML file, Text File, BLOB file, Serialized Object File, a external resource file, but not you own exe.


  • KenBaker

    I am using a resource file and a ResourceManager to maintain configuration information for my GUI. The resource file includes default data values, time outs, etc. I used a resource editor to create the file. Within my application, when the user makes a selection that changes one of the values that was retrieved from the resource file, I would like to update the resource file so that the next time my application starts it will use the most recent user selection as the default value.
  • Devcom

    BioGeek wrote:

    The problem with a ResourceWriter is that it does not have a method to change the value of a resource entry. It only allows you to "Add" a resource and if that resource already exists it throws an exception. It seems that ResourceWriter is designed to create new resource file instead of editing an existing one.

    Am I incorrect

    You normally never change something but allways, read it in memory, edit it and then flush (override) it to the file again.

    So you have to build your own logic.

    BioGeek wrote:
    I am using a resource file and a ResourceManager to maintain configuration information for my GUI. The resource file includes default data values, time outs, etc. I used a resource editor to create the file. Within my application, when the user makes a selection that changes one of the values that was retrieved from the resource file, I would like to update the resource file so that the next time my application starts it will use the most recent user selection as the default value.

    Normally this kind of settings belong in a config file or registery.



  • KingMax

    Right. What I am trying to do is update an existing external resource file. I am using a ResourceManager to read the values from the resource file but don't know how to change the values within that file.

    I know how to use a seperate application to create / edit resouce files. I am looking for a method of updating these files from within my application so I can save user selections.


  • gareth andrew lewis

    That appears to be a resource editor application. I am looking for a way to update a resource file from within my application so that I can save user selections. Is this not an appropriate use of resource files Should I be using some other mechanism like the registry
  • editing resource files