Parsing Shortcut using Script

Sunday, April 29, 2007 by SirSmiley | Discussion: DesktopX

Ok. First, I'd like to say sorry to sviz as I sent this to him & it was probably discombobulated. Create a new object & drop this whole script in it. Then drag one (only one) shortcut on to it to see how the FSO parses it.

Code: vbscript
  1. Sub Object_OnDropFiles(files)
  2. '--Call shell & FSO object
  3. Set WshShell = CreateObject("WScript.Shell")
  4. Set objFSO = CreateObject("Scripting.FileSystemObject")
  5. '--Uses the CreateShortcut Method to retrieve the target Path(s) of the the shortcut
  6. '--eg. The actual file/folder or application the shortcut points to
  7. Set oShellLink = WshShell.CreateShortcut(files)
  8. '--Echos back the full path to respective Target
  9. msgbox "Path to Application: " & oShellLink.TargetPath
  10. objFile = oShellLink.TargetPath
  11. '--Using the comment field as temp storage for file target path
  12. Object.Comments = objFSO.GetAbsolutePathName(objFile)
  13. '-- Updates Tooltip & Text Label to Application Name
  14. Object.ToolTipText = objFSO.GetBaseName(objFile)
  15. '--Parses Paths using FSO & echoes back
  16. msgbox "Absolute path: " & objFSO.GetAbsolutePathName(objFile)
  17. msgbox "Parent folder: " & objFSO.GetParentFolderName(objFile)
  18. msgbox "File name: " & objFSO.GetFileName(objFile)
  19. msgbox "Base name: " & objFSO.GetBaseName(objFile)
  20. msgbox "Extension name: " & objFSO.GetExtensionName(objFile)
  21. '--Echos back path to Icon
  22. msgbox "Path to Icon: " & oShellLink.IconLocation
  23. End Sub
  24. '--Go to selected target on L-click
  25. Sub Object_OnLbuttonUp(x,y,dragged)
  26. Dim appPath
  27. appPath=object.Comments
  28. If Not dragged Then
  29. On Error Resume Next
  30. Set Sh = CreateObject("WScript.Shell")
  31. Sh.Run (Chr(34)& appPath & Chr(34))
  32. Set Sh = Nothing
  33. End If
  34. End Sub

RomanDA
Reply #1 Monday, April 30, 2007 9:39 AM
Just a suggestion on the following code:

'--Parses Paths using FSO & echoes back
msgbox "Absolute path: " & objFSO.GetAbsolutePathName(objFile)
msgbox "Parent folder: " & objFSO.GetParentFolderName(objFile)
msgbox "File name: " & objFSO.GetFileName(objFile)
msgbox "Base name: " & objFSO.GetBaseName(objFile)
msgbox "Extension name: " & objFSO.GetExtensionName(objFile)
msgbox "Path to Icon: " & oShellLink.IconLocation

When i make a "TEST" object i always send the output to:
object.text

The reason for not wanting to use msgbox is that it can get into loops at places, and really mess you up.

My suggestion for the above code:

'--Parses Paths using FSO & echoes back
object.text = "Absolute path: " & objFSO.GetAbsolutePathName(objFile)
object.text = object.text & vbnewline & msgbox "Parent folder: " & objFSO.GetParentFolderName(objFile)
object.text = object.text & vbnewline & "File name: " & objFSO.GetFileName(objFile)
object.text = object.text & vbnewline & "Base name: " & objFSO.GetBaseName(objFile)
object.text = object.text & vbnewline & "Extension name: " & objFSO.GetExtensionName(objFile)
object.text = object.text & vbnewline & "Path to Icon: " & oShellLink.IconLocation

This gives you one text string with all the info above. the vbnewline just puts a line break in there.

Just my ideas. Take 'em or leave 'em
SirSmiley
Reply #2 Monday, April 30, 2007 6:35 PM
That makes perfect sense. Really I should be using msgbox constants then that would eliminate potential looping issues. I like your idea better because it is more for a demo purpose anyway. Thanks.
RomanDA
Reply #3 Tuesday, May 1, 2007 9:42 AM
no problem.

