I'm trying to delete an old desktop shortcut on program startup. Only this code isn't working.

        ' Get rid of the updater icon on the desktop. 
        Dim DeleteShortcut As String
        DeleteShortcut = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\Sample Shortcut.lnk"
        If System.IO.File.Exists(DeleteShortcut) = True Then
            System.IO.File.Delete(DeleteShortcut)
        End If

Looks pretty straight forward- but just not working. Is there another way to do this?

I also tried-

        ' Get rid of the updater icon on the desktop. 
        If System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\Sample Shortcut.lnk") Then
            System.IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\Sample Shortcut.lnk")
        End If

It's got to do with my path. I put in a message box after THEN but nothing came up.

Your code will work if the .lnk file is in the current users desktop directory. But if it's in the All Users desktop Directory, you'll need to use Environment.SpecialFolder.CommonDesktopDirector.

Yup, that did it- thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.