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.