Getting a target Path from having the path name as a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NyNyHelp
    New Member
    • Jul 2007
    • 21

    Getting a target Path from having the path name as a string

    I have the shortcut path name as a string "C:\test\batch1 .bat.lnk" for example. Is there anyway I can get the target path from that. I'm using VB 2005 Express
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    #2
    Originally posted by NyNyHelp
    I have the shortcut path name as a string "C:\test\batch1 .bat.lnk" for example. Is there anyway I can get the target path from that. I'm using VB 2005 Express

    Code:
    Private Sub Command1_Click()
        MsgBox GetTargetPath("ShortCut Filename")
    End Sub
    
    Pivate Function GetTargetPath(ByVal FileName As String)
        Dim Obj As ObjectSet
        Obj = CreateObject("WScript.Shell")
        Dim Shortcut As ObjectSet
        Shortcut = Obj.CreateShortcut(FileName)
        GetTargetPath = Shortcut.TargetPathShortcut.Save
    End Function
    i think this will help you

    Comment

    • NyNyHelp
      New Member
      • Jul 2007
      • 21

      #3
      Originally posted by hariharanmca
      Code:
      Private Sub Command1_Click()
          MsgBox GetTargetPath("ShortCut Filename")
      End Sub
      
      Pivate Function GetTargetPath(ByVal FileName As String)
          Dim Obj As ObjectSet
          Obj = CreateObject("WScript.Shell")
          Dim Shortcut As ObjectSet
          Shortcut = Obj.CreateShortcut(FileName)
          GetTargetPath = Shortcut.TargetPathShortcut.Save
      End Function
      i think this will help you
      It states that Type ObjectSet is not defined. How do I fix that?

      Comment

      • hariharanmca
        Top Contributor
        • Dec 2006
        • 1977

        #4
        Originally posted by NyNyHelp
        It states that Type ObjectSet is not defined. How do I fix that?

        Code:
        Private Sub Command1_Click()
            MsgBox GetTargetPath("ShortCut Filename")
        End Sub
         
        Pivate Function GetTargetPath(ByVal FileName As String)
            Dim Obj As Object
            Set Obj = CreateObject("WScript.Shell")
            Dim Shortcut As ObjectSet
            Shortcut = Obj.CreateShortcut(FileName)
            GetTargetPath = Shortcut.TargetPathShortcut.Save
        End Function
        okay, its an typo.....

        Code:
            Dim Obj As Object
            Set Obj = CreateObject("WScript.Shell")

        Comment

        • NyNyHelp
          New Member
          • Jul 2007
          • 21

          #5
          Originally posted by hariharanmca
          Code:
          Private Sub Command1_Click()
              MsgBox GetTargetPath("ShortCut Filename")
          End Sub
           
          Pivate Function GetTargetPath(ByVal FileName As String)
              Dim Obj As Object
              Set Obj = CreateObject("WScript.Shell")
              Dim Shortcut As ObjectSet
              Shortcut = Obj.CreateShortcut(FileName)
              GetTargetPath = Shortcut.TargetPathShortcut.Save
          End Function
          okay, its an typo.....

          Code:
              Dim Obj As Object
              Set Obj = CreateObject("WScript.Shell")
          I really appreciate all the help. I am receiving this error when I debug at the line
          GetTargetPath = Shortcut.Target PathShortcut.Sa ve

          Public member 'TargetPathShor tcut' on type 'IWshShortcut' not found.

          Comment

          • NyNyHelp
            New Member
            • Jul 2007
            • 21

            #6
            Awesome I got it! My final code is:



            Private Sub Command1_Click( )

            MsgBox GetTargetPath(" ShortCut Filename")

            End Sub


            Private Function GetTargetPath(B yVal FileName As String)

            Dim Obj As Object

            Obj = CreateObject("W Script.Shell")

            Dim Shortcut As Object

            Shortcut = Obj.CreateShort cut(FileName)

            GetTargetPath = Shortcut.Target Path
            End Function


            Thank you so much!

            Comment

            Working...