0

我有一个代码,该任务将更改 .url 或 .lnk (快捷方式)属性,但它似乎没有做任何事情。

Imports System.IO
Imports Shell32

Module Module1
    Sub Main()
        'References Microsoft Shell Controls and Automation.
        'http://msdn.microsoft.com/en-us/library/bb776890%28v=VS.85%29.aspx
    End Sub
    Public Sub Change_Shortcut()

    Dim shell As Shell32.Shell
    Dim folder As Shell32.Folder
    Dim folderItem As Shell32.FolderItem
    Dim shortcut As Shell32.ShellLinkObject

    shell = New Shell32.Shell

    folder = shell.NameSpace("C:\Users\GrzegoP\Desktop\xxx") 'Shortcut path
    If Not folder Is Nothing Then
        folderItem = folder.ParseName("o2.url") 'Shortcut name
        If Not folderItem Is Nothing Then
            shortcut = folderItem.GetLink
            If Not shortcut Is Nothing Then
                shortcut.Path = "www.o2.ie" 'new shortcut address
                shortcut.Save()
                MsgBox("Shortcut changed")
            Else
                MsgBox("Shortcut link within file not found")
            End If
        Else
            MsgBox("Shortcut file not found")
        End If
    Else
        MsgBox("Desktop folder not found")
    End If

End Sub

End Module

谁能给我一些建议我哪里出错了?

谢谢。

4

3 回答 3

1

这里需要注意的是,您不能以这种方式创建 URL 快捷方式:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb776891%28v=vs.85%29.aspx

相反,您应该简单地xxx.url在桌面上创建一个文件,在其中写入以下文本行:

[InternetShortcut]
URL=http://www.o2.ie

Windows 将把它变成一个网站快捷方式。

于 2013-08-26T16:22:26.007 回答
0

根据我的理解,听起来好像什么都没有被执行。尝试在 sub 的开头放置一个断点,看看它是否被调用。如果没有,请确保您能够正确连接Change_Shortcut()它,以便正确调用它。

设置断点后,您应该能够遍历代码并查看最终的位置,以确保一切按预期工作。

于 2013-08-26T15:57:41.290 回答
0

一个简单的解决我的问题...

在行中:shortcut.Path = "www.o2.ie"

我忘记http://在地址前面放了。

于 2013-08-26T16:24:19.160 回答