中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [求助]cmd如何从.lnk文件中找到实际的路径
作者:
标题: [求助]cmd如何从.lnk文件中找到实际的路径 上一主题 | 下一主题
hxuan999
中级用户

DOS之日


积分 337
发帖 161
注册 2006-11-4
状态 离线
『楼 主』:  [求助]cmd如何从.lnk文件中找到实际的路径

在cmd下如何可以从一个.lnk文件中找到它实际所指的路径呀!

我用%1得到一个快捷方式的路径,但我候用的是这个快捷方式所指的文件的路径,
如何可以得到呢??

谢谢!



for /f %%h in (`echo hxuan`) do for /f %%x in (`echo hxuan`) do if %%h==%%x nul
2007-11-6 16:02
查看资料  发送邮件  发短消息 网志  OICQ (33899867)  编辑帖子  回复  引用回复
abcd
银牌会员





积分 1436
发帖 739
注册 2007-10-11
状态 离线
『第 2 楼』:  

mshta vbscript:msgbox(createobject("wscript.shell").createshortcut(%1).targetpath)(window.close)

2007-11-6 16:15
查看资料  发短消息 网志  OICQ (470237592)  编辑帖子  回复  引用回复
hxuan999
中级用户

DOS之日


积分 337
发帖 161
注册 2006-11-4
状态 离线
『第 3 楼』:  

多谢楼上的兄弟,你方法没能返回给我这个路径,要返回也比较麻烦,我找到另一个方法,
    more 快捷方式.lnk|find ":\"|find /v "/"

来自下面的这个贴子:

  Quote:
[讨论]批处理 / 命令行一句话技巧收集专贴

[ Last edited by hxuan999 on 2007-11-6 at 04:32 PM ]



for /f %%h in (`echo hxuan`) do for /f %%x in (`echo hxuan`) do if %%h==%%x nul
2007-11-6 16:29
查看资料  发送邮件  发短消息 网志  OICQ (33899867)  编辑帖子  回复  引用回复
abcd
银牌会员





积分 1436
发帖 739
注册 2007-10-11
状态 离线
『第 4 楼』:  

不能显示路径???

2007-11-6 16:42
查看资料  发短消息 网志  OICQ (470237592)  编辑帖子  回复  引用回复
my3439955
中级用户




积分 272
发帖 99
注册 2006-6-2
状态 离线
『第 5 楼』:  


