locked
How to change value in XML file using VB Script RRS feed

  • Question

  • 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"

    I've been researching the xml dom references, but can't 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 I'm doing wrong or provide a different script to help me complete this change? 

     

     

     Example A: Example of XML File to Change

     

    <?xml version="1.0" encoding="UTF-8" ?>
    
    
    
    <camtasiaRelay>
    
    
    
     <users>
    
    
    
     <user userName="">
    
    
    
      <presentation>
    
    
    
      <files />
    
    
    
      <PresenterName />
    
    
    
      <PresenterEmail />
    
    
    
      <PresentationTitle />
    
    
    
      <PresentationDescription />
    
    
    
      <PresentationStartTime />
    
    
    
      </presentation>
    
    
    
      <RecPauseHotkey ctrl="false" shift="false" alt="false" charIndex="47" />
    
    
    
      <StopHotkey ctrl="true" shift="true" alt="false" charIndex="47" />
    
    
    
      <testRecording>
    
    
    
      <testrecordingdir />
    
    
    
      <testfiles />
    
    
    
      </testRecording>
    
    
    
      <audioDevice title="Microphone (SoundMAX Integrated Digital High Definition Audio)" mixer="1" subsource="0" />
    
    
    
      <preferredDesktop>0</preferredDesktop>
    
    
    
      <recordDimensions X="1280" Y="800" />
    
    
    
      <recordRect left="0" top="0" right="1280" bottom="800" />
    
    
    
      <UpdateAction>NoUpdate</UpdateAction>
    
    
    
      <UpdateActionVersion>2.0.0</UpdateActionVersion>
    
    
    
      <ServerVersion>2.0.0</ServerVersion>
    
    
    
     </user>
    
    
    
     <user userName="UserNameID">
    
    
    
      <presentation>
    
    
    
      <files />
    
    
    
      <PresenterName>Jimmy Hoffa</PresenterName>
    
    
    
      <PresenterEmail>someone@somewhere.com</PresenterEmail>
    
    
    
      <PresentationTitle></PresentationTitle>
    
    
    
      <PresentationDescription></PresentationDescription>
    
    
    
      <PresentationStartTime></PresentationStartTime>
    
    
    
      </presentation>
    
    
    
      <audioDevice title="Microphone (SoundMAX Integrated Digital High Definition Audio)" mixer="1" subsource="0" />
    
    
    
      <preferredDesktop>-1</preferredDesktop>
    
    
    
      <UpdateAction>NoUpdate</UpdateAction>
    
    
    
      <UpdateActionVersion>2.0.0</UpdateActionVersion>
    
    
    
      <ServerVersion>2.0.0</ServerVersion>
    
    
    
      <recordDimensions X="1920" Y="1080" />
    
    
    
      <recordRect left="0" top="0" right="1920" bottom="1080" />
    
    
    
      <recordSettingXml>&lt;recordingProfile&gt;&lt;pcSettings&gt;&lt;screenCodecType&gt;TSCC&lt;/screenCodecType&gt;&lt;screenFrameRate&gt;10&lt;/screenFrameRate&gt;&lt;screenKeyFrameRate&gt;100&lt;/screenKeyFrameRate&gt;&lt;useAutoDetectSettings&gt;0&lt;/useAutoDetectSettings&gt;&lt;audioEnable&gt;1&lt;/audioEnable&gt;&lt;audioCodec&gt;PCM&lt;/audioCodec&gt;&lt;audioSampleRate&gt;22050&lt;/audioSampleRate&gt;&lt;audioNumChannels&gt;1&lt;/audioNumChannels&gt;&lt;audioBitRate&gt;44100&lt;/audioBitRate&gt;&lt;audioBitDepth&gt;16&lt;/audioBitDepth&gt;&lt;cameraEnable&gt;0&lt;/cameraEnable&gt;&lt;cameraFrameRate&gt;0&lt;/cameraFrameRate&gt;&lt;cameraProfile&gt;System.Data.DataRowView&lt;/cameraProfile&gt;&lt;cameraVideoWidth&gt;320&lt;/cameraVideoWidth&gt;&lt;cameraVideoHeight&gt;240&lt;/cameraVideoHeight&gt;&lt;/pcSettings&gt;&lt;macSettings&gt;&lt;screenCodecType&gt;TechSmith EnSharpen&lt;/screenCodecType&gt;&lt;screenFrameRate&gt;10&lt;/screenFrameRate&gt;&lt;screenKeyFrameRate&gt;100&lt;/screenKeyFrameRate&gt;&lt;adjustScreenCaptureRate&gt;0&lt;/adjustScreenCaptureRate&gt;&lt;useAutoDetectSettings&gt;0&lt;/useAutoDetectSettings&gt;&lt;audioEnable&gt;1&lt;/audioEnable&gt;&lt;audioCodec&gt;AAC&lt;/audioCodec&gt;&lt;audioSampleRate&gt;22050&lt;/audioSampleRate&gt;&lt;audioNumChannels&gt;1&lt;/audioNumChannels&gt;&lt;audioBitRate&gt;0&lt;/audioBitRate&gt;&lt;audioBitDepth&gt;0&lt;/audioBitDepth&gt;&lt;cameraEnable&gt;0&lt;/cameraEnable&gt;&lt;cameraFrameRate&gt;0&lt;/cameraFrameRate&gt;&lt;cameraCodec&gt;Apple Planar RGB&lt;/cameraCodec&gt;&lt;cameraVideoWidth&gt;320&lt;/cameraVideoWidth&gt;&lt;cameraVideoHeight&gt;240&lt;/cameraVideoHeight&gt;&lt;/macSettings&gt;&lt;/recordingProfile&gt;</recordSettingXml>
    
    
    
      <SequenceNumber>0</SequenceNumber>
    
    
    
      <RecordingComplete>true</RecordingComplete>
    
    
    
      <ProfileId>-1</ProfileId>
    
    
    
      <TempRecordingDir />
    
    
    
      <RecPauseHotkey ctrl="false" shift="false" alt="false" charIndex="47" />
    
    
    
      <StopHotkey ctrl="false" shift="false" alt="false" charIndex="47" />
    
    
    
      <testRecording>
    
    
    
      <testrecordingdir />
    
    
    
      <testfiles />
    
    
    
      </testRecording>
    
    
    
     </user>
    
    
    
     </users>
    
    
    
     <computerID>8F4D1531-66C3-4F99-880F-C910BA03551B</computerID>
    
    
    
    </camtasiaRelay>
    
    
    
    
    
    
    
     
    
    
    
    
    
    
    
    
    
    
    
    

     

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

     

    Dim WshShell, UserProfile, xmlfile
    
    
    
    
    
    
    
    Set WshShell = WScript.CreateObject("WScript.Shell") 
    
    
    
    UserProfile = WshShell.ExpandEnvironmentStrings("%Userprofile%") 
    
    
    
    xmlfile = Userprofile & "\AppData\Local\TechSmith\Camtasia Relay\RelayConfig.xml"
    
    
    
    
    
    
    
    Set objXMLDoc = CreateObject("MSXML2.DomDocument.3.0") 
    
    
    
    objXMLDoc.async = False
    
    
    
    objXMLdoc.Load(xmlFile)
    
    
    
    
    
    
    
    Dim objNode, xmlnode
    
    
    
    
    
    
    
    Set objNode = objXMLDoc.documentElement.lastChild 
    
    
    
    Set xmlnode = objxmldoc.SelectNodes("//user") 
    
    
    
    
    
    
    
    For i=0 To xmlnode.count - 1 
    
    
    
    ' Loops only if record exists 
    
    
    
    If xmlnode(i).HasChildNodes Then
    
    
    
    'iterating through each child node of User node 
    
    
    
    For j=0 To xmlnode(i).ChildNodes.count - 1 
    
    
    
    'checking condition if childnode of User node contains RECPAUSEHOTKEY element 
    
    
    
    If xmlnode(i).ChildNodes(j).LocalName.ToUpper().Equals("RECPAUSEHOTKEY") Then
    
    
    
     xmlnode(i).ChildNodes(j).Attributes(3).InnerText = "13"
    
    
    
    End If
    
    
    
    'checking condition if childnode of User node contains RECPAUSEHOTKEY element 
    
    
    
     If xmlnode(i).ChildNodes(j).LocalName.ToUpper().Equals("STOPHOTKEY") Then
    
    
    
     xmlnode(i).ChildNodes(j).Attributes(3).InnerText = "55"
    
    
    
    End If
    
    
    
    Next
    
    
    
     objxmlDoc.Save ("relayconfig.xml")
    
    
    
    End If
    
    
    
    Set objXMLDoc = Nothing
    
    
    
    Next
    
    
    
    

     


    Wes
    • Moved by Liliane Teng Friday, February 11, 2011 8:27 AM (From:Visual Basic General)
    Monday, February 7, 2011 8:59 PM

Answers

All replies