Creating IE-Style Shortcut on the Desktop

Whenever we want to create shortcuts for our programs on the desktop, what we do normally is, we create .lnk files for our programs using IShellLink. When we create it in such a way, what we get is an icon on the desktop with an arrow on its bottom left corner, and if you right click it, youll be getting the normal menu, with cut, copy, paste, delete etc. items. But if you see the Internet Explorers shortcut icon on the desktop, its a normal icon without the arrow on its corner and with a different menu also. (If you see Microsofts connection manager, youll see the difference very well than Internet Explorer). Now lets see how to create such a shortcut on the desktop with your own customized menu items.

When you execute this code, youll be getting an icon on the desktop with "Netlinker" as its shortcut name. If you double click it, itll open the Internet Explorer and if you right click, you can see a customized menu with no cut, copy, paste, rename items. Even you cannot delete this shortcut from the desktop. If you select the properties of this icon, itll open the Internet properties dialog box.

Choose a 32x32 icon and specify its path.

CString shtct_ico=_T("C:\\32x32.ico");
This is to show the Internet explorer properties dialog box.
CString shtct_prop=_T("rundll32.exe shell32.dll,
                      Control_RunDLL inetcpl.cpl,,0");
This is the shortcut name to be displayed on the desktop.
CString shtct_name=_T("Netlinker");
Catch the path of the Internet Explorer and store it.
CRegKey m_Kiepath;

CString ie_path;

DWORD dwval;

m_Kiepath.Open(HKEY_LOCAL_MACHINE,
               "SOFTWARE\\Microsoft\\Windows\\"
               "CurrentVersion\\App Paths\\IEXPLORE.EXE");

m_Kiepath.QueryValue(ie_path.GetBuffer(1000),
                     NULL,
                     &dwval);

m_Kiepath.Close();

CString shtct_to=ie_path;
Create a GUID using guidgen.exe and copy it to the clipboard and paste it here. This is the GUID that we are going to use for the representation of our shortcut and its menu items. Here, the GUID that we have generated is, 6270AEE4-AA41-11d4-A25D-008048B63F94. Create this GUID key under the HKCR\CLSID and set the shortcut name as its value

CRegKey m_kdsktp;

m_kdsktp.Create(HKEY_CLASSES_ROOT,
                "CLSID\\{6270AEE4-AA41-11d4-A25D-"
                "008048B63F94}");

m_kdsktp.SetValue(shtct_name);

m_kdsktp.Close();
Under this GUID, create the DefaultIcon key, which represents the icon for the shortcut, and set its value with the path of the icon.

m_kdsktp.Create(HKEY_CLASSES_ROOT,
                "CLSID\\{6270AEE4-AA41-11d4-A25D"
                "-008048B63F94}\\DefaultIcon");

m_kdsktp.SetValue(shtct_ico);

m_kdsktp.Close();

Now set the menu items for the right click menu.

Here is the Open menu item and its executable is set

m_kdsktp.Create(HKEY_CLASSES_ROOT,
                "CLSID\\{6270AEE4-AA41-11d4-A25D-"
                "008048B63F94}\\Shell\\Open\\Command");

m_kdsktp.SetValue(shtct_to);

m_kdsktp.Close();
Set the properties menu item and its executable.
m_kdsktp.Create(HKEY_CLASSES_ROOT,
                "CLSID\\{6270AEE4-AA41-11d4-A25D-"
                "008048B63F94}\\Shell\\Properties\\Command");

m_kdsktp.SetValue(shtct_prop);

m_kdsktp.Close();

Now set the attributes of the menu so that the default menu items such as cut, copy, paste, rename, delete etc are removed.

BYTE *b;

HANDLE heap;

char a[20];

m_kdsktp.Create(HKEY_CLASSES_ROOT,
                "CLSID\\{6270AEE4-AA41-11d4-A25D-"
                "008048B63F94}\\ShellFolder");

strcpy(a,"00.00.00.00");

heap=HeapCreate(0,0,0);

b=(BYTE*)HeapAlloc(heap,0,30);

sscanf(a,
       "%x.%x.%x.%x",
       &b[0],
       &b[1],
       &b[2],
       &b[3]);

RegSetValueEx(m_kdsktp.m_hKey,
              "Attributes",
              0,
              REG_BINARY,
              b,
              4);

HeapFree(heap, 0, b);

HeapDestroy(heap);

m_kdsktp.Close();

Now we have to create a reference for this GUID under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\Namespace. Then only itll appear on the desktop.

m_kdsktp.Create(HKEY_LOCAL_MACHINE,
                "SOFTWARE\\Microsoft\\Windows\\"
                "CurrentVersion\\Explorer\\Desktop\\"
                "NameSpace\\{6270AEE4-AA41-11d4-A25D-"
                "008048B63F94}");

m_kdsktp.SetValue("Netlink");

m_kdsktp.Close();
Since weve played with the shell, we must notify it. Then only the changes will reflect immediately.
SHChangeNotify(SHCNE_ASSOCCHANGED,SHCNF_FLUSHNOWAIT, 0, 0);


Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds