Search code examples
c#winformsregistryini

Should I use ini or registry to store parameters for application in C# for Windows 7


I'm writing a Windows application in C#.
Its an application that when called outputs data to a printer and com port. It has to be invisible to the user, so I have a separate application to set up the printer and com port parameters that the application reads every time it is started. The application starts, runs for a couple of seconds and then closes, until it is executed again, which will haven periodically every few minutes. So, unless I hard code the printer and com port settings, I guess I need to have them read every time the application is started.

So is it faster to read from, an ini, XML, or registry/local machine? Speed is my main deciding factor.

Is there any other way to the variables between executions? In Linux i might use environment variables, is that a feasible option in windows? Thanks


Solution

  • How about using an AppSetting?

    This will read an <appsettings> entry that you can put in either the .config for the project or in the machine.config in the Microsoft .NET folder on the machine.

    Then in the code You can just reference ConfigurationManager.AppSettings["printer"] anywhere you need to. You can edit the appsetting at any time.

    I will warn you though, be very careful when messing with the machine.config, you can really mess up your pc or environment if you use incorrect syntax or forget a closing /> For this reason, I would highly recommend using the .config of your project.

    Check this link for more info