使用VBS复制lnk文件

发布于 2024-11-07 22:18:34 字数 1046 浏览 0 评论 0原文

这是我的代码

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

口干舌燥 2024-11-14 22:18:35

我必须重新创建快捷方式,因为 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 

I had to recreate the shortcut because VBS wont copy it.

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 
我的痛♀有谁懂 2024-11-14 22:18:34

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

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

如果没有斜杠,您将尝试覆盖该文件夹,因此权限被拒绝。

I think you might need a trailing slash on your detination path as it refers to the folder:

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

Without the slash, you are trying to overwrite the folder, hence permission denied.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文