This question explains how to create a shortcut in C#. For example,
using System;
using IWshRuntimeLibrary;
using System.IO;
namespace TestCreateShortcut
{
class Program
{
static void Main(string[] args)
{
WshShell shell = new WshShell();
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string source = "C:\\foo\\hello.exe";
string dest = desktop + "\\hello.lnk";
IWshRuntimeLibrary.IWshShortcut shortcut =
(IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(dest);
shortcut.TargetPath = source;
shortcut.WorkingDirectory = new FileInfo(source).Directory.Name;
shortcut.Save();
}
}
}
The problem is that, as an Administrator user, I want to create this shortcut on another user's Desktop. I could change the desktop string to be their Desktop path instead of mine, but the catch is this user will have been created right before I want to call the code to make a Desktop shortcut, so there is no C:\Users\TheUser folder yet!
What are some ways to alleviate this situation or make it possible to put a shortcut on a newly-created user's desktop? I preferably want to do this before the users actually log in for the first time. Thank you.