Using Kbox scripting to replace a file
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!
Answers (1)
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
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
Comments:
-
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. :) - jdmabry 12 years ago -
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 - jagadeish 12 years ago -
ok, I have the script working locally. I just cant figure out how to push the script out with the kbox. Any ideas? - jdmabry 12 years ago
-
http://afzalyousufi.blogspot.co.uk/2011/03/procedure-to-run-vb-script-file-using.html - jagadeish 12 years ago
-
Thanks for everyone's help. Got this working last night! Awesome community! - jdmabry 12 years ago