How to change value in XML file using VB Script

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello,
I have a xml file I want to change the values under each user node (needs to loop through each user node) where "charIndex" for "RecPauseHotkey" and "StopHotkey" are changed.
An example using the xml file below would be to change the "charIndex" for "RecPauseHotkey" and "StopHotkey" under each user node from "47" to "55"
Ive been researching the xml dom references, but cant seem to complete the vb script I intend to use to modify these values with group policy during logon.
Can you look at the script I have below and let me know what Im doing wrong or provide a different script to help me complete this change?


Example A: Example of XML File to Change

<div style="background-color:white; color:black
<pre><span style="color:blue <?<span style="color:#a31515 xml <span style="color:red version<span style="color:blue =<span style="color:black "<span style="color:blue 1.0<span style="color:black " <span style="color:red encoding<span style="color:blue =<span style="color:black "<span style="color:blue UTF-8<span style="color:black " <span style="color:blue ?>



<span style="color:blue <<span style="color:#a31515 camtasiaRelay<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 users<span style="color:blue >



<user userName="



<span style="color:blue <<span style="color:#a31515 presentation<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 files <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 PresenterName <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 PresenterEmail <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 PresentationTitle <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 PresentationDescription <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 PresentationStartTime <span style="color:blue />



<span style="color:blue </<span style="color:#a31515 presentation<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 RecPauseHotkey <span style="color:red ctrl<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red shift<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red alt<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red charIndex<span style="color:blue =<span style="color:black "<span style="color:blue 47<span style="color:black " <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 StopHotkey <span style="color:red ctrl<span style="color:blue =<span style="color:black "<span style="color:blue true<span style="color:black " <span style="color:red shift<span style="color:blue =<span style="color:black "<span style="color:blue true<span style="color:black " <span style="color:red alt<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red charIndex<span style="color:blue =<span style="color:black "<span style="color:blue 47<span style="color:black " <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 testRecording<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 testrecordingdir <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 testfiles <span style="color:blue />



<span style="color:blue </<span style="color:#a31515 testRecording<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 audioDevice <span style="color:red title<span style="color:blue =<span style="color:black "<span style="color:blue Microphone (SoundMAX Integrated Digital High Definition Audio)<span style="color:black " <span style="color:red mixer<span style="color:blue =<span style="color:black "<span style="color:blue 1<span style="color:black " <span style="color:red subsource<span style="color:blue =<span style="color:black "<span style="color:blue 0<span style="color:black " <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 preferredDesktop<span style="color:blue >0<span style="color:blue </<span style="color:#a31515 preferredDesktop<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 recordDimensions <span style="color:red X<span style="color:blue =<span style="color:black "<span style="color:blue 1280<span style="color:black " <span style="color:red Y<span style="color:blue =<span style="color:black "<span style="color:blue 800<span style="color:black " <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 recordRect <span style="color:red left<span style="color:blue =<span style="color:black "<span style="color:blue 0<span style="color:black " <span style="color:red top<span style="color:blue =<span style="color:black "<span style="color:blue 0<span style="color:black " <span style="color:red right<span style="color:blue =<span style="color:black "<span style="color:blue 1280<span style="color:black " <span style="color:red bottom<span style="color:blue =<span style="color:black "<span style="color:blue 800<span style="color:black " <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 UpdateAction<span style="color:blue >NoUpdate<span style="color:blue </<span style="color:#a31515 UpdateAction<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 UpdateActionVersion<span style="color:blue >2.0.0<span style="color:blue </<span style="color:#a31515 UpdateActionVersion<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 ServerVersion<span style="color:blue >2.0.0<span style="color:blue </<span style="color:#a31515 ServerVersion<span style="color:blue >