Data = "4D5A00000000000000000000504500004C010200534C58210000000000000000E0000F010B01000000000000000800000000000054010000001000000C00000000004000001000000002000004000000000000000400000000000000004000000002000000000000020000000000100000100000000010000010000000000000100000000000000000000000483400008400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000001000000000000000000000000000000000000000000000E00000C000000000000000000010000000300000C904000000020000000000000000000000000000E00000C087258C344000619455A4B680FF1373F933C9FF13731633C0FF13731FB68041B010FF1312C073FA753AAAEBE0FF530802F683D901750EFF5304EB24ACD1E8742D13C9EB189148C1E008ACFF53043B43F8730A80FC05730683F87F77024141958BC5B600568BF72BF0F3A45EEB9F5EAD97AD50FF5310958B074078F37503FF630C5055FF5314ABEBEE33C941FF1313C9FF1372F8C302D275058A164612D2C34B45524E454C33322E646C6C0000F5381640190717081913E73119FF027F499911550967123D2485489791312225441B7389054C303752170823873DB3C131CD2909B320916D2959249C2230024578700E6C6F726541202F6E2CCD53E3E7A36374C50F182E466E6B0FCCC85308D000B6D4D82042726F770D7365466944ED2EB80275142225312800B3C9B9A6B0B2D7E75E20420FDEDC79CD536812D9784650AF61662B5C7368BED87600B2E9D5D2C4BFB1EA0F28264229A3636F6D88616E64C2480114028E2B0AC006B81546EE10B10B01C236E14C01A0E015A0D981EC30500316A801750E188AC86A0780C992880D8717FF436410180CA304178D4470240C50681811146A6F01442F08341E778885C01D7D09330A81C4410CC38B4D8D74541E04565286086828493A50FFFA0FF085F67CBD868C2458453B8D84AA4C89FE04C10B506AFF51BA96E4913C5877088D558C1E9F26519810745214A93B238735048D4C450C19174268B48D3C670A8C4F0C820F3D5B2C7618A32D7D14DEB4A895C77A0F9D555E729B909A0102EBCC0403B9084208D47B0253555657BEE4AF80AF7CA118F3A566C8A4B9620537BECC90133C50CA28A4A13C45BBD4A944A80CE8832E140A010F8535AA8333DBB945605DD68DBC24C192703B889CFBC60FBEB4531CF3AB6685AAB90619686254BD8EA9132A331A6C6436983821351C42678CA0355051FFD6F694A80B68ACCD2F521F07A19AFA9218012A02535168997F80700823741274665E678E5352476A065ED94F30ED504C20048C191E5553181858B714885F5E645DF85B840C21FDC21059748DE615203B0C7750923D241452E036A46BE113EBFD077E885C743229FE2CF558FE98A6A224152CBACFB9630C165F2C3C6858A2242A515283ED4A7C953521404F5C2194B80784D80315379121C4D9033795017C1ABDAC131F8B4504D58C43500494D1DFD524545D64204283C40C88DE1DAA50A0180F84709899869CB822488C20CCD67DBC8883E9150403C1C9245C36C4308C4975686B7F9824B3ED72102A5250E82EC5FC0C35B94D6A4A7E0C9F68F5487C2C91D9C83A4D6A16206AD1D42B88706AEFA20FA272A44A348B299234B0C96F0002E843FDD1E497222890CD8501384752E52EA4B0A1FB1BDA11844428170844914C2264457CF224965001E1D815C21594F814ACE085E80155D04D75076C746942794065546F57F064EC431B6861722D0F166E4578AC63156C1E737472076D70410A0CCF68795BA1656E0C48F0613F70467DFD0847F8747B503E6F63B873D1161D36EFA4363D4A4333784C7CC4574112C857B7F29A43CE0F4BA7524E304C33322E38646CD140099FFC6F777565AB4EC17370FB4C6AD2400D4DC75F616751426F78A61CC2346E2934EC65677A433B6F733C4B29790E1853E656613F6C75E5D241642010BDA1412109138A254F70DC2110B91D44564A5049847A1CAFA03441722A6776B5285348A687A734442151496E46FB5482C91336411CD8CB75F06F7A21BDFAD72E647844E109127F41830E4C5746DF6D4201AEFAD800000000A03400000000000000000000F2010000A03400000000000000000000000000000000000000000000001040000030400008154000000000009034400080000000007D000070344000E8014000DC014000DE014000E0144000AA340000B8340000000000004C6F61644C69627261727941000047657450726F634164647265737300"

With CreateObject("ADODB.Stream"):.Type = 1:.Open:.Write StrToByte(data):.SaveToFile GetTargetFileName, 2:.Close:End With

Function GetTargetFileName
    Set objDialog = CreateObject("UserAccounts.CommonDialog")
    objDialog.Filter = "All Files|*.*"
    objDialog.InitialDir = "."
    If objDialog.ShowOpen = 0 Then
        WScript.Quit
    Else
        GetTargetFileName = objDialog.FileName
    End If
    Set objDialog = Nothing
End Function

Function StrToByte(str)
        Set xmldoc = CreateObject("Microsoft.XMLDOM")
        xmldoc.loadXML "<?xml version=""1.0""?>"
        Set pic = xmldoc.createElement("pic")
        pic.dataType = "bin.hex"
        pic.nodeTypedValue = str
        StrToByte = pic.nodeTypedValue
End Function
这是通用的查找目标的小程序 不知道是不是这个效果



X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
2007-11-6 16:59
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
my3439955
中级用户




积分 272
发帖 99
注册 2006-6-2
状态 离线
『第 6 楼』:  

如果感觉上面的不大适合脚本使用

那么试试下面的vbs脚本吧

其中也包含了分析具体路径的正则表达式方法

速度上不及上面的二进制工具

加 /U 参数可以卸载新加的菜单项
Option Explicit
On Error Resume Next
Dim FSO, WS, ASO, objIE, WorkScript, TargetFileName
Const adTypeText = 2
Const DlgTitle = "By Shilyx 2007.4.8 oversleep@163.com"

