No announcement yet.

Maping Network drive.

  • Filter
  • Time
  • Show
Clear All
new posts

  • Maping Network drive.


    i'm trying to create a batch file that maps the specific "home" folder per user.
    it used to work but i've added "net use * /del /y" (in order to auto delete old folders).
    in the AD under "profile" the home folder sets under the right folder but when the logon script is runing the folder don't get remaped and when i manually run the batch file the general folder is the one that geting maped and not the specific user home folder.
    for exp: \\fs\users\%username%
    onley the - "users" folder geting maped instaed of the %username% folder.
    and any ida why after runing "del /*" the folders not geting remaped?

    thank's ahed for any advice

    good day,

    BTW - i'm maping the folder using the "NET USE" command

    NET USE K: \\fs\K /y
    Last edited by Rems; 22nd September 2009, 09:12.

  • #2
    Re: Maping Network drive.

    Originally posted by sheriden
    BTW - i'm maping the folder using the "NET USE" command

    NET USE K: \\fs\K /y
    I know that when I would use: NET USE K: /home ONLY the shared folder itself would be mapped to a driveletter and not directly to one of its targeted subfolders. That does somewhat look like what happed by your script.
    Also, note that Names from a network path might include embedded spaces, therefore I always wrap quote-signs around path strings.
    And finally, check for the correct values of the environment variables %HOMEDRIVE% and %HOMESHARE% set for the current user.

    Try solving the issue by mapping the actual UNC path:

    OR, if the required user environment variables are both updated correctly from AD then you can best use:

    btw AFAIK net use * /D /Y should normally not be able to un-map the HOMESHARE unless it has manually been disconnected and re-created before.

    The sample below use those two environment variables of the user for re-mappining the HOME share, but not when the HOMESHARE does not end with the USERNAME in that case it will use the path and driveletter hardcoded in the script.
    *Additionally*... the batch offers you an option to re-name the drive name (set by the last line in the batch) in Windows Explorer, so user's wont be able to reveal the actual UNC or DFS path.
    ::# This Logon batch will:
    ::# 1. Disconnect all drives that previously
    ::#    were mapped. (it can not un-map
    ::#    drives that were mapped by and have
    ::#    a handle by the system!!)
    ::# 2. Give the user's mapped HOME-drive
    ::#    a new name (custom label)
    @echo off & setlocal ENABLEEXTENSIONS
    ::# Disconnect currently mapped dives
    ::# (will not delete drives like tsclient-folders and homedrive)
    net use * /D /Y
    ::# As preference the in the AD-account's Profile
    ::# configured HOME networkSHARE will be used. 
    ::# But, when HOMESHARE is not properly defined
    ::# then map the following driveletter:
    SET "strDriveletter=K:"
    ::#  TO this networkpath:
    SET "strUNC=\\fs\users\%USERNAME%"
    ::# as an alternative.
    ::# check the HOMESHARE variable
    ::# (expected to be a networkpath that ends with the user's name!)
    Set HOMESHARE |Findstr /ie "%USERNAME%" ||(
      If NOT exist "%strUNC%" MKDIR "%strUNC%"
      echo\programmatically set: %strUNC% [%strDriveletter%]
      Set "HOMESHARE=%strUNC%"
      Set "HOMEDRIVE=%strDriveletter%")
    ::# Home drive's target will be cached in this subKey, 
    Set "regKey=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2"
    Set "subKey=%HOMESHARE:\=#%"
    ::# Clear the mountpoints cache of *any* previously sharedfolders mapping
    For /f "delims=" %%* in (
       'REG QUERY "%regKey%" ^|Findstr /ib "%regKey%\\#\#"'
       ) do REG DELETE "%%*" /f
    ::# Restore mapping to Homeshare (if not already is present)
    ::# Optionally, configure a custom name for its drive label..
    REG ADD "%regKey%\%subKey%" /f /v "_LabelFromReg" /d "HomeDrive '%USERNAME%'"
    Last edited by Rems; 22nd September 2009, 07:45.

    This posting is provided "AS IS" with no warranties, and confers no rights.


    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts


    • #3
      Re: Maping Network drive.

      Thank u !!!!
      it worked perfectly

      good day