<span style="color:blue </<span style="color:#a31515 user<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 user <span style="color:red userName<span style="color:blue =<span style="color:black "<span style="color:blue UserNameID<span style="color:black "<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 presentation<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 files <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 PresenterName<span style="color:blue >Jimmy Hoffa<span style="color:blue </<span style="color:#a31515 PresenterName<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 PresenterEmail<span style="color:blue >someone@somewhere.com<span style="color:blue </<span style="color:#a31515 PresenterEmail<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 PresentationTitle<span style="color:blue ><span style="color:blue </<span style="color:#a31515 PresentationTitle<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 PresentationDescription<span style="color:blue ><span style="color:blue </<span style="color:#a31515 PresentationDescription<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 PresentationStartTime<span style="color:blue ><span style="color:blue </<span style="color:#a31515 PresentationStartTime<span style="color:blue >



<span style="color:blue </<span style="color:#a31515 presentation<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 audioDevice <span style="color:red title<span style="color:blue =<span style="color:black "<span style="color:blue Microphone (SoundMAX Integrated Digital High Definition Audio)<span style="color:black " <span style="color:red mixer<span style="color:blue =<span style="color:black "<span style="color:blue 1<span style="color:black " <span style="color:red subsource<span style="color:blue =<span style="color:black "<span style="color:blue 0<span style="color:black " <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 preferredDesktop<span style="color:blue >-1<span style="color:blue </<span style="color:#a31515 preferredDesktop<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 UpdateAction<span style="color:blue >NoUpdate<span style="color:blue </<span style="color:#a31515 UpdateAction<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 UpdateActionVersion<span style="color:blue >2.0.0<span style="color:blue </<span style="color:#a31515 UpdateActionVersion<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 ServerVersion<span style="color:blue >2.0.0<span style="color:blue </<span style="color:#a31515 ServerVersion<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 recordDimensions <span style="color:red X<span style="color:blue =<span style="color:black "<span style="color:blue 1920<span style="color:black " <span style="color:red Y<span style="color:blue =<span style="color:black "<span style="color:blue 1080<span style="color:black " <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 recordRect <span style="color:red left<span style="color:blue =<span style="color:black "<span style="color:blue 0<span style="color:black " <span style="color:red top<span style="color:blue =<span style="color:black "<span style="color:blue 0<span style="color:black " <span style="color:red right<span style="color:blue =<span style="color:black "<span style="color:blue 1920<span style="color:black " <span style="color:red bottom<span style="color:blue =<span style="color:black "<span style="color:blue 1080<span style="color:black " <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 recordSettingXml<span style="color:blue ><span style="color:red &lt;recordingProfile<span style="color:red &gt;<span style="color:red &lt;pcSettings<span style="color:red &gt;<span style="color:red &lt;screenCodecType<span style="color:red &gt;TSCC<span style="color:red &lt;/screenCodecType<span style="color:red &gt;<span style="color:red &lt;screenFrameRate<span style="color:red &gt;10<span style="color:red &lt;/screenFrameRate<span style="color:red &gt;<span style="color:red &lt;screenKeyFrameRate<span style="color:red &gt;100<span style="color:red &lt;/screenKeyFrameRate<span style="color:red &gt;<span style="color:red &lt;useAutoDetectSettings<span style="color:red &gt;0<span style="color:red &lt;/useAutoDetectSettings<span style="color:red &gt;<span style="color:red &lt;audioEnable<span style="color:red &gt;1<span style="color:red &lt;/audioEnable<span style="color:red &gt;<span style="color:red &lt;audioCodec<span style="color:red &gt;PCM<span style="color:red &lt;/audioCodec<span style="color:red &gt;<span style="color:red &lt;audioSampleRate<span style="color:red &gt;22050<span style="color:red &lt;/audioSampleRate<span style="color:red &gt;<span style="color:red &lt;audioNumChannels<span style="color:red &gt;1<span style="color:red &lt;/audioNumChannels<span style="color:red &gt;<span style="color:red &lt;audioBitRate<span style="color:red &gt;44100<span style="color:red &lt;/audioBitRate<span style="color:red &gt;<span style="color:red &lt;audioBitDepth<span style="color:red &gt;16<span style="color:red &lt;/audioBitDepth<span style="color:red &gt;<span style="color:red &lt;cameraEnable<span style="color:red &gt;0<span style="color:red &lt;/cameraEnable<span style="color:red &gt;<span style="color:red &lt;cameraFrameRate<span style="color:red &gt;0<span style="color:red &lt;/cameraFrameRate<span style="color:red &gt;<span style="color:red &lt;cameraProfile<span style="color:red &gt;System.Data.DataRowView<span style="color:red &lt;/cameraProfile<span style="color:red &gt;<span style="color:red &lt;cameraVideoWidth<span style="color:red &gt;320<span style="color:red &lt;/cameraVideoWidth<span style="color:red &gt;<span style="color:red &lt;cameraVideoHeight<span style="color:red &gt;240<span style="color:red &lt;/cameraVideoHeight<span style="color:red &gt;<span style="color:red &lt;/pcSettings<span style="color:red &gt;<span style="color:red &lt;macSettings<span style="color:red &gt;<span style="color:red &lt;screenCodecType<span style="color:red &gt;TechSmith EnSharpen<span style="color:red &lt;/screenCodecType<span style="color:red &gt;<span style="color:red &lt;screenFrameRate<span style="color:red &gt;10<span style="color:red &lt;/screenFrameRate<span style="color:red &gt;<span style="color:red &lt;screenKeyFrameRate<span style="color:red &gt;100<span style="color:red &lt;/screenKeyFrameRate<span style="color:red &gt;<span style="color:red &lt;adjustScreenCaptureRate<span style="color:red &gt;0<span style="color:red &lt;/adjustScreenCaptureRate<span style="color:red &gt;<span style="color:red &lt;useAutoDetectSettings<span style="color:red &gt;0<span style="color:red &lt;/useAutoDetectSettings<span style="color:red &gt;<span style="color:red &lt;audioEnable<span style="color:red &gt;1<span style="color:red &lt;/audioEnable<span style="color:red &gt;<span style="color:red &lt;audioCodec<span style="color:red &gt;AAC<span style="color:red &lt;/audioCodec<span style="color:red &gt;<span style="color:red &lt;audioSampleRate<span style="color:red &gt;22050<span style="color:red &lt;/audioSampleRate<span style="color:red &gt;<span style="color:red &lt;audioNumChannels<span style="color:red &gt;1<span style="color:red &lt;/audioNumChannels<span style="color:red &gt;<span style="color:red &lt;audioBitRate<span style="color:red &gt;0<span style="color:red &lt;/audioBitRate<span style="color:red &gt;<span style="color:red &lt;audioBitDepth<span style="color:red &gt;0<span style="color:red &lt;/audioBitDepth<span style="color:red &gt;<span style="color:red &lt;cameraEnable<span style="color:red &gt;0<span style="color:red &lt;/cameraEnable<span style="color:red &gt;<span style="color:red &lt;cameraFrameRate<span style="color:red &gt;0<span style="color:red &lt;/cameraFrameRate<span style="color:red &gt;<span style="color:red &lt;cameraCodec<span style="color:red &gt;Apple Planar RGB<span style="color:red &lt;/cameraCodec<span style="color:red &gt;<span style="color:red &lt;cameraVideoWidth<span style="color:red &gt;320<span style="color:red &lt;/cameraVideoWidth<span style="color:red &gt;<span style="color:red &lt;cameraVideoHeight<span style="color:red &gt;240<span style="color:red &lt;/cameraVideoHeight<span style="color:red &gt;<span style="color:red &lt;/macSettings<span style="color:red &gt;<span style="color:red &lt;/recordingProfile<span style="color:red &gt;<span style="color:blue </<span style="color:#a31515 recordSettingXml<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 SequenceNumber<span style="color:blue >0<span style="color:blue </<span style="color:#a31515 SequenceNumber<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 RecordingComplete<span style="color:blue >true<span style="color:blue </<span style="color:#a31515 RecordingComplete<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 ProfileId<span style="color:blue >-1<span style="color:blue </<span style="color:#a31515 ProfileId<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 TempRecordingDir <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 RecPauseHotkey <span style="color:red ctrl<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red shift<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red alt<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red charIndex<span style="color:blue =<span style="color:black "<span style="color:blue 47<span style="color:black " <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 StopHotkey <span style="color:red ctrl<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red shift<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red alt<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red charIndex<span style="color:blue =<span style="color:black "<span style="color:blue 47<span style="color:black " <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 testRecording<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 testrecordingdir <span style="color:blue />



