0

Good evening,

I'm not sure if what I'm attempting to do is possible or not, but I figured I'd put the question out there - in case somebody may have already tried this and been successful.

I am in the process of testing OpenVPN as a possible VPN solution for our mobile employees. I would like to map two network drives - both being Samba shares. One is a general share accessible simply by calling \servername\sharename (that I have no problem with). The second is the user's home drive.

By user I mean, the user who credentials was used to authenticate and create the VPN tunnel. I've already attempted the following in a batch file, but it's not working:

net use u: \\172.23.6.127\%U /persistent:no

I know in Samba I can use the macro (%u) to represent the logged on user, but I'm not sure how to do this in a batch file. Is it even possible?

NOTE: I know that it works if I specify the actual username, but that means I'll have to create and distribute a separate batch file for each user (which I don't mind doing) but if there's a way not to, I'd like to explore it.

Kismet Agbasi
  • 323
  • 1
  • 4
  • 17

1 Answers1

0

One option is to create (but not distribute) a separate login script for each user with the Samba option

logon script = %U.bat

In .BAT files the username should be in the %USERNAME% variable, so your command will be

net use u: \\172.23.6.127\%USERNAME% /persistent:no

An alternative is to use VBscript:

Set wshNetwork = CreateObject("WScript.Network")
wshNetwork.MapNetworkDrive "u:", "\\172.23.6.127\" & wshNetwork.UserName

Or PowerShell (but it must be installed on your clients)

$STRusername = "username" 
$username = (get-item env:$STRusername).Value 
$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive("u:", "\\172.23.6.127\" + $username)
lrosa
  • 1,687
  • 14
  • 15