I'm trying to have a button that once you press it, it will create a shortcut.
Any time I press the button I am getting an error
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred
Additional information: Exception occurred. (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
Can anyone see why this is happening?
public static void CreateShortcut(string shortcutName)
{
WshShell wsh = new WshShell();
string fileName = savDir + "\\" + ProductName + ".ink";
IWshShortcut shortcut = (IWshShortcut)wsh.CreateShortcut(fileName);
shortcut.Targetpath = Application.ExecutablePath;
shortcut.Save();
}
private void button2_Click(object sender, EventArgs e)
{
string folder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
CreateShortcut("folder");
}
Your call to CreateShortcut
looks wrong:
CreateShortcut("folder");
should be (no quotes):
CreateShortcut(folder);
I also agree that you would want to change
"folder" -> folder
However, I got the same exception. I think the issue is your extension. Try:
".lnk" instead of ".ink"
User contributions licensed under CC BY-SA 3.0