PDA

View Full Version : Changing Path Variables using Automation



rdemarco
11-29-2005, 10:48 PM
Hi,

I am trying to change some of my path variables using Automation via vbscript.

I have the following script which I found on the forum:

dim WshShell
set WshShell = WScript.CreateObject("WScript.Shell")

'the .ISM is assumed to be in the same dir as this .vbs
STRPath = WshShell.CurrentDirectory
ISMPath = STRPath & "\TestProject.ism"

'open the .ISM as a Windows Installer object
dim database, installer, view, record
set installer = CreateObject("WindowsInstaller.Installer")

set database = installer.OpenDatabase(ISMPath,1)


sqlQuery = "SELECT * FROM `ISPathVariable` WHERE `ISPathVariable`.`ISPathVariable`='New Path Variable'"
set view = database.OpenView(sqlQuery)
view.Execute
set record = view.Fetch
'make the change
record.StringData(2)="C:\MyNewpath1"
'save the changes
view.Modify 2,record
view.Close
database.Commit

'close up
set installer = Nothing

The script seems to work against some .ism (all built in IS11) files but not others and I can't seem to figure out why! When the script fails I get the following error:

Line: 12
Error: OpenDatabase, DatabasePath,OpenMode
Code: 80004005
Source: Msi API Error

Line 12 is the OpenDatabase line..

After some testing on the .ism file that does work I did notice that I get the same error when the project is open in IS. Now I don't have the project that doesn't work open in IS and the file is checked out via source safe. Is there any way that the file could be open and hence why it's failing? I did a complete reboot and still get same error..

Anyone have any ideas what might be happening here?

Thanks, Rick

DLee65
11-30-2005, 09:43 AM
Is the path to the ISM correct? What are the properties on the ISM file before the script is run? If they are read-only can you try to switch it to normal before hand?

rdemarco
11-30-2005, 05:51 PM
Yes the path is correct, i've even tried to hard code the path but still no luck.. The file is not read-only either.. I've got this to fail on another project also, the project that does work is pretty much empty and only contains one component...

rdemarco
11-30-2005, 06:31 PM
Thanks for the reply...

I figured out what my problme was, the project file was saved in XML format and not binary and i didn't know until after reading another post that you need the .ism file saved in binary mode to use Windows Automation..

Thanks, Rick

rpalladino
12-15-2005, 07:42 AM
rdemarco,

I have the same problem.
How can I convert my project back from XML to binary?

Thanks!

RobertDickau
12-15-2005, 10:02 AM
General Information > Project Properties > Project File Format should do it.

rpalladino
12-15-2005, 11:22 AM
Thank you!

Brian6667
12-19-2005, 11:16 AM
I've found that performing a Save over the same file name does not always work, after converting I sometimes have to do a Save As with a new file name.

Brian