如何使用"Windows脚本主机"在桌面上创建快捷方式但没有参考吗? [英] How to create shortcut on desktop with "Windows Script Host" but not reference it?

查看:107
本文介绍了如何使用"Windows脚本主机"在桌面上创建快捷方式但没有参考吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在桌面上创建快捷方式时,我引用了"Windows Script Host"并按如下所示对功能进行了编码:

When I created a shortcut on desktop I referenced "Windows Script Host" and coded a function as follows:

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:

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



但是我不想引用"Windows Script Host"(在CreateShortcut()函数中),但是我必须使用"Windows Script Host",该怎么做?谢谢.



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.

推荐答案

我的想法是:当我使用"Windows Script Host"创建快捷方式时,我不得不将其引用到我的项目中,因此当我编译我的项目时,在bin目录中生成一个名为"Interop.IWshRuntimeLibrary.dll"的dll文件,我必须将该dll文件与exe文件一起携带...我只想携带运行良好的exe文件.这个怎么做?希望大家帮帮我.谢谢.
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.


这篇关于如何使用"Windows脚本主机"在桌面上创建快捷方式但没有参考吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