Create symlink without admin mode
-
kiwichick
- Posts: 673
- Joined: 08 Aug 2012 04:14
- Location: Windows 10 Pro 22H2, 150% scaling
Create symlink without admin mode
Is there any way to create a symlink without having XY run as administrator?
Windows 10 Pro 22H2
-
Horst
- Posts: 1374
- Joined: 24 Jan 2021 12:27
- Location: Germany
Re: Create symlink without admin mode
No, that's a Windows restriction..
Unfortunately, XY doesn't just ask using a UAC prompt for this operation
which would be a big improvement.
Unfortunately, XY doesn't just ask using a UAC prompt for this operation
which would be a big improvement.
Windows 11 Home, Version 25H2 (OS Build 26200.8457)
Portable x64 XYplorer (Actual version, including betas)
Display settings 1920 x 1080 Scale 100%
Everything 1.5.0.1412b (x64), Everything Toolbar 2.3.0, Listary Pro 6.3.6.99
Portable x64 XYplorer (Actual version, including betas)
Display settings 1920 x 1080 Scale 100%
Everything 1.5.0.1412b (x64), Everything Toolbar 2.3.0, Listary Pro 6.3.6.99
-
admin
- Site Admin
- Posts: 66083
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Create symlink without admin mode
Will be possible with multi-threading.
FAQ | XY News RSS | XY X
-
kiwichick
- Posts: 673
- Joined: 08 Aug 2012 04:14
- Location: Windows 10 Pro 22H2, 150% scaling
Re: Create symlink without admin mode
Thanks, Don, that's good to know. Is that something that will be available with XYplorerTB?
Windows 10 Pro 22H2
-
kiwichick
- Posts: 673
- Joined: 08 Aug 2012 04:14
- Location: Windows 10 Pro 22H2, 150% scaling
Re: Create symlink without admin mode
Thanks, I realised that when I tried to create a symlink using command prompt and found it had to be run as administrator. So, is it possible to use XY to create a script that can run the command prompt as administrator and execute mklink code?
Windows 10 Pro 22H2
-
admin
- Site Admin
- Posts: 66083
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Create symlink without admin mode
Yes, not immediately but it's planned.
FAQ | XY News RSS | XY X
-
noembryo
- Posts: 231
- Joined: 13 Apr 2022 21:40
- Location: Windows 10 @100%
- Contact:
Re: Create symlink without admin mode
Without knowing any context on this question, one answer might be: "By using the Link Shell Extension"
Check my free programs here..
-
kiwichick
- Posts: 673
- Joined: 08 Aug 2012 04:14
- Location: Windows 10 Pro 22H2, 150% scaling
Re: Create symlink without admin mode
I don't know what 'context' you want but XY scripting can create a symlink. However, XY has to be in run as administrator in order to do it. I just wanted to know if there was any way to do it without XY as admin.
Windows 10 Pro 22H2
-
highend
- Posts: 14923
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Create symlink without admin mode
Write out a .bat script (and run it afterwards) that self-elevates and executes the mklink command?
Code: Select all
$batFile = "%TEMP%\~xyplorer_mklink.bat";
$batContent = <<<>>>
@ECHO OFF
REG QUERY "HKU\S-1-5-19" >NUL 2>NUL && GOTO :ENDUAC
SET "vbsFile=%TEMP%\~getAdmin.vbs"
IF "%1" NEQ "" (FOR /F "tokens=*" %%I IN ('ECHO %*') DO SET "param=%%~I")
ECHO Set UAC = CreateObject^("Shell.Application"^)> "%vbsFile%"
ECHO UAC.ShellExecute "cmd", "/c """"%~s0"" ""%param%""""", "", "runas", ^1>> "%vbsFile%"
CSCRIPT "%vbsFile%" //Nologo
IF EXIST "%vbsFile%" DEL /Q "%vbsFile%" >NUL 2>NUL
EXIT /B
:ENDUAC
>>>;
$batContent .= <crlf 2> . "your mklink stuff here...";
writefile($batFile, $batContent, , "utf8");
run $batFile, "%TEMP%", 0, 1;
One of my scripts helped you out? Please donate via Paypal
-
noembryo
- Posts: 231
- Joined: 13 Apr 2022 21:40
- Location: Windows 10 @100%
- Contact:
Re: Create symlink without admin mode
This is exactly the context I needed.
Do you want to create a symlink, or you want to create a symlink by scripting?
My answer was for the former (it's the way I create symlinks in XYplorer without having administrator rights), but unfortunately you wanted an answer for the latter..
Check my free programs here..
-
kiwichick
- Posts: 673
- Joined: 08 Aug 2012 04:14
- Location: Windows 10 Pro 22H2, 150% scaling
Re: Create symlink without admin mode
Yes it was for the latter. My apologies for not being clear about that.noembryo wrote: ↑09 May 2025 18:04 This is exactly the context I needed.
Do you want to create a symlink, or you want to create a symlink by scripting?
My answer was for the former (it's the way I create symlinks in XYplorer without having administrator rights), but unfortunately you wanted an answer for the latter..
Windows 10 Pro 22H2
-
kiwichick
- Posts: 673
- Joined: 08 Aug 2012 04:14
- Location: Windows 10 Pro 22H2, 150% scaling
Re: Create symlink without admin mode
Thankshighend wrote: ↑09 May 2025 11:01 Write out a .bat script (and run it afterwards) that self-elevates and executes the mklink command?
Code: Select all
$batFile = "%TEMP%\~xyplorer_mklink.bat"; $batContent = <<<>>> @ECHO OFF REG QUERY "HKU\S-1-5-19" >NUL 2>NUL && GOTO :ENDUAC SET "vbsFile=%TEMP%\~getAdmin.vbs" IF "%1" NEQ "" (FOR /F "tokens=*" %%I IN ('ECHO %*') DO SET "param=%%~I") ECHO Set UAC = CreateObject^("Shell.Application"^)> "%vbsFile%" ECHO UAC.ShellExecute "cmd", "/c """"%~s0"" ""%param%""""", "", "runas", ^1>> "%vbsFile%" CSCRIPT "%vbsFile%" //Nologo IF EXIST "%vbsFile%" DEL /Q "%vbsFile%" >NUL 2>NUL EXIT /B :ENDUAC >>>; $batContent .= <crlf 2> . "your mklink stuff here..."; writefile($batFile, $batContent, , "utf8"); run $batFile, "%TEMP%", 0, 1;
Windows 10 Pro 22H2
-
WirlyWirly
- Posts: 312
- Joined: 21 Oct 2020 23:33
- Location: XY 64-Bit | Win 10 @ 100% (3440x1440)
Re: Create symlink without admin mode
Thanks @highend, you saved me a lot of head scratching as I'm getting into symlinks
For anyone interested, I took highend's script and adjusted it slightly so that it will generate a symlink for every currently selected item. There's enough logic to differentiate between file/folder and format
mklink appropriately.Code: Select all
// Generate symlinks for each File/Folder currently selected.
// Elevates cmd to admin
$outputPrefix = 'link-';
// ================================ CODE ================================
$batFile = "<xydata>\Temp\symlinkGenerator.bat";
$batContents = <<<STRING
@ECHO OFF
REG QUERY "HKU\S-1-5-19" >NUL 2>NUL && GOTO :ENDUAC
SET "vbsFile=<xydata>\Temp\~getAdmin.vbs"
IF "%1" NEQ "" (FOR /F "tokens=*" %%I IN ('ECHO %*') DO SET "param=%%~I")
ECHO Set UAC = CreateObject^("Shell.Application"^)> "%vbsFile%"
ECHO UAC.ShellExecute "cmd", "/c """"%~s0"" ""%param%""""", "", "runas", ^1>> "%vbsFile%"
CSCRIPT "%vbsFile%" //Nologo
IF EXIST "%vbsFile%" DEL /Q "%vbsFile%" >NUL 2>NUL
EXIT /B
:ENDUAC
STRING;
foreach($item, <selitems :::>, ':::') {
// Format 'mklink' depending on $item type (file|folder)
$itemDirectory = getpathcomponent($item, 'path');
$itemFilename = getpathcomponent($item, 'name');
if (exists($item) == '1') {
// $item is file
$command = lax(mklink "$itemDirectory\$outputPrefix$itemFilename" "$item");
$batContents .= <crlf> . $command;
} elseif (exists($item) == '2') {
// $item is folder
$command = lax(mklink /D "$itemDirectory\$outputPrefix$itemFilename" "$item");
$batContents .= <crlf> . $command;
}
}
writefile($batFile, $batContents, , "utf8");
run($batFile, , 0, 0);
You do not have the required permissions to view the files attached to this post.
-
kiwichick
- Posts: 673
- Joined: 08 Aug 2012 04:14
- Location: Windows 10 Pro 22H2, 150% scaling
Re: Create symlink without admin mode
Thanks for that but am I missing something? Do I need to do anything other than select a folder and run the script? I tried that and the symlink wasn't created. The bat file created by the script seems to have the correct information.WirlyWirly wrote: ↑20 May 2025 23:50 I took highend's script and adjusted it slightly so that it will generate a symlink for every currently selected item. There's enough logic to differentiate between file/folder and formatmklinkappropriately.
Code: Select all
// Generate symlinks for each File/Folder currently selected. // Elevates cmd to admin $outputPrefix = 'link-'; // ================================ CODE ================================ $batFile = "<xydata>\Temp\symlinkGenerator.bat"; $batContents = <<<STRING @ECHO OFF REG QUERY "HKU\S-1-5-19" >NUL 2>NUL && GOTO :ENDUAC SET "vbsFile=<xydata>\Temp\~getAdmin.vbs" IF "%1" NEQ "" (FOR /F "tokens=*" %%I IN ('ECHO %*') DO SET "param=%%~I") ECHO Set UAC = CreateObject^("Shell.Application"^)> "%vbsFile%" ECHO UAC.ShellExecute "cmd", "/c """"%~s0"" ""%param%""""", "", "runas", ^1>> "%vbsFile%" CSCRIPT "%vbsFile%" //Nologo IF EXIST "%vbsFile%" DEL /Q "%vbsFile%" >NUL 2>NUL EXIT /B :ENDUAC STRING; foreach($item, <selitems :::>, ':::') { // Format 'mklink' depending on $item type (file|folder) $itemDirectory = getpathcomponent($item, 'path'); $itemFilename = getpathcomponent($item, 'name'); if (exists($item) == '1') { // $item is file $command = lax(mklink "$itemDirectory\$outputPrefix$itemFilename" "$item"); $batContents .= <crlf> . $command; } elseif (exists($item) == '2') { // $item is folder $command = lax(mklink /D "$itemDirectory\$outputPrefix$itemFilename" "$item"); $batContents .= <crlf> . $command; } } writefile($batFile, $batContents, , "utf8"); run($batFile, , 0, 0);
Windows 10 Pro 22H2
-
jupe
- Posts: 3446
- Joined: 20 Oct 2017 21:14
- Location: Win10 22H2 120dpi
Re: Create symlink without admin mode
If you wanted you could achieve this with a one liner, with no temp files. eg.
As the script is currently it is just for using in normal folders or non-recursive search results, you'd need to modify it if you wanted it to work in multi hierarchy search results.
Code: Select all
e|open """<xy>"" /fresh /win=min /script=|::". report('new("link-{Name}", "symlink", "{Fullname}"); ', 1) ."exit n;| ""<curpath>""", e;
XYplorer Beta Club