radigast Posted November 13, 2007 Share Posted November 13, 2007 I want to import a global environment variable into Deployment.xml for Adobe Photoshop CS3 so that it will auto/silently install into the program files of any root drive...not just c:/. I know the AutoIT code for this (@ProgramFilesDir & "\Adobe"). However, I am an AutoIT and .xml ubernoob.I've searched .xml parsing, and found this thread. I won't pretend to understand any of this code, but I do know that it is being used in the same manner that I want: to overwrite values in an .xml file. The particulars are different, but the general idea is the same.Can anyone help me adapt his code to fit my application so that my silent install will go where I want? It must simply be changing around a couple of variables, but I have absolutely no clue how to even begin reading this code or identifying what all the .childnodes/.firstchild/.documentelement/.setattribute/etc.... stuff means.Here is the code for the .xml file:Deployment.xml<?xml version="1.0" encoding="utf-8"?><Deployment> <Properties> <Property name="INSTALLDIR">C:\Program Files\Adobe</Property><Property name="installLanguage">en_US</Property></Properties> <Payloads> <Payload adobeCode="{F0699DAC-0DC4-410B-B558-6D8CB5F3511A}"><Action>install</Action></Payload></Payloads> </Deployment>Here is the link and code for the already-made AutoIT script:expandcollapse popup; Get the xml file $filename = @ScriptDir & "\Test_1.xml" ; Parse the result $oXML = _CreateMSXMLObj() If Not IsObj($oXML) Then MsgBox(0, "_CreateMSXMLObj()", "ERROR!: Unable to create MSXML Object!!", 10) Exit 1 EndIf $oXML.async = False $error = $oXML.Load ($filename) If Not $error Then MsgBox(0, "Load XML", "An error occurred loading " & $filename, 10) Exit 1 EndIf $oXMLRoot = $oXML.documentElement $oAppNode = $oXML.selectSingleNode ("//customers") For $oXmlNode In $oAppNode.childNodes $new_name = "smith, tom" $new_age = "43" $oSubdataNode = $oXmlNode.firstchild ConsoleWrite("Debug: Changing Attributes." & @LF) $oSubdataNode.setAttribute ("name", $new_name) $oSubdataNode.setAttribute ("age", $new_age) Next $oXML.Save ($filename) Func _CreateMSXMLObj(); Creates a MSXML instance depending on the version installed on the system $xmlObj = ObjCreate("Msxml2.DOMdocument.6.0"); Latest available, default in Vista If IsObj($xmlObj) Then Return $xmlObj $xmlObj = ObjCreate("Msxml2.DOMdocument.5.0"); Office 2003 If IsObj($xmlObj) Then Return $xmlObj $xmlObj = ObjCreate("Msxml2.DOMdocument.4.0") If IsObj($xmlObj) Then Return $xmlObj $xmlObj = ObjCreate("Msxml2.DOMdocument.3.0"); XP and w2k3 server If IsObj($xmlObj) Then Return $xmlObj $xmlObj = ObjCreate("Msxml2.DOMdocument.2.6"); Win98 ME... If IsObj($xmlObj) Then Return $xmlObj Return 0 EndFunc ;==>_CreateMSXMLObjAny help is greatly appreciated! Thanks in advance! Link to comment Share on other sites More sharing options...
Josbe Posted November 13, 2007 Share Posted November 13, 2007 @radigast: eltorro created a nice UDF, take a look. AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
radigast Posted November 13, 2007 Author Share Posted November 13, 2007 @radigast: eltorro created a nice UDF, take a look.LOL. Thanks for the link. I downloaded the .au3 file, read the comments on the post, and am utterly lost. I barely understand coding, and simply want to create a very small .au3 file to overwrite one variable in the .xml code. I have no clue where to even begin using "xml dom wrapper", or even what it is supposed to do.How do I use this to create the AutoIT file to edit that 1 line of code I want to change? Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 13, 2007 Share Posted November 13, 2007 The easy way, if you don't need the power of an XML parser: Just read the file, do a StringReplace, and write it back to the file: $sFile = 'C:\Temp\Install.xml' $sData = FileRead($sFile) StringReplace($sData, '<Property name="INSTALLDIR">C:\Program Files\Adobe</Property>', _ '<Property name="INSTALLDIR">' & @ProgramFilesDir & '\Adobe</Property>') $hFile = FileOpen($sFile, 2) ; 2 = Overwrite FileWrite($hFile, $sData) FileClose($hFile) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Cr8iveOD Posted January 30, 2008 Share Posted January 30, 2008 any hints for using read only locations (DVD)? Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 30, 2008 Share Posted January 30, 2008 any hints for using read only locations (DVD)?Then you'll have to write it back to a different location. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Cr8iveOD Posted January 30, 2008 Share Posted January 30, 2008 (edited) thanks for the quick reply. I decided to just place the xml file in the OEM folders of my install. . Which leads to my next question. In your script you still use a definite location. ($sFile = 'C:\Temp\Install.xml') is there a way to use a variable there? so it could be installed from any drive not just C? Since the xml file is in the OEM folders of my Vista install, the system drive could be any letter. I would like it if the script would work even if the system drive was not C: forgive my ignorance, I'm pretty new to AutoIT. Seems like a fantastic utility, although as I read more I don't fully grasp its capabilities. thanks ahead of time Edited January 30, 2008 by Cr8iveOD Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 30, 2008 Share Posted January 30, 2008 thanks for the quick reply. I decided to just place the xml file in the OEM folders of my install. . Which leads to my next question. In your script you still use a definite location. ($sFile = 'C:\Temp\Install.xml') is there a way to use a variable there? so it could be installed from any drive not just C? I plan on putting the xml file in the OEM folders of my Vista install. I would like it if the script would work even if the system drive was not C: forgive my ignorance, I'm pretty new to AutoIT. Seems like a fantastic utility, although as I read more I don't fully grasp its capabilities. thanks ahead of time You could use variables and/or macros. Look, for example, in the help file at the @SystemDir macro:$sFile = @SystemDir & "\" & $sSubDir & "\Temp\Install.xml" Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Cr8iveOD Posted January 30, 2008 Share Posted January 30, 2008 Thanks so much! you saved me loads of google searches. Found the macro docs page. I'll try my install tonight report back with results! thanks! Link to comment Share on other sites More sharing options...
Cr8iveOD Posted February 2, 2008 Share Posted February 2, 2008 Hi again. It seems as if my script isn't having any effect on the install.xml file . Can anyone tell me the correct file location of @SystemDir on a windows vista 32bit OS? When i check the script for errors it reports the syntax is good. So the only thing I can think is that it can't find the xml file. Here is the script: $sFile = @SystemDir & "\TEMP\ADOBE CS3\install.xml" $sData = FileRead($sFile) StringReplace($sData, '<Property name="INSTALLDIR">Program Files\Adobe</Property>', _ '<Property name="INSTALLDIR">' & @ProgramFilesDir & '\Adobe</Property>') StringReplace($sData, '<Property name="StartMenuSubFolder">Start Menu\Programs\Adobe Master Collection CS3</Property>', _ '<Property name="StartMenuSubFolder">' & @StartMenuCommonDir & '\Programs\Adobe Master Collection CS3</Property>') StringReplace($sData, '<Property name="installSourcePath">Program Files\Common Files\Adobe\Installers\4dcfd9b7e901b57f81f667144603236</Property>', _ '<Property name="installSourcePath">' & @CommonFilesDir & '\Adobe\Installers\4dcfd9b7e901b57f81f667144603236</Property>') StringReplace($sData, '<Property name="mediaPath">Script Source\Install\ADOBE CS3\payloads\AdobeMasterCollectionSuiteen_US_Volume\AdobeMasterCollectionSuiteen_US_Volume.msi</Property>', _ '<Property name="mediaPath">' & @SystemDir & "\TEMP\ADOBE CS3\payloads\AdobeMasterCollectionSuiteen_US_Volume\AdobeMasterCollectionSuiteen_US_Volume.msi</Property>") $hFile = FileOpen($sFile, 2); 2 = Overwrite FileWrite($hFile, $sData) FileClose($hFile) I thought @SystemDir pointed at C:\Windows\System32 . but I've tried it pretty much everywhere. Are spaces a problem? Any help would be appreciated. thanks Link to comment Share on other sites More sharing options...
MHz Posted February 3, 2008 Share Posted February 3, 2008 Hi again. It seems as if my script isn't having any effect on the install.xml file ...That is because you are using StringReplace() without storing the value returned. I changed it to @Tempdir & "\ADOBE CS3\install.xml" for your xml path. If you are using a cmd script or registry then the equivalent to @TempDir is %TEMP%. Modified script $sFile = @TempDir & "\ADOBE CS3\install.xml" $sData = FileRead($sFile) If Not @error And $sData <> '' Then $sData = StringReplace($sData, _ '<Property name="INSTALLDIR">Program Files\Adobe</Property>', _ '<Property name="INSTALLDIR">' & @ProgramFilesDir & '\Adobe</Property>') $sData = StringReplace($sData, _ '<Property name="StartMenuSubFolder">Start Menu\Programs\Adobe Master Collection CS3</Property>', _ '<Property name="StartMenuSubFolder">' & @StartMenuCommonDir & '\Programs\Adobe Master Collection CS3</Property>') $sData = StringReplace($sData, _ '<Property name="installSourcePath">Program Files\Common Files\Adobe\Installers\4dcfd9b7e901b57f81f667144603236</Property>', _ '<Property name="installSourcePath">' & @CommonFilesDir & '\Adobe\Installers\4dcfd9b7e901b57f81f667144603236</Property>') $sData = StringReplace($sData, _ '<Property name="mediaPath">Script Source\Install\ADOBE CS3\payloads\AdobeMasterCollectionSuiteen_US_Volume\AdobeMasterCollectionSuiteen_US_Volume.msi</Property>', _ '<Property name="mediaPath">' & @TempDir & "\ADOBE CS3\payloads\AdobeMasterCollectionSuiteen_US_Volume\AdobeMasterCollectionSuiteen_US_Volume.msi</Property>") $hFile = FileOpen($sFile, 2); 2 = Overwrite If $hFile <> -1 Then FileWrite($hFile, $sData) FileClose($hFile) EndIf EndIf Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now