Skip to content

Instantly share code, notes, and snippets.

@netbootdau
Created December 10, 2017 22:12
Show Gist options
  • Save netbootdau/5343641625ed1e9ac093777a3de9f2e2 to your computer and use it in GitHub Desktop.
Save netbootdau/5343641625ed1e9ac093777a3de9f2e2 to your computer and use it in GitHub Desktop.
Batch file for establishing a WebDAV connection and bind it to a drive letter (non-persistent).
@echo off
:REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:REM
:REM Batch file for establishing a WebDAV connection and bind it to a drive
:REM letter (non-persistent).
:REM
:REM Please adopt WEBDAV_HOST and WEBDAV_USER to your needs as well as the
:REM default password. You also might want to adopt the default drive the
:REM WebDAV connection should be bound to.
:REM
:REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:REM ~~~~~~~~~~
:REM PARAMETERS
:REM ~~~~~~~~~~
set WEBDAV_HOST=http://your.webdav.host/somedrive
set WEBDAV_USER=YourUsername
:REM Use "*" to let "net use" ask you for the password. You might
:REM change this to the real password but mind that this is a security risk.
set WEBDAV_PASSWORD=*
set DRIVE=X:
if exist %DRIVE% (
echo Drive %DRIVE% already in use. Choosing the next free one...
set DRIVE=*
)
:REM ~~~~~~~~~~~~~~~~~~~~
:REM Establish Connection
:REM ~~~~~~~~~~~~~~~~~~~~
echo Establishing connection to "%WEBDAV_HOST%" for "%WEBDAV_USER%"...
echo.
net use "%DRIVE%" "%WEBDAV_HOST%" /User:"%WEBDAV_USER%" "%WEBDAV_PASSWORD%" /persistent:no
if not errorlevel 1 (
echo.
net use
)
:END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment