Windows Mobile Tip: Creating shortcuts

Shortcuts are small files containing the location of another file, or the command line required to launch an application. They are commonly placed within the Windows Start Menu as a convenient way to access common functions of your device. By creating and organising your own shortcuts you can customise the features you have quick access to on your device.

Creating a shortcut

You can create shortcuts directly on the device by using the built in File Explorer application. In order to create a shortcut first navigate to the file you want a shortcut for and tap and hold the stylus over the file to display a context sensitive popup menu. From the menu select the “Copy” option.

Now navigate to the location where you want to place the shortcut and tap and hold the stylus over a blank area (such as after the last file in the directory listing). This displays a similar context sensitive popup menu from which you can select a “Paste Shortcut” option.

A shortcut to the file will be created. By default the newly created shortcut will have the name “Shortcut to XYZ” where XYZ was the original file name. By using the standard file rename functionality you can rename the shortcut to a more suitable name.

Uses of shortcuts

Shortcuts are used within the Windows Mobile operating system for a wide range of purposes. By placing your shortcuts into specific folders you can obtain special functionality. Some examples include:

  • \Windows\StartUp – shortcuts to applications placed in this directory will automatically be started whenever the Windows Mobile device is reset.
  • \Windows\Start Menu – shortcuts placed in this directory will appear in the Windows start menu.
  • \Windows\Start Menu\Settings – as discussed in a previous blog entry shortcuts placed in this folder will appear on the System tab of the Settings application that is accessible via the Start Menu.

Early adopters of the Pointui shell replacement for Windows Mobile devices are using similar techniques to customise the functionality of the built in menus to launch phone dialler applications etc.

Technical Details

Behind the scenes File Explorer is creating a shortcut file (probably via the SHCreateShortcut API). A shortcut is a file that has the extension *.lnk and contains details of the command line or file that the shortcut should open.

Pavel Bánský discusses in his blog the technical details on the contents of a *.lnk file. As an alternative to creating the shortcut file manually, you can also utilise an API called SHCreateShortcut as shown below:

using System.Runtime.InteropServices;
 
[DllImport("coredll.dll")]
public static extern void SHCreateShortcut(
  string target,
  string shortcut);
 
// Create a shortcut to tmail.exe within the
// windows start menu.
SHCreateShortcut(
  @"\windows\start menu\programs\my email.lnk",
  @"\windows\tmail.exe");

Shortcuts can also be created as part of a CAB file installation package for your applications, as discussed in the .NET CF Deployment section of the Microsoft Visual Studio 2005 Professional Guided Tour.

Shortcuts can also have other purposes, one of these I will discuss in greater depth in a future blog posting…

7 Responses to “Windows Mobile Tip: Creating shortcuts”

  1. Daniel says:

    Visual Studio Deployment project cant create a shortcut which includes command line arguments. And if you instead craft your own .lnk file it wont let you deploy it. When you try to add it nothing happens. For some reason it rejects the file extension.

    The only remaining option is to create it in code using a CE Setup dll. which can’t be managed code. So you can’t use System.Runtime.InteropServices.

    Well done Microsoft for completely shafting us again.

  2. Cliff Corbett says:

    How about a programatic method for removing a shortcut?

  3. Hi Cliff,

    I have not verified it, but have you tried calling DeleteFile (or it’s managed equivalent File.Delete), passing in the path to the shortcut?

    For example:

    using System.IO;
     
    File.Delete(@"\windows\start menu\programs\my email.lnk");

    Shortcuts can be treated as if they were any other file on the filesystem.

  4. AD says:

    Hi and thanx a million dude.

    Keep up the good work.

    Caio.

  5. reg says:

    I was wondering about making a shortcut to a webpage. I was able to do it before but I cant remember how I did it. For example I want to make a shortcut to youtube.

    Thanks,
    reg

  6. HemaLatha says:

    Hello anybody can help me in this issue……I have created auto started windows mobile application.That should work as a back end process means we have written code in the form load but we don’t want to show the screen to the user. i have tried form1.hide() and form1.windowsstate=formstate.minimized. But it’s not orking.

    If you have the solution it will be very helpful.

    Regards,
    Hema

  7. Hi Hema,

    Try adding a line such as

    BeginInvoke(new Action(() => Hide()));

    At the end of your Form Load event handler (or even the constructor of your form, directly underneath the call to InitializeComponent).

    The problem is the form load event handler is called part way through the OS attempting to make your window visible. Even if you request it to hide, your load event handler still returns to the code within the OS that then makes the window visible.

    Using a code snippet such as the one I mentioned above essentially “queues” up the request to hide the window. Your form load event handler returns, the window is briefly made visible, and then the OS gets around to processing any outstanding window messages, and hence finds your request to hide it.

    For a similiar reason another method you may see suggested is the use of a timer with a duration of 1 millisecond. The timer tick event triggers after the window is visible, and hence calling Hide() works as expected.

    Depending upon what you are attempting to do it may even be better to start off with a console project, and only make the window visible when first required.

    Hope this helps,
    Christopher Fairbairn

    Hope this helps,
    Christopher Fairbairn

Leave a Reply