Citrix: Drive Mapping Script – Sample

Posted on

‘************************************************
‘ File:     MFDRIVES.vbs  
‘ Author:   Deddy Iswara
‘************************************************
Option Explicit

Dim WshShell
Dim objEnv
Dim Syntax
Dim ObjArgs
Dim InputBoxCancel
Dim InputBoxOK
Dim tmp
Dim WSHNetwork
Dim Share
Dim Drive

Const SERVER=”\\CLIENT\

Set objArgs  = WScript.Arguments
InputBoxCancel  = “User input canceled!”
InputBoxOK  = “You entered:” & vbCrLf
Const ForWriting = 2
Syntax = “Syntax:” & vbCrLf
Syntax = Syntax & “MFDRIVE [Drive Letter]” & vbCrLf
Syntax = Syntax & “MFDRIVE supports mapping local drivers C: – F:” & vbCrLf & vbCrLf
Syntax = Syntax & “Example:  MFDRIVE A” & vbCrLf
Syntax = Syntax & “Maps the \\CLIENT\A$ to A:” & vbCrLf & vbCrLf
Syntax = Syntax & “Example:  MFDRIVE C” & vbCrLf
Syntax = Syntax & “Maps the \\CLIENT\C$ to V:” & vbCrLf & vbCrLf

if ObjArgs.Count <= 0 then
   tmp = MsgBox(Syntax, 0, “Syntax”)
   wScript.quit 1
else
   Share = SERVER + ObjArgs(0) + “$”
   Select Case UCase(ObjArgs(0))
      Case “A”
         Drive = “A:”
      Case “B”
         Drive = “B:”
      Case “C”
         Drive = “V:”
      Case “D”
         Drive = “U:”
      Case “E”
         Drive = “S:”
      Case “F”
         Drive = “R:”
      Case Else
         tmp = MsgBox(“The Zeus utility only supports mapping drivers C: – F:.  The ” + Ucase(ObjArgs(0)) + “: drive is not supported.”, 0+16, “MFDRIVES Error”)
         Wscript.quit 1
   End Select
   ‘wscript.echo share
   ‘Wscript.echo Drive
   set WsHNetwork = CreateObject(“WScript.Network”)
   On Error Resume Next
   WshNetwork.MapNetworkDrive Drive, Share, FALSE
   ‘wscript.echo Err.Number
   Select Case Err.Number
     Case -2147024841
        tmp = MsgBox(“The ” + UCase(Drive) + ” does not exist on your local PC.”, 0+16, “MFDRIVES Error”)
        Wscript.Quit 1
     Case -2147024811
        tmp = MsgBox(“The ” + UCase(Drive) + ” is already in use.”, 0+16, “MFDRIVES Error”)
        Wscript.Quit 1
     ‘Case Else
         ‘tmp = MsgBox(“An unexpected error occured. ” + Err.Number, 0+16, “MFDRIVES Error”)
         ‘wscript.echo Err.number
         ‘Wscript.Quit 1
   End Select
   On Error goto 0

   tmp = MsgBox(“Your local ” + Ucase(ObjArgs(0)) + “: drive has been mapped to ” + UCase(Drive) + “.”, 0+64, “MFDRIVES Error”)

End If

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