Calling info from app.config file.

I have created a tool for someone in our training department to simply reboot about 16 machines at one, basically it calls a shutdown script which has all the machines names. Problem is that this person who will use the tool is not an admin, and cannot be. How do I go about placing admin credentials in an app.config file and then calling that app.config file from my vb application.  this is what I have in my app.config file so far, I just don't know how to make my vb app read from this file.  I am also using the class Imports System.Configuration.ConfigurationSettings

<?xml version="1.0" encoding="utf-8" ?>
<identity impersonate="true" />
<username="admin" />
<Password="password" />

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ravi SinghSenior Software EngineerCommented:
Hi, if you want to read the application config file using the System.Configuration.ConfigurationSettings.AppSettings class then your config file needs to look like:

<?xml version="1.0" encoding="utf-8"?>
                                <add key="impersonate" value="true"/>
            <add key="username" value="username here"/>
            <add key="password" value="password here"/>

Best way to create this file is within the VS.NET IDE itself, goto Project -> Add New Item -> Select Text File and name it "app.config". Write out the XML text into the new file (can be done through the IDE), when you next build the project the app.config file will be output along with your executable.

To access the settings from within your code you can have something like:

Imports System.Configuration.ConfigurationSettings

        Dim UserName As String = AppSettings.Get("username")
        Dim Password As String = AppSettings.Get("password")
solomonacquahAuthor Commented:
Thank you it appears to compile fine but when the program launches I click the button that perfoms this function I get
"Additional information: Unrecognized configuration section appsettings"
solomonacquahAuthor Commented:
I figured that XML is case sensitive, lastly is there anything I have to sepcify if the username I want to use is from a domain account.
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Ravi SinghSenior Software EngineerCommented:
Hi solomonacquah, I'm not really the best person to answer that question... a wild guess would be that to specify a username from a specific domain the username would have to be in the format "domain\username". Apart from that i'm not sure, perhaps if you wait a while another expert may be able to help in this question, if not, try open another question specific to your current problem. Good luck :)
solomonacquahAuthor Commented:
Ok Thank you, one last question do you think this is the best way to have a user run an application that needs administrator rights.
Ravi SinghSenior Software EngineerCommented:
Hi, can you give a basic idea on how you have currently implemented this by answering the following questions; how will the user interact with the application? will he/she put username/passwords for each machine in the application config and then execute your app? How are you then shutting down the machines with this data?
putting the admin cred's into the config file is not a good idea as it's stored in plain text and anyone can simply open the file in notepad and get the credentials.  you could create a shortcut to your application, and then modify the shortcut to run with admin credentials (right click the shortcut - properties - shortcut tab - advanced).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.