Answered by:
How to change value in XML file using VB Script

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><recordingProfile><pcSettings><screenCodecType>TSCC</screenCodecType><screenFrameRate>10</screenFrameRate><screenKeyFrameRate>100</screenKeyFrameRate><useAutoDetectSettings>0</useAutoDetectSettings><audioEnable>1</audioEnable><audioCodec>PCM</audioCodec><audioSampleRate>22050</audioSampleRate><audioNumChannels>1</audioNumChannels><audioBitRate>44100</audioBitRate><audioBitDepth>16</audioBitDepth><cameraEnable>0</cameraEnable><cameraFrameRate>0</cameraFrameRate><cameraProfile>System.Data.DataRowView</cameraProfile><cameraVideoWidth>320</cameraVideoWidth><cameraVideoHeight>240</cameraVideoHeight></pcSettings><macSettings><screenCodecType>TechSmith EnSharpen</screenCodecType><screenFrameRate>10</screenFrameRate><screenKeyFrameRate>100</screenKeyFrameRate><adjustScreenCaptureRate>0</adjustScreenCaptureRate><useAutoDetectSettings>0</useAutoDetectSettings><audioEnable>1</audioEnable><audioCodec>AAC</audioCodec><audioSampleRate>22050</audioSampleRate><audioNumChannels>1</audioNumChannels><audioBitRate>0</audioBitRate><audioBitDepth>0</audioBitDepth><cameraEnable>0</cameraEnable><cameraFrameRate>0</cameraFrameRate><cameraCodec>Apple Planar RGB</cameraCodec><cameraVideoWidth>320</cameraVideoWidth><cameraVideoHeight>240</cameraVideoHeight></macSettings></recordingProfile></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
-
Hello Wes,
Thanks for your post.
spotty has given you helpful suggestions. For VBScript questions, you will get better support at related forums to VBScript.
http://www.visualbasicscript.com/ (A Non-Microsoft Site)
http://social.technet.microsoft.com/Forums/en-US/ITCG/threads
Best regards
Liliane Teng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked as answer by Wes 19 Thursday, April 12, 2012 10:23 PM
Thursday, February 10, 2011 1:38 AM
All replies
-
This forum is for VB.NET questions
For vbscript try posting int he following forum
If you want to do this in .NET then this is extremely simple and We can provide some code examples but VBScript and VB.NET are significantly different.
Monday, February 7, 2011 9:05 PM -
Hello Wes,
Thanks for your post.
spotty has given you helpful suggestions. For VBScript questions, you will get better support at related forums to VBScript.
http://www.visualbasicscript.com/ (A Non-Microsoft Site)
http://social.technet.microsoft.com/Forums/en-US/ITCG/threads
Best regards
Liliane Teng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked as answer by Wes 19 Thursday, April 12, 2012 10:23 PM
Thursday, February 10, 2011 1:38 AM