XenApp: VBScript to Map Network drives


Some applications have requirement that they need some mapped location either at the beginning or at any time in between their execution. They will not behave properly in the absence of the mapped locations. Sometimes they need it to get some files/data or to save some file/data onto that location.

To implement this requirement in XenApp, we have write VBScript to map the network location to some drive and then we have to publish it in XenApp.

Note:The drive which is going to be used for mapping purpose should not be used by other application or should not be reserved one like V drive {mapped to C drive of XenApp}, X drive {roaming profile drive}, C drive, D drive {may be CD drive}. If used/non reserved drives are used, then it might brake other application using those drives. if the reserved drives are used in VBScript, then mapping will not happen.

Prerequisite:

Users should have required access rights {atleast “read” access} on to the network location.

Below is the content of VBScript:

Logic:
  1. We are checking, if H drive is already mapped
  2. If it is already in use i.e. mapped, we have removed its mapping.
  3. Finally, we are mapping H drive to the required network location “\\Server\Share”.
  4. Launching the Notepad application.
'==========================================================================

' NAME: NetworkMap.vbs

'

' AUTHOR: Mohd Aslam

' DATE  : 06/09/2010

'

' COMMENT: 

' This script maps H drive to "\\Server\Share" and then launch Notepad exe

'==========================================================================

Dim objFSO, objNetwork, WshShell

 

Set WshShell = WScript.CreateObject("WScript.Shell")

set objFSO = CreateObject("Scripting.FileSystemObject")

Set objNetwork = CreateObject("WScript.Network")

 

'-----------------------------------------------------------------

'If the "H" drive is already mapped, disconnect the mapping

 

If (objFSO.DriveExists("H:")) Then

objNetwork.RemoveNetworkDrive "H:", True, True

End If

'-----------------------------------------------------------------

objNetwork.MapNetworkDrive "H:" , "\\Server\Share"

 

If Err.Number<>0 Then    

MsgBox "Error in mapping drive!!!!"

MsgBox "Error #" & Err.Number & " " & Err.Description

End If

 

'-----------------------------------------------------------------

'Execute the Notepad program

'-----------------------------------------------------------------

WshShell.Run "C:\Windows\notepad.exe"

 

If Err.Number<>0 Then    

MsgBox "Unable to launch Notepad program !"

MsgBox "Error #" & Err.Number & " " & Err.Source & " " & Err.Description

End If

 

set WshShell = Nothing

Now in XenApp, we just need to publish this VBScript.

It can be published in XenApp as shown below:

Note: For more information on publishing in XenApp, refer to my article https://mdaslam.wordpress.com/2010/06/10/application-publish-in-xenapp/

 image

To test it, if it is working as expected, Launch the published Notepad and click on the menu {File –> Open}. “Open” window will appear. Go to the dropdown list “Look in” and see if the mapped network drive is available or not. It should be available here.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s