I need little help on creating shortcut for my C# app. I want programmatically do this.
I intend to create a shortcut in startup menu folder. Maybe you could also show me how to start my app automatically using a registry entry. Thanks!

8 Years
Discussion Span
Last Post by Diamonddrake

Thanks for reply LizR.
Of course I googled that, and I had a little problem I'll tell you now. I made a reference to "Windows Script Host Object Model", then I included IWshRuntimeLibrary and I made a button for testing, so that when I click it, process for creating the shortcut starts, like this:

private WshShellClass WshShell;

private void button3_Click(object sender, EventArgs e)
            // Create a new instance of WshShellClass

            WshShell = new WshShellClass();

            // Create the shortcut

            IWshRuntimeLibrary.IWshShortcut MyShortcut;

            // Choose the path for the shortcut

            MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(@"C:\Documents and Settings\All Users\Desktop\cLchecker.lnk");

            // Where the shortcut should point to

            MyShortcut.TargetPath = Application.ExecutablePath;

            // Description for the shortcut

            MyShortcut.Description = "Launch cLchecker";

            // Location for the shortcut's icon

            MyShortcut.IconLocation = Application.StartupPath + @"\cLchecker.ico";

            // Create the shortcut at the given path


The problem is that I use File.AppendAllText() method to write to file and I got this error:
" 'File' is an ambiguous reference between 'System.IO.File' and 'IWshRuntimeLibrary.File' ".

It seems to be a little conflict. So, don't worry, I don't wanna lose your time with nothing; I told you now the main problem in my program. And sorry for not pointing to the exact problem. I'll go now; in 7 hours I'm back.


It doesn't work. However thanks for reply.
Somebody else? Ideas?


You dont show the code you're using so we're only guessing..

Your short cut looks like it should appear after your code above.. Whats the file bit for? something else?


Try using System.IO.File.Something or IWshRuntimeLibrary.File.Something.


what you have to do is remove "using System.IO;" from the top of your class, and everytime you need to use System.IO.File you will have to type the full namespace. problem is that when you import the namespace for the object that creates your shortcut you share its namespace scope with the "File" namespace scope of the System.IO, so removing the using block at the top of your class fixes the problem.

Happy Coding!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.