A method for creating a desktop shortcut using Win32 API

Source: Internet
Author: User

When I first came into contact with this problem, I found that the API provides a COM interface call, And IShellLink will allow you to create a shortcut. You need to create a shortcut on the desktop, you just need to save the shortcut to the desktop directory. However, you need to understand the calling method of this COM interface and some API usage problems, such as CreateShortCut, which is very cumbersome and has no results in an hour.

I gave up the above idea and started to study Desktop shortcuts. By studying the shortcuts created by batch processing, I found that when you create a corresponding one on the desktop. the url file. windows parses it as a shortcut.

Assume that your target program is D: \ IDEasm.exe, and create a desktop shortcut for it.

The first problem is:. url File Format

The content and format of the corresponding IDEasm. url file are as follows)

---------------------------------------------

[InternetShortcut] // flag
URL = D: \ IDEasm.exe // full path file name of the target program
IconFile = D: \ IDEasm.exe // set the IDEasm. url file icon below
IconIndex = 0

---------------------------------------------

After the file is saved, the file is automatically parsed as a shortcut. After saving the above files on the desktop, it is equivalent to setting up a shortcut on the desktop.

In this way, you only need to use CreateFile in the program to create this. url file. The only change is the full path File Name of the Target Program (which can be obtained by the program itself ).

The second problem occurs: Get the desktop path name.

1. Identify the system disk, which can be extracted using GetWindowsDirectory. For example, C :\

2. The full desktop path 'C: \ '+ 'documents and Settings \ All Users \ Desktop' is spliced from the above results'

In summary, after obtaining the full path name of the desktop, you can spell out the full path File Name Of The. url file you want to create. Finally, use CreateFile to create this file (that is, C: \ Documents ents and Settings \ All Users \ Desktop \ IDEasm. url), and then write the content in the dotted box above into this file using WriteFile.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.