如何创建快捷方式?

时间:2015-02-20 18:59:00

标签: vb.net shortcut late-binding

我需要为所选文件夹中的选定文件创建快捷方式。在几个站点(包括stackoverflow)上,我找到了以下代码:

Private Sub MakeShortcut(ByVal File As String, ByVal ShortcutFolder As String, ByVal Name As String, ByVal WorkDirectory As String)
        Dim WshShell As Object = CreateObject("WScript.Shell")
        Dim NewShortcut As Object = WshShell.CreateShortcut(ShortcutFolder & "\" & Name & ".lnk")

        NewShortcut.TargetPath = File
        NewShortcut.WindowStyle = 1
        NewShortcut.IconLocation = File & ",0"
        NewShortcut.WorkingDirectory = WorkDirectory
        NewShortcut.Save()
End Function

当然,我在项目中添加了对Interop.IWshRuntimeLibrary.dll的引用,并且" Imports IWshRuntimeLibrary"在一般'范围内表格的一部分。

尽管如此,我确实收到了消息" Option Strict不允许后期绑定"适用于" whshell的所有外观。"和#34; Newshortcut。"

为什么我会收到此错误以及如何解决?

0 个答案:

没有答案