如何操作 VB 脚本中的参数?

how to manipulate argument in VB Script?

我正在尝试自动创建快捷方式,但不知道如何从参数中获取文件名。代码是 运行 作为:

cscript shortcut.vbs "c:\folder\targetfile.ext"

Set objFS=CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
strFile= objArgs(0)
Set objFile = objFS.OpenTextFile(strFile)
Set objFile = objFS.GetFile(strFile)
WScript.Echo objFile.Path 

Set oWS = WScript.CreateObject("WScript.Shell") 
sLinkFile = "c:\myfolder\myshortcut.lnk" 
Set oLink = oWS.CreateShortcut(sLinkFile) 
oLink.TargetPath = objFile.Path 
oLink.Save

是否可以在下一行中将用户指定的文件夹和从参数自动生成的文件名与 .lnk 扩展名结合起来

sLinkFile = "c:\myfolder\myshortcut.lnk"

像这样:

sLinkFile = "c:\myfolder\" + filenamefromargument(e.g targetfile) + ".lnk"

提前致谢:)

@Noodles 第一个建议会起作用——他的第二个建议只是意味着你应该在使用它之前分配 strFile = objArgs(0)

你的 'pseudo examples'
只是让每个人都感到困惑 您首先指定 "c:\folder\targetfile.ext" 作为参数
然后 sLinkFile = "c:\myfolder\myshortcut.lnk" 我认为你的意思是 sLinkFile = "c:\myfolder\myshortcut.ext"

您需要的第二部分是查看 FileSystemObject 方法以提取文件夹和基本名称 - 然后附加您的扩展名

类似于:

之后 strFile= objArgs(0)

插入此代码:

With objFS    
   strLinkFile = .GetParentFolderName(strFile) & .GetBaseName(strFile) & ".lnk"
End With