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, intDriveSet 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
NextIf AlreadyConnected = True then
objNetwork.RemoveNetworkDrive strDriveLetter
objNetwork.MapNetworkDrive strDriveLetter, strRemotePathobjShell.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.







14 comments
Skip to comment form ↓
Breisch
06/17/2010 at 12:43 am (UTC -7) Link to this comment
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.
Andre Leibovici
06/17/2010 at 9:30 am (UTC -7) Link to this comment
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.
Breisch
06/18/2010 at 3:54 am (UTC -7) Link to this comment
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?
Breisch
06/19/2010 at 2:56 am (UTC -7) Link to this comment
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?
Andre Leibovici
06/27/2010 at 2:33 pm (UTC -7) Link to this comment
@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.
Andre Leibovici
06/30/2010 at 2:24 pm (UTC -7) Link to this comment
@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.
Q
02/22/2012 at 11:21 am (UTC -7) Link to this comment
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
Q
02/22/2012 at 1:06 pm (UTC -7) Link to this comment
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.
Rob
06/05/2012 at 7:47 am (UTC -7) Link to this comment
Is there a way to achieve this for remote users that are not directly on the network?
Andre Leibovici
06/05/2012 at 2:13 pm (UTC -7) Link to this comment
@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
Quim
08/23/2012 at 7:43 am (UTC -7) Link to this comment
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!
Andre Leibovici
08/24/2012 at 8:46 am (UTC -7) Link to this comment
@Quim
Would you like to send me the final script to I can update the article?
Andre
Quim
08/27/2012 at 1:50 am (UTC -7) Link to this comment
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!
Andre Leibovici
08/31/2012 at 11:35 am (UTC -7) Link to this comment
@Quim
Thanks for sharing with us!
Andre