Thursday, April 19, 2012

VBScript to determine Root Drive

As per best practices we should not hard code the Root Drive in our package. If your package goes to multiple machines having different Root Drives, then you can use this simple VBScript in your package as Custom Action and it will set the Root Drive automatically for that machine.
This script picks up the Root Drive from where Program Files folder is installed.

Set oshell=CreateObject("Wscript.shell")
prog=oshell.ExpandEnvironmentStrings("%ProgramFiles%")
vletter=Split(prog,":")
dletter=vletter(0) & ":\"
session.property("ROOTDRIVE")=dletter

No comments: