7

I would like to create a shortcut, the target of which does not exist (yet). However, as soon as I try to create it, Windows raises an error saying the specified target does not exist.

While I understand why Windows raises this error, I would like to know if there is a way to bypass it.

My file will be located on D:\MyScript.exe, so creating a fake file with this name will not work, since the character \ is forbidden for Windows filenames.

1
  • Can you confirm you can create a shortcut to a folder on a CD?
    – Dave
    Jan 14, 2013 at 14:44

4 Answers 4

1

Shortcut from Optimumx can create shortcuts to non-existing targets.

You will probably run the following command

shortcut /F:example.lnk /A:C /T:D:\MyScript.exe

Sources:
1. Create a Shortcut to a non-existing folder in Windows XP
2. http://www.msfn.org/board/topic/70537-is-there-a-way-to-create-a-shortcut-without-the-source-file/

0
2

IMO, there is only 1 way, and that is a simple hack.

Create a new file (like a text file), call it the eventual file name with the extension. Of course this file won't work, but Windows will reference it. Then, when you have the real file, just copy it over the top of your dummy file!

4
  • The problem is that my file will be located on D: (CD Reader), so creating a file called D:\myScript.exe will raise the following error : a filename cannot contain \
    – user189857
    Jan 14, 2013 at 14:34
  • 3
    ...Well, to be honest @NNzz I think your OP should have stated that since that's a major part of the question. Please edit your post
    – Dave
    Jan 14, 2013 at 14:36
  • I edited my post.
    – user189857
    Jan 14, 2013 at 14:38
  • HA This worked perfect for what I needed! Clever lol
    – Alex K
    Jan 29, 2015 at 22:35
0

As Dave mentioned you can create a file as a placeholder, that matches the shortcut rule. If its on another drive (like D: as you mentioned) then map a drive to that drive letter (right click my computer >> map a drive >> \\[your hostname]\c$\temp ). If its in a directory you dont have access to, create the shortcut on a different computer where you do, then copy it over.

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

You must log in to answer this question.