3

I am trying to create a shortcut in Windows pointing to a folder which does not yet exist, in a remote server to which I cannot write.

I tried creating any shortcut and overwriting the "Target" field, but when I press 'OK' I get an error because the target cannot be found. Laudable, but I'd like to override it.

Does anyone know how to do that?

I can program (Python) if necessary, but I was wondering if a simpler solution exists.

1
  • 1
    No. A simpler solution than Python does not exist :-)
    – user3463
    Commented May 2, 2011 at 15:51

5 Answers 5

1

I don't think this is possible - I tried doing it but it didn't quite work as expected. Here's what I did:

  1. Download Shortcut (note: direct download link) from Optimum X.

    Shortcut allows you to create, modify or query Windows shell links (shortcuts) from the command-line. You can export the properties of an existing shortcut to a text file in .INI format.

  2. Use the following command to create a shortcut (at this stage C:\testfolder didn't exist):

    shortcut /F:example.lnk /A:C /T:C:\testfolder
    

    The lnk file is created and has all the correct properties, but doesn't work yet. I then created C:\testfolder and checked the shortcut. It pops up the Windows Open With dialogue but doesn't resolve properly as a shortcut.

  3. I ran the above command again and the lnk file was updated and now worked as a proper shortcut.

I doubt this will help in terms of a solution, but should at least hint towards this not being possible in a straightforward way.

3

One easy way to do it is to make a shortcut that uses Explorer instead.

For example, I just made a new shortcut and on Windows 7, it asks for "location of the item". I believe it is called Target on Windows XP.

Just put the following as the target/location:

explorer <desired-dir>

If someone runs the shortcut and the directory is not there, it will just open explorer and navigate to the default directory.

If the directory is there, it will open explorer and successfully go to the desired directory.

0

For those using Cygwin, I wrote a bash script to easily create a shortcut on the current user desktop.

It relies on Optimux shortcut, and is part of ~/.bashrc

$ lnk "C:\fakepath\fakefile.xls"

function lnk #Create shortcut on Windows using Optimux bin
{
    printf "\033c"
    echo -e "This function allows you to create a shortcut (symbolic link) pointing to a non-existing file on MS Windows\nIt requires having 'Shortcut.exe' from Optimum X placed in System32\nPlease note you MUST single or double quote the shortcut path:\n\t.e.g:\tlnk \"C:\\MyFake\\Folder\\Pointingto\\anonexisting.file\""

    if [ -z "$1" ]; then
        echo -e "\nType the filename path and press [ENTER]"
        read -p "Filepath :  " filepath
    else
        filepath="$1"
    fi

    filepath=`cygpath "$filepath"`
    filename=`basename "$filepath"`
    dirpath=`dirname  "$filepath"`
    cmd="shortcut /F:\""$USERPROFILE"\\Desktop\\"$filename".lnk\" /A:C /W:\"`cygpath -w "$dirpath"`\" /T:\"`cygpath -w "$filepath"`\""
    echo "$cmd"
    eval "$cmd"
    echo "File created on your Desktop"
} 
0

Here is a script I wrote up combining some other peoples ideas to create a shortcut to a folder even if it does not exist. It makes the folder then deletes the folder. Copy the below text to a .cmd file and run it. I tested this in Windows 10 21H1. I am not sure if it will work in XP.

The only thing you should need to edit is the variables DIR and NAME. If you are creating a file shortcut, make sure to comment out the mkdir %DIR%" line.

@ECHO OFF
REM This script creates a shortcut to a folder and places it on your Desktop.

ECHO Setting Target Path...
set DIR="C:\Folder_Path"

ECHO Setting Name of shortcut
set NAME=Shortcut_Name

ECHO Creating Temporary Directory for Shortcut to match to...
REM If you are creating a file shortcut, comment out this mkdir line to avoid making a folder shortcut.
mkdir %DIR%

ECHO Running Creating VB Script...
REM This is where the temporary VBS file will be located.
set VBS=%USERPROFILE%\Desktop\Create-Icon.vbs
>> %VBS% echo Dim FileName, UploadStac
>> %VBS% echo UploadStac ="Stac Upload"
>> %VBS% echo FileName = "%NAME%"
>> %VBS% echo Set shortcut = CreateObject("WScript.Shell").CreateShortcut(CreateObject("WScript.Shell").SpecialFolders("Desktop") ^& + "\" + FileName + ".lnk")
>> %VBS% echo shortcut.Description = "Description"
>> %VBS% echo shortcut.TargetPath = %DIR%
>> %VBS% echo shortcut.Arguments = ""
>> %VBS% echo shortcut.Save
REM These two lines let the VBS script auto delete itself.
>> %VBS% echo Dim Fso : set Fso = WScript.CreateObject("Scripting.FileSystemObject")
>> %VBS% echo Fso.deleteFile("%VBS%")

ECHO Running VB Script...
REM Everything should clean itself up after this is done.
start %VBS%

REM Timeout is necessary to allow folder shortcut creation.
timeout /T 1

REM rmdir will not delete a folder with something still in it. Do not worry.
rmdir %DIR% /Q
0

It's possible to do that in three steps.

  1. Download AutoIt and create script test.au3 with content:
    ShellExecute("explorer.exe", "X:\Program Files (x86)\Notepad++")
    Here "X:\Program Files (x86)\Notepad++" is a folder which does not yet exist.
  2. Run Aut2exe.exe in AutoIt folder and convert au3 file to exe. Let's say, resulting file would be test.exe
  3. Create shortcut for the test.exe with "Optimum X Shortcut" as described in earlier answer:
    Shortcut.exe /F:"C:\test.lnk" /A:C /T:"C:\Users\Administrator\Desktop\test.exe"
2
  • And this will work even if the OP has no write access to the destination ? Commented Oct 9, 2022 at 0:12
  • It should work because shortcut just opens folder - it doesn't write anything.
    – Zagavarr
    Commented Oct 9, 2022 at 0:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .