VB6 Problem Creating Shortcuts

vb6 , shortcut , creating shortcut Philadelphia, United States
  • 10 years ago

    Hello Everyone,

    I wrote a program which create creates a series of shortcuts on multiple servers.

    In some cases when I create shortcuts to folders when I click on the folder shortcut the dialog box pops up that asks me which application do I want to use to open this

    I have noticed this most frequently when I am creating shortcuts on remote systems or network shares.

    Here it the code to the create the shortcut

    Public Sub CreateShortcut(ByVal shortcutLocation As String, ByVal shortcutTarget As String, _ ByVal shortcutName As String, ByVal iconType As Integer)

    On Error GoTo CreateShortcut_Err

    Dim MyShortcut As Object Dim oshell As Object

    If InStr(1, shortcutLocation, ":") = 0 And InStr(1, shortcutLocation, "$") = 0 Then shortcutLocation = "C:\" & shortcutLocation

    Set oshell = CreateObject("wscript.shell") Set MyShortcut = oshell.CreateShortcut(shortcutLocation & "\" & shortcutName)

    ' Set shortcut object properties and save it
    MyShortcut.TargetPath = shortcutTarget
    MyShortcut.WindowStyle = 4
    'Set the icon to represent the shortcut (4=open folder  1=textpad 220=IE)
        Select Case iconType
            Case "0"
                MyShortcut.IconLocation = MyShortcut.TargetPath & ",0"
            Case "1"
                MyShortcut.IconLocation = "C:\Windows\System32\Shell32.dll,1"
            Case "4"
                MyShortcut.IconLocation = "C:\Windows\System32\Shell32.dll,4"
            Case "220"
                MyShortcut.IconLocation = "C:\Windows\System32\Shell32.dll,220"
            Case Else
                wlog "Something went wrong building the shortcut"
        End Select
        If InStr(shortcutTarget, "SCConfigTool.exe") <> 0 Then
            MyShortcut.WorkingDirectory = Mid(shortcutTarget, 1, Len(shortcutTarget) - Len("\SCConfigTool.exe"))
        End If
        If InStr(shortcutTarget, "SoarianLogTool.exe") Then
            MyShortcut.WorkingDirectory = Mid(shortcutTarget, 1, Len(shortcutTarget) - Len("\SoarianLogTool.exe"))
        End If
        If InStr(shortcutTarget, "MGR07.EXE") <> 0 Then
            MyShortcut.WorkingDirectory = Mid(shortcutTarget, 1, Len(shortcutTarget) - Len("\MGR07.EXE"))
        End If

    CreateShortcut_Err: logger.LogMessage (Err.Description) Err.Clear Resume Next End Sub

    Here is my call to this sub:

    Call CreateShortcut(fDest, sDrv & Mid(sServicesDir, 2) , "Services.lnk", "4")

    If I view the properties on the shortcut I created the path is valid. If I hit the find target button it opens up the parent folder of the one I built my shortcut to.

    If I click in the path box and enter / immediately I get a list of paths to chose. If I simply type anything in the box and then delete what I typed and hit apply the shortcut starts working.

    Does anyone have any ideas?

    As you can see, I tried doing the shortcut.save twice. I also tried terminating my path with "\" but nothing seems to work.


Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Programs must be written for people to read, and only incidentally for machines to execute.”