title: Shortcut of universal app
body: <p>I'm creating a Xamarin.Forms app and I want to have an option to create a Desktop shortcut (I already implemented on Android).</p>
  
  <p>I have a protocol that I can use to launch my app, so this is not a concern, and I already saved another type of file in the Desktop to test, my only problem is that I can't create a .lnk file.</p>
  
  <p>In my researches I saw a lot of explanations as to how to create a .lnk file programmatically, but all tutorials were related to WindowsForms or PowerShell scripts (as far as I know, UWP doesn't allow executing PS scripts).</p>
  
  <p>So, is there a way of creating Desktop Shortcuts?</p>
  
  <hr>
  
  <p><strong>Edit after answer</strong></p>
  
  <p>When I create the shortcut using the Dialog, everything is fine, but when I create it in the app, the shortcut's icon doesn't change to my app's icon, it displays a confirmation when I run it and after I confirm, it displays an error message saying <strong>The target "" of this Internet Shortcut is not valid.</strong></p>
  
  <p><a href="https://i.stack.imgur.com/elRsB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/elRsB.png" alt="Shortcut with default icon"></a></p>
  
  <p>But if I change the file in any way (rename it, copy and paste it or change it's contents), it changes the icon to the correct one and when I confirm the dialog, it opens my app as expected. This proves that nothing is wrong with the file or its contents, but I don't know how to workaround this.</p>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <pre><code>StorageFile shortcutFile = null;
  
  try
  {
      shortcutFile = await ApplicationData.Current.LocalFolder.GetFileAsync("shortcut.url");
  }
  catch (Exception) { }
  
  if (shortcutFile == null)
  {
      shortcutFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("shortcut.tmp", CreationCollisionOption.ReplaceExisting);
      await FileIO.WriteLinesAsync(shortcutFile, new string[] { "[InternetShortcut]", "URL=yourapp:///" });
  
      string newShortcutName = shortcutFile.Path.Substring(0, shortcutFile.Path.Length - 4) + ".url";
      File.Move(shortcutFile.Path, newShortcutName);
  
      shortcutFile = await ApplicationData.Current.LocalFolder.GetFileAsync(newShortcutName.SplitWithoutEmpty('\\').Last());
  }
  
  FolderPicker savePicker = new FolderPicker
  {
      SuggestedStartLocation = PickerLocationId.Desktop
  };
  savePicker.FileTypeFilter.Add(".url");
  StorageFolder folder = await savePicker.PickSingleFolderAsync();
  
  if (folder != null)
  {
      // Works fine until here, then it throws an exception (Permission Denied)
      await shortcutFile.CopyAsync(folder, shortcutFile.Name);
  }
  </code></pre>