Click here to Skip to main content
12,819,421 members (34,303 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 19 Feb 2008

A simple method to create a shortcut to an executable file

, 19 Feb 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
A simple method to create a shortcut to an executable file.


It is not easy to create a shortcut for an executable file in program. William Rayer has a good article to introduce a method about it; you could see that here. But, that solution may be complex to some people. There is a simple method which can do the same thing.


As we all know, a shortcut is a *.lnk file which has a complex content. *.URL has the same function as *.lnk, but its content is very simple. For example:


Save the the file, and we can get a shortcut to Test.exe.

Sample program

We will see how to create a shortcut using code. We can use 'WritePrivateProfileString' to create a *.URL easily.

#include <windows.h>
#include <stdio.h>

BOOL CreateShortcut(char *ptchExecutableFileName, char *ptchShortcutName)
    BOOL Res = TRUE;
    FILE *fp;
    if(NULL == (fp = fopen(ptchExecutableFileName, "r")))
        printf("\nCan`t find executable file!\n");
        return FALSE;
    Res &= WritePrivateProfileString("InternetShortcut", 
               "URL", ptchExecutableFileName, ptchShortcutName);
    Res &= WritePrivateProfileString("InternetShortcut", 
               "IconIndex", "0", ptchShortcutName);
    Res &= WritePrivateProfileString("InternetShortcut", 
               "IconFile", ptchExecutableFileName, ptchShortcutName);
    return Res;

    For example: create a shortcut on desktop for e:\Test.exe 
      "C:\\Documents and Settings\\Administrator\\Desktop\\Test.url");

Existing issue

The method can create a shortcut to an executable file normally. But I don't know how to create a shortcut to a folder. If there is a folder c:\MyFolder, we make the following file:


Save it. When you click the icon of the file, you can open the folder, but the display of the icon is abnormal!

If you known a solution to this, please share it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Jude Deng
Software Developer
China China

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Frank T. Clark3-Jun-15 12:27
professionalFrank T. Clark3-Jun-15 12:27 
QuestionHow to get the folder icon path and icon index for a given folder name Pin
Stephan Poirier19-Feb-08 18:59
memberStephan Poirier19-Feb-08 18:59 
AnswerRe: How to get the folder icon path and icon index for a given folder name Pin
June Deng20-Feb-08 14:22
memberJune Deng20-Feb-08 14:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 20 Feb 2008
Article Copyright 2008 by Jude Deng
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid