Skip to content

Instantly share code, notes, and snippets.

@rmtbb
Created March 4, 2026 21:55
Show Gist options
  • Select an option

  • Save rmtbb/28c281dae4e27e71f9623a6c6af9aa9b to your computer and use it in GitHub Desktop.

Select an option

Save rmtbb/28c281dae4e27e71f9623a6c6af9aa9b to your computer and use it in GitHub Desktop.
Persistent Non Intrusive NAS SMB Drive Mapping Script
@echo off
set "DRIVE=Z:"
set "SHARE=\\10.10.10.10\media"
set "USER=USER"
set "PASS=PASSWORD"
rem If Z: exists (mapped or local), do not touch it
if exist %DRIVE%\ (
exit /b 0
)
rem Map only if unused
net use %DRIVE% "%SHARE%" /user:%USER% "%PASS%" /persistent:yes >nul 2>&1
exit /b %errorlevel%
@rmtbb
Copy link
Author

rmtbb commented Mar 4, 2026

1. Save the script

Save your file as C:\Scripts\map-nas.bat

@echo off
if exist Z:\ exit /b
net use Z: \\10.10.10.10\media /user:USER PASSWORD /persistent:yes

2. Open Task Scheduler

  1. Press Start
  2. Search Task Scheduler
  3. Open it

3. Create the task

  1. Click Create Basic Task
  2. Name it: Map NAS
  3. Click Next

4. Trigger

Select:

When I log on

Click Next


5. Action

Select:

Start a program

Click Next

Program/script:

C:\Scripts\map-nas.bat

Click Next → Finish


✅ Done.
Now when the user logs in, it runs the script and only maps Z: if it doesn't already exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment