Click here to Skip to main content
5,787,682 members and growing! (20,941 online)
Email Password   helpLost your password?
Desktop Development » Files and Folders » General     Beginner License: The Code Project Open License (CPOL)

A simple method to create a shortcut of executable file

By Jude Deng

A simple method to create a shortcut of executable file
C++ (VC6, C++), Windows (Windows, WinXP), Win32, Dev

Posted: 19 Feb 2008
Updated: 19 Feb 2008
Views: 6,560
Bookmarked: 5 times
Note: This is an unedited reader contribution
Announcements
Loading...



Search    
Advanced Search
Sitemap
4 votes for this Article.
Popularity: 0.71 Rating: 1.18 out of 5
3 votes, 75.0%
1
1 vote, 25.0%
2
0 votes, 0.0%
3
0 votes, 0.0%
4
0 votes, 0.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

It is not easy what create a shortcut of executable file in program. William Rayer have a good article to introduce a method about it;you could see here . But it may be complex to some people. There is a simple method which can do same thing.

Background

As we all known, a shortcut is a file of *.lnk which have complex content. *.URL have same function with *.lnk, but it`s content is very simple.For example:

========================================

[InternetShortcut]
URL=C:\MyFolder\Test.exe
IconIndex=0
IconFile=C:\MyFolder\Test.exe

========================================

Save the the file then we can get a shortcut of Test.exe .

Sample program

There show how to create shortcut using code. We can use 'WritePrivateProfileString' to create *.URL simply.

See here:

     
#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;
    }
    fclose(fp);
    
    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 
    CreateShortcut("E:\\Test.exe", "C:\\Documents and Settings\\Administrator\\Desktop\\Test.url");
//*/

  

Existing issue

The method can create shortcut of executable file normally. But I don`t know how to create a shortcut of folder .If there is a folder c:\MyFolder , and write following file:

========================================

[InternetShortcut]
URL=C:\MyFolder
IconIndex=0
IconFile=C:\MyFolder

========================================

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

If you known , please tell us how to solve the issue.

License

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

About the Author

Jude Deng


^_^
Occupation: Software Developer
Location: China China

Other popular Files and Folders articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
AnswerHow to get the folder icon path and icon index for a given folder namememberStephan Poirier18:59 19 Feb '08  
GeneralRe: How to get the folder icon path and icon index for a given folder namememberJune Deng14:22 20 Feb '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 19 Feb 2008
Editor:
Copyright 2008 by Jude Deng
Everything else Copyright © CodeProject, 1999-2009
Web12 | Advertise on the Code Project