黑料海角91入口

Map a Network Drive

This article details how to map a network drive upon login using a registry entry and a batch file, without needing to store a password in plain text. The batch file that you create and upload to the command builds a netuse.bat file automatically to map drives when the user logs in to their device.

Prerequisites:

  • This command works on Windows devices only.
  • This method applies to file servers with NTFS permissions, AD file servers, and any NAS device, as long as the username and password on the device matches the username and password on the end user鈥檚 device.

Considerations:

  • The example used in this article will:
    • Create a registry entry key named mapdrive that will run a script (c:\scripts\netuse.bat) every time a user logs in.
    • Delete any old version of c:\scripts\netuse.bat that exists.
    • Generate the netuse.bat file that contains the actual drive map commands and save it to c:\scripts\.
  • The example variables should be edited to specify the desired drive letter, file server/NAS address, and share name.
  1. Create the batch file (setnetdrive.bat), replacing the variables as necessary:

echo off
reg add hklm\software\microsoft\windows\currentversion\run /v mapdrive /t REG_SZ /d c:\scripts\netuse.bat /fmkdir c:\scripts
echo net use * /delete /yes > c:\scripts\netuse.bat
echo net use f: "\\fileserver\share" /user:%%username%% >>
echo net use g: "\\fileserver\share" /user:%%username%% >>
 c:\scripts\netuse.bat

Note:

If the file server is an Active Directory member file server, then add the DOMAIN NAME before the %%username%% variable:

echo net use f: "\\fileserver\share" /user:DOMAIN\%%username%%

For example, if the file server is 10.10.10.10, share name is 鈥淔inance,鈥 and AD domain is 鈥淐ontoso.Local鈥 the command would look like this:

echo net use f: "\\10.10.10.10\Finance" /user:CONTOSO\%%username%%

  1. In the 黑料海角91入口 Admin Portal, go to DEVICE MANAGEMENT > Commands
  2. Click + and choose Command.
  3. Enter the following Details:
    • For Name, enter a name that is identifiable to you.
    • For Type, select Windows.
      • Ensure the Windows Powershell option remains unchecked.
    • In the Command* field, enter  cmd.exe /c c:\windows\temp\setnetdrive.bat.
  4. Under Launch Event, set the Event to Manually to run once per device.
  5. (Optional) Under Options, configure the command鈥檚 timeout settings appropriately, or leave the default settings.
  6. Under Files, click Upload File.
  7. Upload the setnetdrive.bat file you created in step 1. Ensure the File Destination is listed as c:\Windows\Temp\setnetdrive.bat.
  8. Assign the command to the device or device group where you want to apply the registry entry.
    • From the Device Groups tab, select one or more device groups. For device groups with multiple OS member types, the policy is applied only to the supported OS.
    • From the Devices tab, select one or more devices.
  9. Click Save
  10. From the Commands list, find the command and click Run Now to execute the setnetdrive.bat file on all selected devices.
  11. The registry entry is applied and the netuse.bat file is built on the end device, and will be run every time a user logs into that device.

Additional Resources

Enroll:

Blog: Accessing File Shares on AD-Connected Windows File Servers

Back to Top

Still Have Questions?

If you cannot find an answer to your question in our FAQ, you can always contact us.

Submit a Case