Created
November 8, 2015 07:25
-
-
Save 0x60df/0f8f76bd24ce0b054a06 to your computer and use it in GitHub Desktop.
Windows bat file for creating symbolic link without cmd(run as administrator).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal | |
set invalidUsage=false | |
if "%1"=="" set invalidUsage=true | |
if "%2"=="" set invalidUsage=true | |
if "%invalidUsage%"=="true" ( | |
echo Usage: ln-s TARGET LINK_NAME | |
exit /b 1 | |
) | |
set target=%1 | |
set linkName=%2 | |
if "%target:~-1,1%"=="\" set target=%target:~0,-1% | |
if "%linkName:~-1,1%"=="\" set linkName=%linkName:~0,-1% | |
if not exist "%target%" ( | |
echo Target^(%target%^) does not found. | |
exit /b 1 | |
) | |
if exist "%linkName%" ( | |
echo Linkname^(%linkName%^) already exists | |
exit /b 1 | |
) | |
if not "%target:~1,1%"==":" set target=%CD%\%target% | |
if not "%linkName:~1,1%"==":" set linkName=%CD%\%linkName% | |
set arguments="/c","mklink","%linkName%","%target%" | |
if exist "%target%\" set arguments=%arguments%,"/d" | |
powershell.exe -Command Start-Process ^ | |
-FilePath "cmd" ^ | |
-ArgumentList %arguments% ^ | |
-Verb Runas | |
endlocal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment