Link to home
Start Free TrialLog in
Avatar of solomonacquah
solomonacquahFlag for United States of America

asked on

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" ?>
<configuration>
<identity impersonate="true" />
<username="admin" />
<Password="password" />

</configuration>
Avatar of Ravi Singh
Ravi Singh
Flag of United Kingdom of Great Britain and Northern Ireland image

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"?>
<configuration>
      <appSettings>
                                <add key="impersonate" value="true"/>
            <add key="username" value="username here"/>
            <add key="password" value="password here"/>
      </appSettings>
</configuration>

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")
Avatar of solomonacquah

ASKER

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"
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.
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 :)
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.
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?
ASKER CERTIFIED SOLUTION
Avatar of LordWabbit
LordWabbit

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial