How to Map a Drive within a ThinApp Packaged App
On occasion, we get asked how to do something like have a drive mapped before launching a ThinApp in the event the app needs to find something on the network instead of the local system or inside the Packaged app. Here is a simple script showing how to map a drive within ThinApp (before the app launches) and unmap the drive once the ThinApp packaged app is shut down.
NOTE: This will NOT be seen as a Virtual drive. Rather, this will map the network drive within Windows natively (like any other network mapped drive) so the drive will be visible to everything - including the ThinApp packaged app.
VBS ThinApp Drive Mapping Script
' DECLARE VARIABLES Dim WSHNetwork, WSHShell, objFSO, objShell Dim sDrive, sShare, sName ' SET GLOBAL VARIABLES Set WSHNetwork = CreateObject("WScript.Network") Set WSHShell = CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("Shell.Application") ' SET LOCAL VARIABLES sDrive = "<DRIVE>:" ' Set the Drive Letter to map sShare = "\\<SERVER>\<SHARE>" ' Set the share to map the drive letter to sName = "ThinApp Drive" Function OnFirstParentStart ' Conduct Drive Mapping If Not objFSO.DriveExists(sDrive) Then WSHNetwork.MapNetworkDrive sDrive, sShare, 0 objShell.NameSpace(sDrive).Self.Name = sName End If ' Set the current directory WSHShell.CurrentDirectory = sDrive & "<PATH>" ' Set the Current Directory only if necessary. Otherwise remark out. End Function Function OnLastProcessExit ' Unmap Drive WSHNetwork.RemoveNetworkDrive sDrive, True, True End Function
The ThinApp Drive Mapping Script can be downloaded from here.
Implementation
To implement, do the following steps:
- Download the ThinApp Drive Mapping Script (in TXT format) and rename to a file (any name) with a ".VBS" extension.
- Save the ".VBS" file in the root folder of your ThinApp Project with whatever name you wish.
- Edit the ".VBS" file and replace the current values for sDrive, sShare, and sName variables to something which matches your network configuration.
- After saving your configs, run BUILD.BAT to incorporate these changes.
Example:
' SET LOCAL VARIABLES
sDrive = "Z:" ' Set the Drive Letter to map
sShare = "\\10.1.1.10\THINAPP$" ' Set the share to map the drive letter to
sName = "My App's ThinApp Drive"
In the example above, this will set the "Z:" drive to be mapped to the "\\10.1.1.10\THINAPP$" share and change it's name in Windows Explorer to "My App's ThinApp Drive".
NOTE: Don't forget to also disable or set WSHShell.CurrentDirectory value to your proper path necessary.
You are now done! Test your app to ensure the packaged app properly maps the drive before launching and unmaps the drive after closing.
Comments