I am a complete newb when it comes to scripting. I have a program that pulls the location of it's database from a small xml file. I am migrating the database to another server and I need to send out a command to all of the computers on our network to replace the xml file with the new one that has the new server information in it. I imagine that something like this would take an experienced scripter like 5 minutes to write, for me however, I'll probably sit here for hours trying to figure it out and eventually have to just go to each computer and update it manually. I have to get this done today so I'm hoping for a savior. :) Here's the info:

 

XML file name: settings.xml 

settings.xml location: C:\Program Files (x86)\Phoenix Ortho\Bin\Release

Current settings.xml file info:

<?xml version="1.0" encoding="utf-8"?>

<Settings>

  <Server>Phoenix</Server>

  <UserName></UserName>

  <Password></Password>

  <PreferredProvider>0</PreferredProvider>

  <LoginName>jmabry</LoginName>

  <LocalServer></LocalServer>

  <LocalUserName></LocalUserName>

  <LocalPassword></LocalPassword>

  <RemoteServer></RemoteServer>

  <RemoteUserName></RemoteUserName>

  <RemotePassword></RemotePassword>

  <ErxAns1></ErxAns1>

  <ErxAns2></ErxAns2>

</Settings>

Updated settings.xml file with the server field updated with new server.

<?xml version="1.0" encoding="utf-8"?>

<Settings>

  <Server>EVE</Server>

  <UserName></UserName>

  <Password></Password>

  <PreferredProvider>0</PreferredProvider>

  <LoginName>jmabry</LoginName>

  <LocalServer></LocalServer>

  <LocalUserName></LocalUserName>

  <LocalPassword></LocalPassword>

  <RemoteServer></RemoteServer>

  <RemoteUserName></RemoteUserName>

  <RemotePassword></RemotePassword>

  <ErxAns1></ErxAns1>

  <ErxAns2></ErxAns2>

</Settings>

Here's a screen shot of how I'm trying to accomplish this in the kbox:

Any help would be awesome! Thanks!

 

Answer Summary:
Use the below VBScript Option Explicit On Error Resume Next Dim xmlDoc, nNode, strResult, wshShell, ProgramFiles, objFSO Set wshShell = CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") ProgramFiles = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%") Set xmlDoc = CreateObject("Microsoft.XMLDOM") If objFSO.FileExists(ProgramFiles & "\Phoenix Ortho\Bin\Release\Settings.xml") Then xmlDoc.Load ProgramFiles & "\Phoenix Ortho\Bin\Release\Settings.xml" Set nNode = xmlDoc.SelectSingleNode ("//Settings/Server") nNode.Text = "EVE" strResult = xmlDoc.Save(ProgramFiles & "\Phoenix Ortho\Bin\Release\Settings.xml") End If Set xmlDoc = Nothing Set wshShell = Nothing Set nNode = Nothing Set objFSO = Nothing WScript.Quit
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

3

Use the below VBScript

Option Explicit

On Error Resume Next

Dim xmlDoc, nNode, strResult, wshShell, ProgramFiles, objFSO

Set wshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

ProgramFiles = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%")
Set xmlDoc = CreateObject("Microsoft.XMLDOM")

If objFSO.FileExists(ProgramFiles & "\Phoenix Ortho\Bin\Release\Settings.xml") Then

xmlDoc.Load ProgramFiles & "\Phoenix Ortho\Bin\Release\Settings.xml" 
Set nNode = xmlDoc.SelectSingleNode ("//Settings/Server") 
nNode.Text = "EVE" 
strResult = xmlDoc.Save(ProgramFiles & "\Phoenix Ortho\Bin\Release\Settings.xml")

End If

Set xmlDoc = Nothing
Set wshShell = Nothing
Set nNode = Nothing
Set objFSO = Nothing
WScript.Quit

 

Answered 07/22/2012 by: jagadeish
Red Belt

  • Wow, thanks for the speedy response!

    I'm completely new to scripting, so I have no idea how to implement this vbscript with the kbox. Can I just copy this code into notepad and attach it to the dependencies? Or can I simply paste that into the batch file section in the screenshot? I need instructions for dummies. :)
  • This is VBScript... Copy and paste the above script in notepad and save it with .vbs extenstion.. Refer the below post to execute this with the kbox

    http://www.itninja.com/question/kace-k1000-how-do-you-run-a-vbscript-file
  • ok, I have the script working locally. I just cant figure out how to push the script out with the kbox. Any ideas?
  • http://afzalyousufi.blogspot.co.uk/2011/03/procedure-to-run-vb-script-file-using.html
  • Thanks for everyone's help. Got this working last night! Awesome community!
Please log in to comment
Answer this question or Comment on this question for clarity