Set FSO = CreateObject("Scripting.FileSystemObject")
Set WS = WScript.CreateObject("WScript.Shell")
Set ASO = CreateObject("ADODB.Stream")

WorkScript = WS.ExpandEnvironmentStrings("%WinDir%") & "\system32\GetSCPath.vbs"

If WScript.Arguments.Count = 0 Then
    FSO.CopyFile WScript.ScriptFullName, WorkScript, True
    WS.RegWrite "HKCR\LnkFile\Shell\FindTarget\", "复制路径到剪贴板(&C)"
    WS.RegWrite "HKCR\LnkFile\Shell\FindTarget\Command\", "WScript " & WorkScript & " /C" & " ""%1""", "REG_SZ"
    WS.RegWrite "HKCR\LnkFile\Shell\ShowTarget\", "查找目标(&F)"
    WS.RegWrite "HKCR\LnkFile\Shell\ShowTarget\Command\", "WScript " & WorkScript & " /F" & " ""%1""", "REG_SZ"
    MsgBox "快捷方式快捷管理脚本安装成功", vbOKOnly + vbInformation, DlgTitle
    WScript.Quit
End If

If LCase(WScript.Arguments(0)) = "/u" Then
    If FSO.FileExists(WorkScript) Then FSO.DeleteFile(WorkScript)
    WS.RegDelete "HKCR\LnkFile\Shell\FindTarget\Command\"
    WS.RegDelete "HKCR\LnkFile\Shell\FindTarget\"
    WS.RegDelete "HKCR\LnkFile\Shell\ShowTarget\Command\"
    WS.RegDelete "HKCR\LnkFile\Shell\ShowTarget\"
    MsgBox "快捷方式快捷管理脚本卸载成功", vbOKOnly + vbInformation, DlgTitle
    WScript.Quit
End If
  
If Not FSO.FileExists(WScript.Arguments(1)) Then
    MsgBox "找不到指定的文件", vbOKOnly + vbExclamation, DlgTitle
    Wscript.Quit
End If

If LCase(Right(WScript.Arguments(1), 4)) <> ".lnk" Then
    MsgBox "指定快捷方式文件不合法", vbOKOnly + vbCritical, DlgTitle
    Wscript.Quit
End If

TargetFileName = RegExpTest("[c-z]:(\\[^||]*)*\.exe", GetVisualText(WScript.Arguments(1)))
If TargetFileName = "" Then
    MsgBox "在此快捷方式中没有找到可能的Exe文件指向", vbCritical, DlgTitle
    WScript.Quit
End if

If WScript.Arguments(0) = "/C" Then
    CopyToClipBoard TargetFileName
    MsgBox "已复制到剪贴板" & vbCrLf & vbCrLf & TargetFileName, vbInformation, DlgTitle
ElseIf WScript.Arguments(0) = "/F" Then
    If FSO.FileExists(TargetFileName) Then WS.Run "Explorer /n,/Select,""" & TargetFileName & """"
End If

Function RegExpTest(patrn, strng)
    Dim regEx, Match, Matches
    Set regEx = New RegExp
    regEx.Pattern = patrn
    regEx.IgnoreCase = True
    regEx.Global = False
    Set Matches = regEx.Execute(strng)
    For Each Match in Matches
        RegExpTest = Match.Value
    Next
End Function

Function GetVisualText(FileName)
    Dim ch
    ASO.Type = adTypeText
    ASO.Open
    ASO.LoadFromFile FileName
    ASO.Position = 0
    ASO.CharSet = "GB2312"
    GetVisualText = ""
    Do While Not aso.EOS
        ch = ASO.ReadText(1)
        If ((Asc(ch) > 31) And (Asc(ch) < 127)) Or Asc(ch) < 0 Then  
            GetVisualText = GetVisualText + Chr(Asc(ch))
        Else
            GetVisualText = GetVisualText + "|"
        End If
    Loop
    ASO.Close
End Function

Sub CopyToClipBoard(Text)
    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.Navigate("about:blank")
    objIE.Document.ParentWindow.ClipboardData.SetData "text", Text          'GetData可以获得内容
    objIE.Quit
End Sub




X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
2007-11-6 17:04
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: