Thread: Program to apply windows registry settings

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    9

    Program to apply windows registry settings

    Hello,

    I was trying to think about if it would be possible to create a text file that could be in a directory and create a program that loops through each line in the text file to assign values to variables and apply registry settings. The text file could have on each line a registry setting. The purpose of the text file would be so that it could be updated frequently without re-engineering any code.

    Fordy wrote code to apply registry settings, but I was wondering if something could be done a bit differently. I dont want to be notified whether or not each individual registry setting was applied successfully or not, unless it was written into an output file or log. Here is a link to Fordy's post. I dont want to paste the code directly into this post because I want to make sure Fordy gets all of the credit for his code.

    Editing Windows Registry in C?

    So, would it be possible to maintain a text file or even and excel spreadsheet, so that the hive, key, type, and values could be assigned to the variables in a loop that applies each registry key. Does anyone know how this could happen? I am interested, so any thoughts would be appreciated.

    Thanks,
    John

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    This is a windows programming question, not a C question.

    It's not all that hard. Just define a means of representing the registry keys and values in a consistent format. When reading the files, call windows registry functions (CreateRegKeyEx(), etc) as required. The main complexity is that registry keys are hierarchical, and that both your file format and code need to accommodate that. And of course the need for error checking.

    You are aware that regedit is able to import and export registry settings .... and that such imported and exported files are text?
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    9
    Im interested in doing over 100 registry key creations or changes. I know that this can be done with a batch file while using REG ADD commands, but I thought it would be easier to have a list that I maintained as new requirements or changes came about, and just have a loop make all of the changes. The thing that I am not familiar with is how C can assign a value from a location in an external file (such as an excel spreadsheet) to a variable.

    In terms of importing and exporting registry settings, can you import without deleting other keys in hives, or does its simply create the non-existent keys?

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by john3j View Post
    The thing that I am not familiar with is how C can assign a value from a location in an external file (such as an excel spreadsheet) to a variable.
    I hinted at that, albeit rather indirectly, in my last post. Read data from file in some form. Then call CreateRegKeyEX() and other registry functions to make the changes specified. Repeat as needed/

    It's not magical. There needs to be code somewhere to read the file and call various functions to make the actual changes in the registry. Such code is how regedit is implemented. You can also write such code for specific purposes.
    Quote Originally Posted by john3j View Post
    In terms of importing and exporting registry settings, can you import without deleting other keys in hives, or does its simply create the non-existent keys?
    Yes, it is possible to create new keys without affecting unrelated keys. In fact, windows would be pretty unstable if that was not possible.

    There are functions to check whether a registry key exists. That means it is possible to check if a key exists before attempting to create one or modify it.

    You need to read up on the various functions (eg through MSDN) that affect the registry. There is a whole family of functions that either read, modify, create, or delete registry keys. Using them in concert, it is possible to do almost anything you can envisage with the registry.


    And, no, I'm not going to spoonfeed you with sample code. You will learn more by going through the process of designing and implementing a solution for yourself.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    Registered User
    Join Date
    Sep 2012
    Posts
    9
    Thank you for your input! It sounds like creating a .reg file while compiling all of the different settings would be easier than writing the code and maintaining a seperate file as well. I didn't expect anyone to spoon feed me code, I was just trying to collaborate on the best way to achieve a goal at work. Thanks again!

  6. #6
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Quote Originally Posted by john3j View Post
    Im interested in doing over 100 registry key creations or changes. I know that this can be done with a batch file while using REG ADD commands, but I thought it would be easier to have a list that I maintained as new requirements or changes came about, and just have a loop make all of the changes. The thing that I am not familiar with is how C can assign a value from a location in an external file (such as an excel spreadsheet) to a variable.
    Batch files can loop over files, loop over lines in files, and seperate lines in files into tokens. Type 'for /?' into a command prompt to find out how. If you know VBScript or Javascript, you can do your parsing and/or registry manipulation in those, since Windows has command line parsers for them.You'd have to export the Excel file as a CSV file or some other delimited format though, looping over an xls file as is takes a lot of scaffold code.

    Heck, you could even do some VBA and launch reg.exe from a macro without even having to leave excel.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Apply style to multiple windows
    By gaurav_13191 in forum Windows Programming
    Replies: 5
    Last Post: 07-07-2011, 11:59 PM
  2. Code Blocks vs Windows settings?
    By LeonK in forum C++ Programming
    Replies: 2
    Last Post: 06-20-2011, 06:16 AM
  3. Application fails to load settings only at windows startup
    By DanFraser in forum C# Programming
    Replies: 3
    Last Post: 09-27-2009, 11:15 AM
  4. Windows explorer folder view settings
    By anonytmouse in forum Tech Board
    Replies: 1
    Last Post: 10-06-2003, 02:59 AM
  5. Windows Registry
    By Nor in forum Windows Programming
    Replies: 1
    Last Post: 02-15-2002, 03:19 AM