Phil
Posts: 22
Joined: Sat Aug 27, 2005 3:47 am

How to get target drive?

Hi, simple question: I pass the TARGETDIR to a custom action ok. However I also need to pass the target drive. How can I get it?

I need to do this because the custom action I run is a batch file.... so I need to do something like:

E:
CD E:\MyApps\SomeDir

Thanks,
Phil
Mike
Posts: 292
Joined: Wed Jun 01, 2005 10:50 am
Location: Craiova, Romania
Contact: Website

Hi,

The TARGETDIR includes the information about the target drive. You could use a custom action to extract from that string the string that contains the drive letter.

Regards,
Mihai
Mihai Bobaru
Advanced Installer Team
http://www.advancedinstaller.com
Phil
Posts: 22
Joined: Sat Aug 27, 2005 3:47 am

Mike wrote:The TARGETDIR includes the information about the target drive. You could use a custom action to extract from that string the string that contains the drive letter.
Bugger.

How the heck do I do that? Do I need to do a sub-string some how??
Mike
Posts: 292
Joined: Wed Jun 01, 2005 10:50 am
Location: Craiova, Romania
Contact: Website

I meant the the second value you need is a substring in the first. So, all you need to do is to extract a substring from that string. You can achieve this with the usual string routines from any language.

Here is an example in VBScript:

Code: Select all

Dim path, root
path = "C:\Some Folder\Other Folder"
root = Left(path,3)
' Now root = "C:\"
Hope this helps.

All the best,
Mihai
Mihai Bobaru
Advanced Installer Team
http://www.advancedinstaller.com
Phil
Posts: 22
Joined: Sat Aug 27, 2005 3:47 am

The script side of it is not a problem. The problem now is I don't understand how to set a property in the installer with the result of the script.

What I've done: created a property called 'targetDrive' which I need to pass to a custom action (it could be C:, D:, E:, etc). Then in Custom Actions, the InstallInitialize section, I added a new 'script inline'. In it I specified the source type to be vbs and the script text to be:

Code: Select all

targetDrive = Left("[TARGETDIR]", 2)
However this does not work, and the AI help says the text field is "a plain text field, so you can't add references to files, folders or properties".

So how do I do it? Do I have the wrong type of custom action? I don't mind whether the script is vbs, js or I run an exe, but I cannot see how to set my 'targetDrive' parameter??

Thanks
Mike
Posts: 292
Joined: Wed Jun 01, 2005 10:50 am
Location: Craiova, Romania
Contact: Website

Hi,

In VBScript a property is accessed through the Session object.

Session.Property("TARGETDIR") returns the value of TARGETDIR.

So, your script should be

Code: Select all

Session.Property("targetDrive") = Left(Session.Property("TARGETDIR"), 3)
An example on how a property can be accessed from VBScript is also provided here:
http://www.advancedinstaller.com/user-g ... ipt-inline

All the best,
Mihai
Mihai Bobaru
Advanced Installer Team
http://www.advancedinstaller.com
Phil
Posts: 22
Joined: Sat Aug 27, 2005 3:47 am

That worked great, thanks Mike

Return to “Common Problems”