You should see my desktop, its a mess of test text objects, each running its own script trying to find different things.

I like it cause i can leave them all out there, different colors, fonts, sizes, just to see what works.

I use a lot of TEST text objects when im debugging code, make test1.text test2.text etc.. and put them on the desktop and pass things like "made it this far, var1=.." so i can see what DX is doing.
RomanDA
Reply #4 Tuesday, May 1, 2007 9:46 AM
Quick Q,
I love the formatting above, how did you do that in html?
ZubaZ
Reply #5 Tuesday, May 1, 2007 9:57 AM
I love the formatting above, how did you do that in html?

There is a button on the toolbar with two brackets and text between them.
Click that box and choose your format.  Paste your code in between
Like this:
Code: html
  1. <html>
  2. <body>
  3. The content of the body element is displayed in your browser.
  4. </body>
  5. </html>

RomanDA
Reply #6 Tuesday, May 1, 2007 10:36 AM
verrry nice Zu.. thanks.
SirSmiley
Reply #7 Tuesday, May 1, 2007 10:52 AM
I use a lot of TEST text objects when im debugging code, make test1.text test2.text etc.. and put them on the desktop and pass things like "made it this far, var1=.." so i can see what DX is doing.


Yeah, things do tend to get a little messy when you get going on a project. I added an addin folder under my object development folder which has helped considerably.

I'm tracking some of my projects from start to finish using Todolist which has lead to another object idea of plotting projects to the desktop using the bar charts. Funny how that happens.

Just a note on the code tags when you go to edit it, your code still gets screwed up but usually I'm posting from the object so, it's an easy work-a-round.
thomassen
Reply #8 Tuesday, May 1, 2007 1:48 PM
The reason for not wanting to use msgbox is that it can get into loops at places, and really mess you up.

yea, Evil Msgbox Loop of Doom!
RomanDA
Reply #9 Tuesday, May 1, 2007 2:06 PM
yea, Evil Msgbox Loop of Doom!


why isnt there a CTRL+C to kill the script?


I have lost more code that way, its why i HATE using them now, i put things into text objects, so that even if there is a loop, who the heck cares. I can still STOP the script.

I had spent close to 3 hrs on a gadget, it was doing something stupid "somewhere" so i put in a "msgbox stringhere" into the place where i wanted to see the stringhere var, well crap, it was in the middle of a 100 ms loop.. in about 3 seconds i had 300 msgbox windows all over my screen. NOT GOOD!!

So.. no more msgbox! LOL
SirSmiley
Reply #10 Tuesday, May 1, 2007 4:03 PM
I think I've got the answer to that somewhere in my script library. It halts the script until the message box is dealt with. ie. ok/close/cancel,etc.
RomanDA
Reply #11 Tuesday, May 1, 2007 4:14 PM
yeah you can do that..
but its result = MsgBox(prompt[, buttons][, title][, helpfile, context])

But when you just want something to show up on the screen as feedback.. thats how you get in trouble.

but that is a good idea.
sViz
Reply #12 Thursday, May 3, 2007 7:30 AM
This is a very nice script. I see what you meant about the icon location. Some work some don't. I'll definitely put this in the updated version of the script helper.


Oh, yeah and it's...

First, I'd like to say sorry to sviz as I sent this to her & it was probably discombobulated


No worries, though. Thanks again, SirS.

SirSmiley
Reply #13 Thursday, May 3, 2007 11:19 AM
Oops! Sorry about that. Guess I should read people's profiles instead of just looking at their galleries.

Please login to comment and/or vote for this skin.

Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:

  • Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
  • Access to a great community, with a massive database of many, many areas of interest.
  • Access to contests & subscription offers like exclusive emails.
  • It's simple, and FREE!



web-wc01