使用VBS复制lnk文件

时间:2011-05-18 17:35:36

标签: file scripting file-io vbscript windows-scripting

这是我的代码

Const ALL_USERS_DESKTOP = &H19&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(ALL_USERS_DESKTOP)
Set objFolderItem = objFolder.Self
Wscript.Echo objFolderItem.Path
objFSO.CopyFile "\\server\folder\folder\Name of File 8.5.lnk" , objFolderItem.Path , OverwriteExisting

在最后一行给我一个错误。我不确定问题是什么,但我认为它与lnk文件有关。如果我输入bat文件或txt文件,则会复制该文件。 lnk会出错。

使用VBSEdit作为我的编辑器和CScript(不是WScript)

错误讯息是 C:\用户\公用\桌面 Microsoft VBScript运行时错误(18,1):权限被拒绝

我知道我可以访问服务器和文件夹。我也可以复制所有其他非lnk文件

-------------更新-----

我使用以下

修改了代码
Const DESKTOP = &H10&
Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(DESKTOP)
    Set objFolderItem = objFolder.Self
    Wscript.Echo objFolderItem.Path
    objFSO.CopyFile "\\server\folder\folder\Name of File 8.5.lnk" , objFolderItem.Path , OverwriteExisting

同样的事情。它说权限被拒绝(甚至是我自己的桌面)。使用鼠标,我可以在没有密码或特殊权限的桌面上创建我想要的任何内容。

2 个答案:

答案 0 :(得分:1)

我认为您的目标路径上可能需要一个尾部斜杠,因为它引用了文件夹:

objFSO.CopyFile "\\server\folder\folder\Name of File 8.5.lnk" , objFolderItem.Path & "\" , True

没有斜杠,您试图覆盖该文件夹,因此拒绝了权限。

答案 1 :(得分:1)

我不得不重新创建快捷方式,因为VBS不会复制它。

Set Shell = CreateObject("WScript.Shell") 
DesktopPath = Shell.SpecialFolders("Desktop") 
Set link = Shell.CreateShortcut(DesktopPath & "\shortcut.lnk") 
link.TargetPath = "C:\dir\filename.vbs"  ' the location where you store the file on the server 
link.Arguments = ""
link.Description = "Shortcut"
link.HotKey = "CTRL+L"
link.IconLocation = "C:\dir\filename.ico"
link.WindowStyle = 1
link.WorkingDirectory = "C:\dir"
link.Save 
相关问题