Add vbscript custom action?
I'm attempting to add a vbscript custom action for the first time to a package but it is failing to run with an Expected End of Statement error. Can I use a variable from the Directory table to specify the path in a VBScript? Do I have to put this script in the Binary table?
Script I want to run:
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "ALM_CONFIG_FILES\AdobeConfigPro.XML" , "ALM_CONFIG_FILES\AdobeConfig.XML"
Added custom action type 38:
Script I want to run:
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "ALM_CONFIG_FILES\AdobeConfigPro.XML" , "ALM_CONFIG_FILES\AdobeConfig.XML"
Added custom action type 38:
RenAdobeConfig 38 Set objFSO = CreateObject("Scripting.FileSystemObject") objFSO.MoveFile "ALM_CONFIG_FILES\AdobeConfigPro.XML" , "ALM_CONFIG_FILES\AdobeConfig.XML"
0 Comments
[ + ] Show comments
Answers (19)
Please log in to answer
Posted by:
captain_planet
15 years ago
You can use the MoveFile table to rename files I think? You should look into that first.
To access a directory property from an immediate CA you can use:
Session.Property("ALM_CONFIG_FILES")
However, because this is a system change it should be done in a deferred context and hence you'd have to fiddle around a bit like this: http://www.symantec.com/connect/articles/how-access-windows-installer-property-deferred-execution
To access a directory property from an immediate CA you can use:
Session.Property("ALM_CONFIG_FILES")
However, because this is a system change it should be done in a deferred context and hence you'd have to fiddle around a bit like this: http://www.symantec.com/connect/articles/how-access-windows-installer-property-deferred-execution
Posted by:
joedown
15 years ago
Unfortunately the MoveFile table is only for files that already exist prior to the installation of the package. I attempted that first. This looks to be a lot more difficult than I thought it would be. What is the best option for renaming a file after it gets installed? Unfortunately I cannot change the name of the file in the administrative install point.
ORIGINAL: captain_planet
You can use the MoveFile table to rename files I think? You should look into that first.
To access a directory property from an immediate CA you can use:
Session.Property("ALM_CONFIG_FILES")
However, because this is a system change it should be done in a deferred context and hence you'd have to fiddle around a bit like this: http://www.symantec.com/connect/articles/how-access-windows-installer-property-deferred-execution
Posted by:
captain_planet
15 years ago
Don't be overwhelmed by that boring article I posted a link to. Passing properties to deferred CAs is actually quite easy.
(Using Wise)
Step 1
Create a property. Call it 'AdobeConfigDir' and give it a default value of anything (we're going to set this to our directory name in Step 2....).
Step 2
Create a SetProperty CA (Type 51), call it 'setAdobeConfigDir', select your 'AdobeConfigDir' property, and under property value write '[ALM_CONFIG_FILES]'. Execute this action as Immediate, before InstallInitialize with a condition of 'NOT Installed' (or whatever condition you require).
Step 3
Create another CA - this time a 'Call VBScript from Embedded code' (Type 38). It is IMPORTANT you call this the same name as your property you made earlier, so call it 'AdobeConfigDir'. In your script, to retrieve the directory name use (this is NOT tested):
I think that covers it.....
(Using Wise)
Step 1
Create a property. Call it 'AdobeConfigDir' and give it a default value of anything (we're going to set this to our directory name in Step 2....).
Step 2
Create a SetProperty CA (Type 51), call it 'setAdobeConfigDir', select your 'AdobeConfigDir' property, and under property value write '[ALM_CONFIG_FILES]'. Execute this action as Immediate, before InstallInitialize with a condition of 'NOT Installed' (or whatever condition you require).
Step 3
Create another CA - this time a 'Call VBScript from Embedded code' (Type 38). It is IMPORTANT you call this the same name as your property you made earlier, so call it 'AdobeConfigDir'. In your script, to retrieve the directory name use (this is NOT tested):
Dim ConfigXMLDir
ConfigXMLDir = Session.Property("CustomActionData")
'ConfigXMLDir now contains the directory
Dim pathToConfigFile
pathToConfigFile = ConfigXMLDir & "AdobeConfigPro.XML"
'pathToConfigFile now contains the full path to the file
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(pathToConfigFile) Then
objFSO.MoveFile pathToConfigFile, getConfigDir & "AdobeConfig.XML"
End If
Now, schedule this CA as 'Deferred in a System Context' and put it between the standard actions 'ScheduleReboot' and 'InstallFinalize' (or generally, just make sure it's after 'InstallFiles' and before 'InstallFinalize'). Again, use a condition of 'NOT Installed' or whatever you see fit for your needs.I think that covers it.....
Posted by:
joedown
15 years ago
Only have InstEdit or Orca available. Should I be overwhelmed now? ;-) I think I can handle most of that but I'm not sure about the vbscrpt. Does it all go on one line in the CA table?
ORIGINAL: captain_planet
Don't be overwhelmed by that boring article I posted a link to. Passing properties to deferred CAs is actually quite easy.
(Using Wise)
Posted by:
ramesh111k
15 years ago
Hi Joedown,
If the requirement is only to rename an installed file from xxx.doc to yyy.doc or anything like this, a CA calling vbscript will solve the issue.
Ex: After installation if the file is stored in C:\program files\xxx\xxx.doc and if you want to rename it to yyy.doc, then please use the below script.
Dim fso,wshshell
set fso=createobject("scripting.filesystemobject")
set wshshell = createobject("wscript.shell")
progfile = wshshell.expandenvironmentstrings("%programfiles%")
If fso.fileexists(progfile & "\xxx\xxx.doc") Then
fso.movefile progfile & "\xxx\xxx.doc", progfile & "\xxx\yyy.doc"
End If
If you are using Wise: Now edit the msi and use CA Call vbscript from embedded code and copy the script there, sequence it just before InstallFinalize and condition Not installed. Under processing select Synchronous ignore exit code.
Hope this information will help you.
If the requirement is only to rename an installed file from xxx.doc to yyy.doc or anything like this, a CA calling vbscript will solve the issue.
Ex: After installation if the file is stored in C:\program files\xxx\xxx.doc and if you want to rename it to yyy.doc, then please use the below script.
Dim fso,wshshell
set fso=createobject("scripting.filesystemobject")
set wshshell = createobject("wscript.shell")
progfile = wshshell.expandenvironmentstrings("%programfiles%")
If fso.fileexists(progfile & "\xxx\xxx.doc") Then
fso.movefile progfile & "\xxx\xxx.doc", progfile & "\xxx\yyy.doc"
End If
If you are using Wise: Now edit the msi and use CA Call vbscript from embedded code and copy the script there, sequence it just before InstallFinalize and condition Not installed. Under processing select Synchronous ignore exit code.
Hope this information will help you.
Posted by:
captain_planet
15 years ago
If you are using Wise- he only has Orca/InstEdit- just like he said above. [;)]
Joe - it's easier to add type 38 CAs using the latest version of InstEdit than it is with Orca - just double click the 'Target' column in your CA table and paste away in the Multi-line text box it provides. Don't forget though, with your VBScript CA the type will actually go from a type 38 to a type 3110 because you're elevating it in a system context:
(see msi.chm)
38 = VBScript text stored in this sequence table.
3072 = Queues for execution at scheduled point within script. Executes with no user impersonation. Runs in system context.
3072 + 38 = 3110!
....or, if worse comes to the worst, you can hard-code your path like Ramesh said and do away with passing your directory property to the deferred CA. (boooo.....hissssssss)
Posted by:
joedown
15 years ago
Ok, what am I doing wrong? I'm using version 1.5.7.15 of InstEd and it is not allowing me to paste multiple lines in the Target field of my custom action.
ORIGINAL: captain_planet
If you are using Wise- he only has Orca/InstEdit- just like he said above. [;)]
Joe - it's easier to add type 38 CAs using the latest version of InstEdit than it is with Orca - just double click the 'Target' column in your CA table and paste away in the Multi-line text box it provides. Don't forget though, with your VBScript CA the type will actually go from a type 38 to a type 3110 because you're elevating it in a system context:
(see msi.chm)
38 = VBScript text stored in this sequence table.
3072 = Queues for execution at scheduled point within script. Executes with no user impersonation. Runs in system context.
3072 + 38 = 3110!
....or, if worse comes to the worst, you can hard-code your path like Ramesh said and do away with passing your directory property to the deferred CA. (boooo.....hissssssss)
Dim ConfigXMLDir ConfigXMLDir = Session.Property("CustomActionData") 'ConfigXMLDir now contains the directory Dim pathToConfigFile pathToConfigFile = ConfigXMLDir & "AdobeConfigPro.XML" 'pathToConfigFile now contains the full path to the file Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(pathToConfigFile) Then objFSO.MoveFile pathToConfigFile, getConfigDir & "AdobeConfig.XML" End If
Posted by:
captain_planet
15 years ago
Ok, what am I doing wrong?
Ha ha. Good question. At a glance, I have no idea how to insert multiple lines in an InstEdit Custom Action either! (Though I am using an earlier version than you). Maybe somebody on this forum can enlighten us? Or maybe it's an application limitation? I confess, I made my CA using Wise, and then opened it with InstEdit. But as seem as you can't do that, as a temporary 'fix' to your problem, copy and paste this script into a .vbs file, then drag your MSI/ISM/WSI onto the .vbs file. This will then add a Custom Action called 'retrieveProperty' with a multi line target field. This is only a quick hacky script so if you run it multiple times you WILL get MSI API errors because you're trying to insert a duplicate key.....
Set oInstaller = CreateObject("WindowsInstaller.Installer")
Set oDatabase = oInstaller.OpenDatabase(WScript.Arguments.Item(0), 1)
oDatabase.OpenView("INSERT INTO `CustomAction` (`Action`,`Type`,`Source`,`Target`) VALUES ('retrieveProperty','3110',' , 'Add carriage return....." & chr(13) & "')").Execute
oDatabase.Commit
MsgBox("Custom Action added!")
Set oDatabase = Nothing
Set oInstaller = Nothing
Posted by:
joedown
15 years ago
That worked good. I made a copy of the msi and dropped it onto the vbs file. I then opened the msi and copied the new row to my transform. I'm not getting any errors when running the install but it's not renaming the file. Here are the lines from my tables and the install log. I'm puzzled about the value returned in the log but maybe this is correct?
Tables
Install Log
Tables
Property:
AdobeConfigDir [ALM_CONFIG_FILES]
InstallExecuteSequence:
SetAdobeConfigDir Not Installed 1498
AdobeConfigDir Not Installed 6578
CustomAction:
SetAdobeConfigDir 51 [ALM_CONFIG_FILES]
AdobeConfigDir 3110 Dim ConfigXMLDir
ConfigXMLDir = Session.Property("CustomActionData")
'ConfigXMLDir now contains the directory
Dim pathToConfigFile
pathToConfigFile = ConfigXMLDir & "AdobeConfigPro.XML"
'pathToConfigFile now contains the full path to the file
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(pathToConfigFile) Then
objFSO.MoveFile pathToConfigFile, getConfigDir & "AdobeConfig.XML"
End If
Install Log
Property(s): AdobeConfigDir=[ALM_CONFIG_FILES]
MSI (s) (98:E4) [10:24:56:546]: Executing op: CustomActionSchedule(Action=AdobeConfigDir,ActionType=3110,Source=Dim ConfigXMLDir
ConfigXMLDir = Session.Property("CustomActionData")
'ConfigXMLDir now contains the directory
Dim pathToConfigFile
pathToConfigFile = ConfigXMLDir & "AdobeConfigPro.XML"
'pathToConfigFile now contains the full path to the file
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(pathToConfigFile) Then
objFSO.MoveFile pathToConfigFile, getConfigDir & "AdobeConfig.XML"
End If,,CustomActionData=[ALM_CONFIG_FILES])
ORIGINAL: captain_planet
Ok, what am I doing wrong?
Ha ha. Good question. At a glance, I have no idea how to insert multiple lines in an InstEdit Custom Action either! (Though I am using an earlier version than you). Maybe somebody on this forum can enlighten us? Or maybe it's an application limitation? I confess, I made my CA using Wise, and then opened it with InstEdit. But as seem as you can't do that, as a temporary 'fix' to your problem, copy and paste this script into a .vbs file, then drag your MSI/ISM/WSI onto the .vbs file. This will then add a Custom Action called 'retrieveProperty' with a multi line target field. This is only a quick hacky script so if you run it multiple times you WILL get MSI API errors because you're trying to insert a duplicate key.....
Set oInstaller = CreateObject("WindowsInstaller.Installer")
Set oDatabase = oInstaller.OpenDatabase(WScript.Arguments.Item(0), 1)
oDatabase.OpenView("INSERT INTO `CustomAction` (`Action`,`Type`,`Source`,`Target`) VALUES ('retrieveProperty','3110',' , 'Add carriage return....." & chr(13) & "')").Execute
oDatabase.Commit
MsgBox("Custom Action added!")
Set oDatabase = Nothing
Set oInstaller = Nothing
Posted by:
captain_planet
15 years ago
Posted by:
joedown
15 years ago
Yes, that was the problem. I'm now getting the correct path set in my property. However for some strange reason it is moving the file from the original location and depositing it in C:\Windows\System32. It did rename it so that's a good thing.
ORIGINAL: captain_planet
Joe - I'm not on a PC with my tools on at the moment, but looking at your post i suspect the type 51 CA is slightly wrong. It should be:
CustomAction:
SetAdobeConfigDir           51       AdobeConfigDir            [ALM_CONFIG_FILES]
Posted by:
captain_planet
15 years ago
Posted by:
joedown
15 years ago
Posted by:
captain_planet
15 years ago
Posted by:
anonymous_9363
15 years ago
Posted by:
captain_planet
15 years ago
Posted by:
joedown
15 years ago
Someone should tell that to Adobe. Adobe has moved the MoveFiles action to after the InstallFiles action. I wonder what MSI rule Adobe has not broken yet?
Since Adobe did move it to after the InstallFiles action I thought that this might possibly work to use the MoveFiles table to change the name. But unfortunately I was unable to get it to work.
Since Adobe did move it to after the InstallFiles action I thought that this might possibly work to use the MoveFiles table to change the name. But unfortunately I was unable to get it to work.
ORIGINAL: captain_planet
VBScab - I thought about that too, but the SDK clearly states:
"Sequence Restrictions
The MoveFiles action must come after the InstallValidate action and before the InstallFiles action."
Posted by:
captain_planet
15 years ago
Posted by:
instedit
14 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.