<span style="color:blue <<span style="color:#a31515 testfiles <span style="color:blue />



<span style="color:blue </<span style="color:#a31515 testRecording<span style="color:blue >



<span style="color:blue </<span style="color:#a31515 user<span style="color:blue >



<span style="color:blue </<span style="color:#a31515 users<span style="color:blue >



<span style="color:blue <<span style="color:#a31515 computerID<span style="color:blue >8F4D1531-66C3-4F99-880F-C910BA03551B<span style="color:blue </<span style="color:#a31515 computerID<span style="color:blue >



<span style="color:blue </<span style="color:#a31515 camtasiaRelay<span style="color:blue >



















[/code]


Example B: Example of vbscript I have so far...

<div style="background-color:white; color:black
<pre><span style="color:blue Dim WshShell, UserProfile, xmlfile







<span style="color:blue Set WshShell = WScript.CreateObject(<span style="color:#a31515 "WScript.Shell")



UserProfile = WshShell.ExpandEnvironmentStrings(<span style="color:#a31515 "%Userprofile%")



xmlfile = Userprofile & <span style="color:#a31515 "AppDataLocalTechSmithCamtasia RelayRelayConfig.xml"







<span style="color:blue Set objXMLDoc = CreateObject(<span style="color:#a31515 "MSXML2.DomDocument.3.0")



objXMLDoc.async = <span style="color:blue False



objXMLdoc.Load(xmlFile)







<span style="color:blue Dim objNode, xmlnode







<span style="color:blue Set objNode = objXMLDoc.documentElement.lastChild



<span style="color:blue Set xmlnode = objxmldoc.SelectNodes(<span style="color:#a31515 "//user")







<span style="color:blue For i=0 <span style="color:blue To xmlnode.<span style="color:blue count - 1



<span style="color:green Loops only if record exists



<span style="color:blue If xmlnode(i).HasChildNodes <span style="color:blue Then



<span style="color:green iterating through each child node of User node



<span style="color:blue For j=0 <span style="color:blue To xmlnode(i).ChildNodes.<span style="color:blue count - 1



<span style="color:green checking condition if childnode of User node contains RECPAUSEHOTKEY element



<span style="color:blue If xmlnode(i).ChildNodes(j).LocalName.ToUpper().<span style="color:blue Equals(<span style="color:#a31515 "RECPAUSEHOTKEY") <span style="color:blue Then



xmlnode(i).ChildNodes(j).Attributes(3).InnerText = <span style="color:#a31515 "13"



<span style="color:blue End <span style="color:blue If



<span style="color:green checking condition if childnode of User node contains RECPAUSEHOTKEY element



<span style="color:blue If xmlnode(i).ChildNodes(j).LocalName.ToUpper().<span style="color:blue Equals(<span style="color:#a31515 "STOPHOTKEY") <span style="color:blue Then



xmlnode(i).ChildNodes(j).Attributes(3).InnerText = <span style="color:#a31515 "55"



<span style="color:blue End <span style="color:blue If



<span style="color:blue Next



objxmlDoc.Save (<span style="color:#a31515 "relayconfig.xml")



<span style="color:blue End <span style="color:blue If



<span style="color:blue Set objXMLDoc = <span style="color:blue Nothing



<span style="color:blue Next



[/code]


<
Wes

View the full article
 
Back
Top