2013-08-26 66 views
0

我有一个代码,它的任务将被改变的.url或.LNK(快捷方式)属性,但它似乎并没有做任何事情。VB:更改快捷方式性质在

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 

任何人都可以给我一些建议,我哪里会出错?

谢谢。

+0

什么消息框,最终显示出来?如果有的话,很高兴知道你遇到了什么错误。 –

+0

它没有显示任何运行中断的消息。 – Saint

回答

0

从我的理解,它听起来就像是越来越执行什么。试着在子的开头放一个断点,看看它是否被调用。如果没有,那么请确保您能够正确连接Change_Shortcut(),以便它被正确调用。

一旦您设置断点,你应该能够通过代码走,看你在哪里结束,以确保一切按预期工作。

+0

OK做到了,我从HRESULT异常:在这行代码0x80041001:shortcut.Path =“www.o2.ie” – Saint

+0

增添了新的答案。如果我的解决方案帮助您发现问题,请妥善接受我的回答。 –

0

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

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

我忘记把http://在地址的前面。