In VBS How to use a parameter from environment variable



I'm new to VBS and i wrote a little script that can modify an xml file, And I need to put the computer name inside a node in the xml.


i got the computer name as an environment variable called HOST, and i was able to capture it through the vb script. using this lines:



Set wshShell = CreateObject( "WScript.Shell" )
WScript.Echo wshShell.ExpandEnvironmentStrings( "HOST=%HOST%" )


now i want to put it in the path inside the XML, meaning everywhere you see %HOST% I want the computer name to be.



sWebcastFlash = "%HOST%:port/webcast/"
sWebcastInfra = "%HOST%/webcast/"
sWebcastTelephone = "%HOST%:port/telephone/"


Sorry for the dumb question but this is my first script in this language and I can use the help.


This is the full script i wrote:



Set wshShell = CreateObject( "WScript.Shell" )
WScript.Echo wshShell.ExpandEnvironmentStrings( "HOST=%HOST%" )
'wshShell = Nothing


sWebcastFlash = "%HOST%:port/webcast/"
sWebcastInfra = "%HOST%/webcast/"
sWebcastTelephone = "%HOST%:port/telephone/"

'Create XMLDoc object
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.load "D:\Configuration\developer\developer-definitions.xml"

Set nWebcastFlash = xmlDoc.selectSingleNode("//clusters/cluster/servers/server/webcast-fms-url-for-flash")
Set nWebcastInfra = xmlDoc.selectSingleNode("//clusters/cluster/servers/server/webcast-fms-url-for-infra")
Set nWebcastTelephone = xmlDoc.selectSingleNode("//clusters/cluster/servers/server/webcast-fms-telephone-preview-url")
Set nWebcamUrl = xmlDoc.selectsinglenode ("//clusters/cluster/servers/server/webcam-self-test-url")
Set nHostName = xmlDoc.selectsinglenode ("//clusters/cluster/servers/server/host-name")
Set nHostAddress = xmlDoc.selectsinglenode ("//clusters/cluster/servers/server/host-address")
Set nAudUrl = xmlDoc.selectsinglenode ("//media-definitions/media-servers/on-demand-media-url/url-list/url/aud-url")
Set nFlashUrl = xmlDoc.selectsinglenode ("//flash-server-chat-list-url/flash-server-url")
Set nWebcamTest = xmlDoc.selectsinglenode ("//flash-server-webcam-self-url/webcam-self-test")

'Set the text node with the new value
nWebcastFlash.text = sWebcastFlash
nWebcastInfra.text = sWebcastInfra
nWebcastTelephone.text = sWebcastTelephone
'Save the xml document with the new settings.
strResult = xmldoc.save("D:\out.xml")

No comments:

Post a Comment