2013-08-26 63 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://在地址的前面。