«

»

Jun 09 2010

Local Drive Mapping with VMware View and PCoIP

Teradici PCoIP was built from ground up to be a very efficient display protocol. Later on Teradici introduced Local Pointers to the protocol, allowing it to be used over the WAN with extreme efficiency. PCoIP will always deliver the best possible user experience utilising the total bandwidth available.

Because PCoIP was designed to achieve the best throughput on constrained networks some bandwidth hungry features have not been implemented on the protocol at this stage. VMware View also supports other display protocols such as RDP and RGS.

I have put together a vbscript (more like a compilation of scripts) to automate drive or cdrom mapping trough the network using SMB/CIFS. The script utilise VMware View volatile variables to connect to the workstation’s IP address.

Execute the script either manually or during logon time and make sure the local cdrom or local drive is shared with the required permissions. The share name should reflect the strRemotePath in the script.

 

Option Explicit
Dim strDriveLetter, strRemotePath
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive

Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()

strDriveLetter = "L:"
strRemotePath="\\"&objShell.ExpandEnvironmentStrings("%ViewClient_IP_Address%")&"\cdrom"

On Error Resume Next
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count – 1 Step 2
If CheckDrive.Item(intDrive) =strDriveLetter _
Then AlreadyConnected =True
Next

If AlreadyConnected = True then
objNetwork.RemoveNetworkDrive strDriveLetter
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath

objShell.PopUp "Drive " & strDriveLetter & _
"Disconnected, then connected successfully."
Else
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
objShell.PopUp "Drive " & strDriveLetter & _
" connected successfully." End if
WScript.Quit

 

DISCLAIMER: I provide this script to you “as is” without warranties or conditions of any kind.

16 comments

