By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,537 Members | 1,750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,537 IT Pros & Developers. It's quick & easy.

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

P: 21
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
Jul 17 '07 #1
Share this Question
Share on Google+
5 Replies


hariharanmca
100+
P: 1,977
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

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.     MsgBox GetTargetPath("ShortCut Filename")
  3. End Sub
  4.  
  5. Pivate Function GetTargetPath(ByVal FileName As String)
  6.     Dim Obj As ObjectSet
  7.     Obj = CreateObject("WScript.Shell")
  8.     Dim Shortcut As ObjectSet
  9.     Shortcut = Obj.CreateShortcut(FileName)
  10.     GetTargetPath = Shortcut.TargetPathShortcut.Save
  11. End Function
i think this will help you
Jul 17 '07 #2

P: 21
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.     MsgBox GetTargetPath("ShortCut Filename")
  3. End Sub
  4.  
  5. Pivate Function GetTargetPath(ByVal FileName As String)
  6.     Dim Obj As ObjectSet
  7.     Obj = CreateObject("WScript.Shell")
  8.     Dim Shortcut As ObjectSet
  9.     Shortcut = Obj.CreateShortcut(FileName)
  10.     GetTargetPath = Shortcut.TargetPathShortcut.Save
  11. End Function
i think this will help you
It states that Type ObjectSet is not defined. How do I fix that?
Jul 17 '07 #3

hariharanmca
100+
P: 1,977
It states that Type ObjectSet is not defined. How do I fix that?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.     MsgBox GetTargetPath("ShortCut Filename")
  3. End Sub
  4.  
  5. Pivate Function GetTargetPath(ByVal FileName As String)
  6.     Dim Obj As Object
  7.     Set Obj = CreateObject("WScript.Shell")
  8.     Dim Shortcut As ObjectSet
  9.     Shortcut = Obj.CreateShortcut(FileName)
  10.     GetTargetPath = Shortcut.TargetPathShortcut.Save
  11. End Function
okay, its an typo.....

Expand|Select|Wrap|Line Numbers
  1.     Dim Obj As Object
  2.     Set Obj = CreateObject("WScript.Shell")
Jul 17 '07 #4

P: 21
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.     MsgBox GetTargetPath("ShortCut Filename")
  3. End Sub
  4.  
  5. Pivate Function GetTargetPath(ByVal FileName As String)
  6.     Dim Obj As Object
  7.     Set Obj = CreateObject("WScript.Shell")
  8.     Dim Shortcut As ObjectSet
  9.     Shortcut = Obj.CreateShortcut(FileName)
  10.     GetTargetPath = Shortcut.TargetPathShortcut.Save
  11. End Function
okay, its an typo.....

Expand|Select|Wrap|Line Numbers
  1.     Dim Obj As Object
  2.     Set Obj = CreateObject("WScript.Shell")
I really appreciate all the help. I am receiving this error when I debug at the line
GetTargetPath = Shortcut.TargetPathShortcut.Save

Public member 'TargetPathShortcut' on type 'IWshShortcut' not found.
Jul 17 '07 #5

P: 21
Awesome I got it! My final code is:



Private Sub Command1_Click()

MsgBox GetTargetPath("ShortCut Filename")

End Sub


Private Function GetTargetPath(ByVal FileName As String)

Dim Obj As Object

Obj = CreateObject("WScript.Shell")

Dim Shortcut As Object

Shortcut = Obj.CreateShortcut(FileName)

GetTargetPath = Shortcut.TargetPath
End Function


Thank you so much!
Jul 17 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.