Create symlink without admin mode

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
kiwichick
Posts: 673
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Create symlink without admin mode

Post by kiwichick »

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

Post by Horst »

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.
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

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

Post by admin »

Will be possible with multi-threading.

kiwichick
Posts: 673
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Create symlink without admin mode

Post by kiwichick »

admin wrote: 07 May 2025 18:32 Will be possible with multi-threading.
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

Post by kiwichick »

Horst wrote: 07 May 2025 10:18 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.
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

Post by admin »

kiwichick wrote: 08 May 2025 03:47
admin wrote: 07 May 2025 18:32 Will be possible with multi-threading.
Thanks, Don, that's good to know. Is that something that will be available with XYplorerTB?
Yes, not immediately but it's planned.

noembryo
Posts: 231
Joined: 13 Apr 2022 21:40
Location: Windows 10 @100%
Contact:

Re: Create symlink without admin mode

Post by noembryo »

kiwichick wrote: 07 May 2025 05:22 Is there any way to create a symlink without having XY run as administrator?
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

Post by kiwichick »

noembryo wrote: 08 May 2025 11:55 Without knowing any context on this question
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: 14924
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Create symlink without admin mode

Post by highend »

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

Post by noembryo »

kiwichick wrote: 09 May 2025 10:53
noembryo wrote: 08 May 2025 11:55 Without knowing any context on this question
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.
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

Post by kiwichick »

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..
Yes it was for the latter. My apologies for not being clear about that.
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

Post by kiwichick »

highend 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;

Thanks 😁👍
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

Post by WirlyWirly »

highend wrote: 09 May 2025 11:01 Write out a .bat script (and run it afterwards) that self-elevates and executes the mklink command?
...
Thanks @highend, you saved me a lot of head scratching as I'm getting into symlinks :biggrin:

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

Post by kiwichick »

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 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);

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.
Windows 10 Pro 22H2

jupe
Posts: 3446
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Create symlink without admin mode

Post by jupe »

If you wanted you could achieve this with a one liner, with no temp files. eg.

Code: Select all

e|open """<xy>"" /fresh /win=min /script=|::". report('new("link-{Name}", "symlink", "{Fullname}"); ', 1) ."exit n;| ""<curpath>""", e;
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.

Post Reply