Reuse custom action passing properties
I have a set properties custom action that I would like to utilize for two VBScript custom actions. How do I tie the two VBScripts to the set properties custom action? I'm guessing that it is in the Source column of the CustomAction table? Or is this not even possible and instead I have to have two set property custom actions even though the value is the same?
0 Comments
[ + ] Show comments
Answers (12)
Please log in to answer
Posted by:
anonymous_9363
14 years ago
Posted by:
joedown
14 years ago
No, both scripts are in the binary table and run deferred execute(just before InstallFinalize). Is it possible to pass the same value from a set property custom action to two Custom Action VBscripts? My scenario is this: I need a script to run during install and a second script to run during uninstall. Both scripts need to be passed the same value from the set property custom action. So what is the standard method for accomplishing this type of thing?
ORIGINAL: VBScab
Are they embedded scripts running in Deferred Execute? If not, why bother? The hoop-jumping of naming the property with the same name as the CA is only required for that type of script.
I guess that would be better expressed as: What is it you're trying to achieve?
Posted by:
anonymous_9363
14 years ago
The best approach would be to move the code which does the work and processes the variables into a function. Then, pass the properties to the function in the call.
Assuming:
- your function is called 'Main' and takes two parameters
- the Binary table entry is called MyScript
- you want to pass 2 properties, THISPROPERTY and THATPROPERTY
the Custom Action table would look like:
Action,Type,Source,Target
CA_ED_Whatever,3078,MyScript,Main([THISPROPERTY], [THATPROPERTY])
Assuming:
- your function is called 'Main' and takes two parameters
- the Binary table entry is called MyScript
- you want to pass 2 properties, THISPROPERTY and THATPROPERTY
the Custom Action table would look like:
Action,Type,Source,Target
CA_ED_Whatever,3078,MyScript,Main([THISPROPERTY], [THATPROPERTY])
Posted by:
joedown
14 years ago
Can you explain the moving code into a function? I think I understand what you have stated below except for the function you called Main. Or are you talking about a function in my VBscript called Main? In which case my script is getting the properties from the session.property("CustomActionData") which I'm then splitting out into an array since I'm passing six properties into the script via the CustomActionData property.
ORIGINAL: VBScab
The best approach would be to move the code which does the work and processes the variables into a function. Then, pass the properties to the function in the call.
Assuming:
- your function is called 'Main' and takes two parameters
- the Binary table entry is called MyScript
- you want to pass 2 properties, THISPROPERTY and THATPROPERTY
the Custom Action table would look like:
Action,Type,Source,Target
CA_ED_Whatever,3078,MyScript,Main([THISPROPERTY], [THATPROPERTY])
Posted by:
anonymous_9363
14 years ago
You may already be in an appropriate state but anyway...
Let's say your code looks like this currently:
We want to turn that into a function which takes 2 parameters. Instead of 'Main' I'll call it DeleteFolder:
Let's say your code looks like this currently:
Dim objFSO
Dim strTargetFolder
Dim objFolder
Dim blnForceDeletion
Set objFSO = CreateObject("Scripting.FileSystemObject")
strTargetFolder = "C:\WINDOWS"
blnForceDeletion = True
With objFSO
If .FolderExists(strTargetFolder) Then
Set objFolder = .GetFolder(strTargetFolder)
objFolder.Delete blnForceDeletion
If .FolderExists(strTargetFolder) Then
WScript.Echo "Delete failed"
End If
End With
Set objFSO = Nothing
We want to turn that into a function which takes 2 parameters. Instead of 'Main' I'll call it DeleteFolder:
Dim blnReturn
strTargetFolder = "C:\WINDOWS"
blnForceDeletion = True
blnReturn = DeleteFolder(strTargetFolder, blnForceDeletion)
If Not blnReturn Then
WScript.Echo "Delete failed"
End If
Function DeleteFolder(ByVal strTarget, ByVal blnForce)
Dim objFSO
Dim objFolder
DeleteFolder = False
Set objFSO = CreateObject("Scripting.FileSystemObject")
With objFSO
If .FolderExists(strTarget) Then
Set objFolder = .GetFolder(strTarget)
objFolder.Delete blnForce
If .FolderExists(strTarget) Then
Exit Function
End If
End With
DeleteFolder = True
Set objFSO = Nothing
End Function
Posted by:
joedown
14 years ago
This is the begining code in both my scripts:
I thought the only way to pass properties to a deferred CA was to use a set property CA? Are you saying that I can just pass my property variables in the Target field?
propCommaDelim = Session.Property("CustomActionData")'Recieves comma delimitted list of properties that the MSI will pass in
propArray = Split(propCommaDelim,",")
StrRemoteSyncUser = propArray(0)
StrRemoteSyncPass= propArray(1)
StrLocalSQLUser = propArray(2)
StrLocalSqlPass = propArray(3)
StrRmsFarUser = propArray(4)
StrInstallFolder = propArray(5)
I thought the only way to pass properties to a deferred CA was to use a set property CA? Are you saying that I can just pass my property variables in the Target field?
Posted by:
joedown
14 years ago
Posted by:
anonymous_9363
14 years ago
Posted by:
joedown
14 years ago
Posted by:
anonymous_9363
14 years ago
Posted by:
joedown
14 years ago
My script doesn't appear to be receiving the property values. I just want to make sure I'm doing this right. Going by the function example you have above my Target field would look like the following:
DeleteFolder([TargetFolder], [ForceDeletion])
My Target field:
Install([SYNCUSER], [SYNCPASS], [SQLUSER], [SQLPASS], [FARUSER], [TARGETDIR])
My function:
Public Sub Install(ByVal SYNCUSER, ByVal SYNCPASS, ByVal SQLUSER, ByVal SQLPASS, ByVal FARUSER, ByVal TARGETDIR)
StrRemoteSyncUser = SYNCUSER
StrRemoteSyncPass= SYNCPASS
StrLocalSQLUser = SQLUSER
StrLocalSqlPass = SQLPASS
StrRmsFarUser = FARUSER
StrInstallFolder = TARGETDIR
DeleteFolder([TargetFolder], [ForceDeletion])
My Target field:
Install([SYNCUSER], [SYNCPASS], [SQLUSER], [SQLPASS], [FARUSER], [TARGETDIR])
My function:
Public Sub Install(ByVal SYNCUSER, ByVal SYNCPASS, ByVal SQLUSER, ByVal SQLPASS, ByVal FARUSER, ByVal TARGETDIR)
StrRemoteSyncUser = SYNCUSER
StrRemoteSyncPass= SYNCPASS
StrLocalSQLUser = SQLUSER
StrLocalSqlPass = SQLPASS
StrRmsFarUser = FARUSER
StrInstallFolder = TARGETDIR
Posted by:
anonymous_9363
14 years ago
AFAIK, you can't use Sub: it has to be a Function. Also, there's no need to duplicate things by assigning new variables to those which already exist. No need for the 'Public' keyword, either. Try
Function Install(ByVal strRemoteSyncUser, ByVal strRemoteSyncPass, ByVal strLocalSQLUser, ByVal strLocalSqlPass, ByVal strRmsFarUser, ByVal strInstallFolder)
Then, in your function, just use the relevant variables as they are.
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.