Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

app.config from vbs 2

Status
Not open for further replies.

shyler

Programmer
May 3, 2010
11
US
I have a custom windows service with an app.config. I have a vbs file that needs to read values from that app.config file. I found this for vb.net -

Dim aConfig As Configuration.ConfigurationSettings
Dim aExcelFile As String = aConfig.AppSettings("MyExcelFileName")

But I need something that will work in vbs file, or a way to import System.Configuration into vbs file, but as far as I can see that's not possible.

I've done a lot of searching online and haven't found anything helpful yet. Please, someone, tell me it can be done!
 
You can do it like this.
[tt]
[green]'your givens
appconfig_path="c:\xyz\bin\debug\abc.exe.config"
[/green]
set oparser=createobject("msxml2.domdocument")
with oparser
.async=false
.resolveexternals=true
.validateonparse=false
end with

bret=oparser.load(appconfig_path)

if not bret then
wscript.echo oparser.parseerror.errorcode & vbcrlf & oparser.parseerror.reason
set oparser=nothing
wscript.quit 9 'early exit
end if

set odic=createobject("scripting.dictionary")
set cnodes=oparser.getElementsByTagName("add")
for each oadd in cnodes
skey=oadd.getAttribute("key")
sval=oadd.getAttribute("value")
if not odic.exists(skey) then
odic.add skey, sval
else
'issue warning
wscript.echo "warning (duplicate) ... " & skey & vbcrlf & "permissible, but not handled here"
end if
next
'for each skey in odic.keys
' wscript.echo skey & "=" & sval
'next
set oparser=nothing

if odic.exists("MyExcelFileName") then
aExcelFile=odic("MyExcelFileName")
'make use of aExcelFile as needed
else
aExcelFile="" 'decide what to do
end if

[/tt]
 
tsuji, thanks for the reply!

I get this error message when using the code you provided:

"Object doesn't support this property or method: 'oadd.getAttributes'
 
Replace this:
oadd.getAttributes
with this:
oadd.getAttribute

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Oh duh. Hahaha. Working great now.

Thanks so much for your help you guys!!!
 
>"Object doesn't support this property or method: 'oadd.getAttributes'"
Most probably a typo. It could easily be mine, but, no, to people's desolation, not this time. Not mine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top