Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I created a shortcut on desktop I referenced "Windows Script Host" and coded a function as follows:

C#
using IWshRuntimeLibrary;
using System.IO;
public static void CreateShortcut(string targetPath,
                                   string shortcutFile, 
                                   string description, 
                                   string arguments,
                                   string hotKey,
                                   string workingDirectory,
                                   string iconLocation)
        {
             if (String.IsNullOrEmpty(targetPath))
                throw new ArgumentNullException("targetPath");

            if (String.IsNullOrEmpty(shortcutFile))
                throw new ArgumentNullException("shortcutFile");

            WshShellClass wshShell = new WshShellClass();

            IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(shortcutFile);

            shortcut.TargetPath = targetPath;

            shortcut.Description = description;

            if (!String.IsNullOrEmpty(arguments))
                shortcut.Arguments = arguments;

            if (!String.IsNullOrEmpty(hotKey))
                shortcut.Hotkey = hotKey;

            if (!String.IsNullOrEmpty(workingDirectory))
                shortcut.WorkingDirectory = workingDirectory;

            if (!String.IsNullOrEmpty(iconLocation))
                shortcut.IconLocation = iconLocation;

            shortcut.Save();
        }


and I called it:

C#
CreateShortcut(C:\\abc.exe",
                        Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\abc.lnk",
                                            null,
                                            null,
                                            null,
                                            null,
                                            null);


But I dont want to referene "Windows Script Host" (in CreateShortcut() function), but I have to use "Windows Script Host", how to do this? Thanks.
Posted
Updated 16-Sep-12 16:20pm
v2

1 solution

My idea is: When i created shortcut with "Windows Script Host" then I had to referece it into my project, so when i compiled my project then in bin directory generates a dll file called "Interop.IWshRuntimeLibrary.dll", i had to carry that dll with exe file... I want to only carry exe file that it runs well. How to do this? Hope everyone help me. Thanks.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900