使用VBS复制lnk文件
这是我的代码
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
。它说权限被拒绝(即使是我自己的桌面)。使用鼠标,我可以在桌面上创建任何我想要的内容,而无需密码或特殊权限。
Here is my code
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
Gives me an error on last line. I'm not sure what the problem is but I think it has to do with the lnk file. If I put a bat file or a txt file, the file gets copied. The lnk gives an error.
Using VBSEdit as my editor and CScript (not WScript)
Error message is
C:\Users\Public\Desktop
Microsoft VBScript runtime error (18, 1) : Permission denied
I know that I have access to the server and folder. I also can copy all the other non lnk files
------------- UPDATE -----
I modified the code with the following
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
Same thing. It says Permission denied (even to my own desktop). Using the mouse, I can create anything I want on my desktop without a password or special privs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我必须重新创建快捷方式,因为 VBS 不会复制它。
I had to recreate the shortcut because VBS wont copy it.
我认为您的目标路径可能需要一个尾部斜杠,因为它指的是文件夹:
如果没有斜杠,您将尝试覆盖该文件夹,因此权限被拒绝。
I think you might need a trailing slash on your detination path as it refers to the folder:
Without the slash, you are trying to overwrite the folder, hence permission denied.