MSFN Forum: lnk file target path - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

lnk file target path batch Rate Topic: -----

#1 User is offline   sweept 

  • Junior
  • Pip
  • Group: Members
  • Posts: 55
  • Joined: 08-November 05

Posted 09 October 2009 - 04:28 AM

I need a batch that will tell the targets path from dragging a lnk file on to it ...

thanks


#2 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 9,095
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 09 October 2009 - 06:25 AM

This should do:
@ECHO OFF
IF %1.==. GOTO :EOF
IF NOT EXIST %~dpnx1 GOTO :EOF
ECHO %~dpnx1
IF NOT %~x1.==.lnk. GOTO :EOF
more %~dpnx1 | FIND ":\" | FIND /V "/"
pause


jaclaz

#3 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,195
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 09 October 2009 - 07:44 AM

The following works with Win7 shortcuts.
@More "%~dpn1.lnk" 2>Nul|Findstr ":\\."&&Ping -n 6 127.0.0.1>Nul
Just drag and drop the shortcut onto it to see it in action.

#4 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,019
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 09 October 2009 - 10:07 AM

Here is the VBS script way of getting the lnk path. This script can handle multiple .lnk files being drag and drop on to it self.

Quote

 Dim Obj, Act :Set Act = CreateObject("WScript.Shell")
   If Not Wscript.Arguments.Count = 0 Then
	For Each Obj In WScript.Arguments
	 If InStr(LCase(obj),LCase(".lnk")) Then
	   Act.Popup vbCrLf & Act.CreateShortcut(obj).TargetPath,5,"ShortCut Path",4128
	 End If
	Next 
   End If


#5 User is offline   sweept 

  • Junior
  • Pip
  • Group: Members
  • Posts: 55
  • Joined: 08-November 05

Posted 03 January 2010 - 07:55 PM

first-of thanks for the help guys
Had problems posting lately &thanks is due...

now to further refine Yzöwl's code that worked here in batch :

from the current batch output result * how to omit just the "\target.file" (from the right end of the line & so that only the path folder directory is shown.)

thanks

#6 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,195
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 04 January 2010 - 06:53 AM

You'll need to use a few more lines by implementing a 'For loop'

Something like this should do:
@Echo off & Setlocal & Set "P_="
If "%~1" Neq "" (If Exist "%~1" (If /I %~x1 Equ .lnk (
			For /F "tokens=*" %%# In ('More "%~f1"^|Findstr ":\\."') Do (
				Set "P_=%%~dp#"))))
If Defined P_ (Set "P_=%P_:~,-1%" & Call Echo/%%P_%% & Ping -n 6 127.0.0.1>Nul)


#7 User is offline   sweept 

  • Junior
  • Pip
  • Group: Members
  • Posts: 55
  • Joined: 08-November 05

Posted 24 February 2010 - 07:02 AM

so far this worked perfectly for me .. thanks again!

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy