Group Policy Preference to connect mapped network drive using %ClientName%

  • 316 Views
  • Last Post 10 June 2019
nidhin_ck posted this 04 June 2019

P {margin-top:0;margin-bottom:0;}

Hi Experts,


I'm trying to achieve a solution for the below issue.


When the user connects to terminal servers, they need to connect to a network drive with their Client Machine name. If we put below path in Mapped network drive on GPP, it is not working


\server001.domain.com\xxx\%clientname%


But if we put below path, it is working. But the problem is the shared drive which is getting mapped is with the terminal server name.


\server001.domain.com\xxx\%ComputerName%


Is there any way I can connect network drive with users client machine name instead of the terminal server name.



Order By: Standard | Newest | Votes
bdesmond posted this 04 June 2019

If you open a command prompt and run “Set” from a TS session, is there a variable called ClientName that has their client computer’s name in it?

 



Thanks,

Brian Desmond

 

(w) 312.625.1438 | (c) 312.731.3132

 



 

show

nidhin_ck posted this 04 June 2019

P {margin-top:0;margin-bottom:0;}







Hi Brian,








Yes. It has the Client machine name
























Regards,



Nidhin.CK




show

bdesmond posted this 04 June 2019

I’m not sure if GP Prefs supports arbitrary environment variables or if they have to be from a list:



https://sdmsoftware.com/group-policy-blog/group-policy-preferences/group-policy-preferences-and-environment-variables/

 

Thanks,


Brian



 



 

show

nidhin_ck posted this 04 June 2019

P {margin-top:0;margin-bottom:0;}







I even tried via GPO Logon script. But it is not working. But if I execute the bat file manually after login to TS then it is mapping the drive with the client machine name.



UAC is disabled & also applied EnableLinkedConnections registry key on the terminal server. But no luck 








bat file content:



\domain\NETLOGON\script\MapNetworkDrivesdaas.vbs O:

\server\xx\%clientname%








vbs file content:



Option Explicit




On Error Resume Next




Dim fso,Args, NetMap,oShell




Dim map
letter, mappath, localuser,drive,drivescol









Set fso = CreateObject("Scripting.FileSystemObject")




Set NetMap = CreateObject("Wscript.Network")




Set oShell = CreateObject( "WScript.Shell" )




Set Args = WScript.Arguments









map
letter = Args(0)




mappath = Args(1)









Set drivescol = fso.Drives




For Each drive In drivescol




 If UCase(drive.Path) = UCase(map
letter) Then




 'Remove the drive if exists




 NetMap.RemoveNetworkDrive drive.Path




 End If




Next




NetMap.MapNetworkDrive mapletter,mappath




WScript.Quit
















Regards,



Nidhin.CK




show

bdesmond posted this 04 June 2019

I would have your script log the value of the environment variable to a file or the event log and see if it’s even set at the time you’re running.

 

Thanks,


Brian



 



 

show

zhiaga posted this 04 June 2019

Try this
https://deployhappiness.com/run-in-logged-on-users-security-context/












El martes, 4 de junio de 2019 13:46:04 GMT-5, Brian Desmond <brian@xxxxxxxxxxxxxxxx> escribió:













I would have your script log the value of the environment variable to a file or the event log and see if it’s even set at the time you’re running.

 

Thanks,


Brian



 



 

show

nidhin_ck posted this 04 June 2019

P {margin-top:0;margin-bottom:0;}







I tried that already. Still, it is not accepting %ClientName%













show

webster posted this 04 June 2019

Like Brian Desmond stated, that variable may not be ready at the time your script is running. Follow his suggestion.

 



Thanks

 

 

Carl Webster

Citrix Technology Professional Fellow

| IGEL Tech Community Insider | Parallels VIPP

http://www.CarlWebster.com

The Accidental Citrix Admin



 

show

zhiaga posted this 04 June 2019

Put in script (vbs) in the folder C:\Windows or in another folder where all the users in the server have access.
Generates a bat file that executes the script in this path
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup.
(applies to all users who log in to the computer)
You could also try creating a task programmed by GPO, that will run only when the user starts the session.












El martes, 4 de junio de 2019 14:56:54 GMT-5, Nidhin CK <nidhinck@xxxxxxxxxxxxxxxx> escribió:













I tried that already. Still, it is not accepting %ClientName%















show

ElasticSky posted this 04 June 2019

Hi there,

Sorry not helping but just interested in what scenario there is a requirement to map a drive based on the Workstation people are logging on from?

Kind regards,

Glen

show

jeremyts posted this 10 June 2019

It simply won’t be available in the users environment at the time the GPP executes. You would need to look at writing a logon script using either of the following options:

1)     

Run a delayed logon script using a scheduled task. Not a great option in my opinion.

2)     

Read it directly from the users registry under “HKEYCURRENTUSER\Volatile Environment\<SessionID>”.

3)     

Write some code using the WTSGetActiveConsoleSessionId function.

 

Cheers,

Jeremy

 

show

Close