Skip to comment form

  1. Breisch

    Each time I run the script, I get the following error message:

    Line: 15
    Char: 38
    Error: Invalid Character
    Code: 800A0408
    Source: Microsoft VBScript compilation error

    Do you have any ideas? It seems to be around the “- 1” that is throwing the error.

  2. Andre Leibovici

    If you open your command prompt and set SET you should see the VMware View volatile variables. It should look like %ViewClient_IP_Address%.

    If you don’t see that most likely your VMware View environment is missing the ADM templated to be loaded onto the Group Policies or there is an issue with you VMware View Agent (try re-installing)

    The script uses this volatile variable to map the local drive.

  3. Breisch

    I see the %ViewClient_IP_Address% variable just fine when using the set command. Actually from my VM, I can go to Start, Run, and type \\%ViewClient_IP_Address%\CDROM and can pull up the contents of the cd in the drive. It seems to work great, but when using the script, I get the following error each time”

    Line 15, Char 38 is the following:
    For intDrive = 0 To CheckDrive.Count – 1 Step 2

    It seems that the problem is coming somewhere between “Count – 1”
    I have uninstalled/reinstalled the view agent.
    Do you have any suggestions?

  4. Breisch

    I found another problem. Not with your script, but with the way the variables are set from VMWare. If you reboot or log off of a vm and then log back in, the VMWare variables are not set at all. You must first disconnect from your session, (not reboot or log off), and then log back into the currently running session in order for the VMWare variables to map.
    I’ve tested it both ways:
    1. Rebooted and logged into the vm – The variables are not set. Disconnected and logged back in and the variables are set correctly.
    2. Logged off (not disconnect) and logged into the vm – The variables are not set. Disconnected and logged back in and the variables are set correctly.

    Have you run into this at all during your testing?

  5. Andre Leibovici

    @Breishc, tanks for your note. I actually have seen this behavior before but I don’t know the root cause of the issue. I’ll see if I can get some more information on that.

  6. Andre Leibovici

    @Breisch
    This information can be gathered every time you log in, so if a user changes location, you can see that change in the variables. This can be run with the CommandsToRunOnConnect once the VDM_AGENT.ADM template has been configured in your AD and you have assigned the polices for CommandToRunOnConnect and/or CommandToRunOnReconnectoption.

    You will find additional information at Location Awareness in VMware View 4 document.

  7. Q

    I run a modified version of this in VMware View 5 client and get a successful message, but the drive doesn’t appear in My Computer. Any ideas?

    Here’s my modified code to use the registry instead of environment variables:

    Option Explicit
    Dim strComputer, strKeyPath, strValueName, strLocalComputerIP
    Dim strDriveLetter, strRemotePath
    Dim objNetwork, objShell, objReg
    Dim CheckDrive, AlreadyConnected, intDrive

    ‘——————————————————————
    ‘ Get the IP address of the local machine.

    ‘ Magic number
    const HKEY_CURRENT_USER = &H80000001
    strComputer = “.”

    ‘ Open the registry.
    Set objReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” &_
    strComputer & “\root\default:StdRegProv”)

    ‘ Extract the IP address of the local computer.
    strKeyPath = “Volatile Environment”
    strValueName = “ViewClient_IP_Address”
    objReg.GetExpandedStringValue HKEY_CURRENT_USER,strKeyPath,_
    strValueName,strLocalComputerIP

    ‘—————————————————————–
    ‘ Connect the local drive to a mapped drive.

    ‘ Open the shell and network.
    Set objShell = CreateObject(“WScript.Shell”)
    Set objNetwork = CreateObject(“WScript.Network”)
    Set CheckDrive = objNetwork.EnumNetworkDrives()

    objShell.PopUp “Remote IP is ” & strLocalComputerIP & “.”

    ‘ Construct the drive paths.
    strDriveLetter = “L:”
    strRemotePath=”\\”&strLocalComputerIP&”\c\”

    ‘ Start trying to map the local computer’s C: drive.
    On Error Resume Next
    AlreadyConnected = False
    For intDrive = 0 To CheckDrive.Count – 1 Step 2
    If CheckDrive.Item(intDrive) =strDriveLetter _
    Then AlreadyConnected =True
    Next

    ‘——————————————————————
    ‘ Inform user of result.

    If AlreadyConnected = True then
    objNetwork.RemoveNetworkDrive strDriveLetter
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
    objShell.PopUp “Drive ” & strDriveLetter & _
    “Disconnected, then connected successfully.”
    Else
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
    objShell.PopUp “Drive ” & strDriveLetter & _
    ” connected successfully.” End if

    WScript.Quit

  8. Q

    I figured out the problem with my script. The line:

    strRemotePath=”\\”&strLocalComputerIP&”\c\”

    should read:

    strRemotePath=”\\”&strLocalComputerIP&”\c”

    Also, there’s a much simpler way to get the registry entry with a call to objShell.RegRead, but the above should work.

  9. Rob

    Is there a way to achieve this for remote users that are not directly on the network?

  10. Andre Leibovici

    @Rob
    Perhaps possible but you would need t expose the CIFS share on the internet, and the users would need to be connected to the internet. I would not recommend something like that. If you need file shares exposed to users while away from the office, please consider using something like FTP or WebDAV.

    Andre

  11. Quim

    Both scripts work for me, but only when I changed “\cdrom” for “\c$” for the first script, and “\c” for “\c$” in the second script. (I need the ‘C’ unit, not cdrom)

    A part from that, I had also Breisch problem, which I solved rewritten the “-” sign, as sometimes copy-pasting has some problems with punctuation symbols. I also had to change all the “-” and quotes in Q’s script, as they were giving errors to me as well.

    In addition, make sure you have permissions on that unit (if it requires credentials it won’t be mapped).

    Now the challenge would be writing a single script that connected all the local units available (cdrom, C, D, E, F…)

    Salut!

  12. Andre Leibovici

    @Quim
    Would you like to send me the final script to I can update the article?

    Andre

  13. Quim

    Yes, sure.

    By the way, I also had problems in some network restrictions. So in case of problems, make sure you can do the mapping manually before blaming on the script.

    Your Script:


    Option Explicit
    Dim strDriveLetter, strRemotePath
    Dim objNetwork, objShell
    Dim CheckDrive, AlreadyConnected, intDrive

    Set objShell = CreateObject(“WScript.Shell”)
    Set objNetwork = CreateObject(“WScript.Network”)
    Set CheckDrive = objNetwork.EnumNetworkDrives()

    strDriveLetter = “L:”
    strRemotePath=”\\”&objShell.ExpandEnvironmentStrings(“%ViewClient_IP_Address%”)&”\c$”

    On Error Resume Next
    AlreadyConnected = False
    For intDrive = 0 To CheckDrive.Count – 1 Step 2
    If CheckDrive.Item(intDrive) =strDriveLetter _
    Then AlreadyConnected =True
    Next

    If AlreadyConnected = True then
    objNetwork.RemoveNetworkDrive strDriveLetter
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath

    objShell.PopUp “Drive ” & strDriveLetter & _
    “Disconnected, then connected successfully.”
    Else
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
    objShell.PopUp “Drive ” & strDriveLetter & _
    ” connected successfully.” End if
    WScript.Quit

    Q’s script:

    Option Explicit
    Dim strComputer, strKeyPath, strValueName, strLocalComputerIP
    Dim strDriveLetter, strRemotePath
    Dim objNetwork, objShell, objReg
    Dim CheckDrive, AlreadyConnected, intDrive

    const HKEY_CURRENT_USER = &H80000001
    strComputer = “.”

    Set objReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” &_
    strComputer & “\root\default:StdRegProv”)

    strKeyPath = “Volatile Environment”
    strValueName = “ViewClient_IP_Address”
    objReg.GetExpandedStringValue HKEY_CURRENT_USER,strKeyPath,_
    strValueName,strLocalComputerIP

    Set objShell = CreateObject(“WScript.Shell”)
    Set objNetwork = CreateObject(“WScript.Network”)
    Set CheckDrive = objNetwork.EnumNetworkDrives()

    objShell.PopUp “Remote IP is ” & strLocalComputerIP & “.”

    strDriveLetter = “L:”
    strRemotePath=”\\”&strLocalComputerIP&”\c$”

    On Error Resume Next
    AlreadyConnected = False
    For intDrive = 0 To CheckDrive.Count – 1 Step 2
    If CheckDrive.Item(intDrive) =strDriveLetter _
    Then AlreadyConnected =True
    Next

    If AlreadyConnected = True then
    objNetwork.RemoveNetworkDrive strDriveLetter
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
    objShell.PopUp “Drive ” & strDriveLetter & _
    “Disconnected, then connected successfully.”
    Else
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
    objShell.PopUp “Drive ” & strDriveLetter & _
    ” connected successfully.” End if

    WScript.Quit

    Salut!

  14. Andre Leibovici

    @Quim
    Thanks for sharing with us!

    Andre

  15. Ethan

    Is this script work with the PCoIP Gateway? I have tested this script but not work with PCoIP Gateway.

  16. Andre Leibovici

    Hi Ethan, I have never tried the script with the new PCoIP gateway. – Andre

Leave a Reply