VB.NET 改變桌面捷徑圖示

加入參考(COM) Microsoft Shell Controls and Automation (Windows\System32\Shell32.dll)
Dim dp = New DirectoryInfo( _
My.Computer.FileSystem.SpecialDirectories.Desktop)
Dim ca = New DirectoryInfo(Environment.GetFolderPath( _
Environment.SpecialFolder.CommonApplicationData))
Dim fd = ca.FullName.Replace(ca.Name, dp.Name)
Dim n1 = String.Format("{0}.lnk", Name1)
Dim n2 = String.Format("{0}.lnk", Name2)
Dim k1 = IO.Path.Combine(fd, n1)
If IO.File.Exists(k1) = False Then
    fd = dp.FullName
    k1 = IO.Path.Combine(fd, n1)
    If IO.File.Exists(k1) = False Then
        Return
    End If
End If
Dim sl = New Shell32.ShellClass
Dim dr = sl.NameSpace(fd)
Dim im = dr.Items.Item(n1)
Dim lk = im.GetLink
Dim ap = IO.Path.Combine(AppPath, _
String.Format("{0}.exe", Application.ProductName))
With lk
    .SetIconLocation(ap, IconIndex)
    .Save()
End With
sl = Nothing        

留言

熱門文章