使用'objFSO.DeleteFile()'删除图标

时间:2013-09-13 10:09:42

标签: file-io vbscript

我有一个VBScript应该删除所有用户的桌面图标并用干净的版本替换它们,但由于某种原因它不会删除。

如果我手动删除,则会复制图标。但是,如果我注释掉副本行,然后运行脚本,则不会删除它们。没有错误发生。

有人可以建议问题是什么吗?

'****************************************************
'* Logon Script File For Users in the DD Domain     *
'* Purpose: Ensure required icons are on desktop    *
'****************************************************

Option Explicit

Dim objFSO                  ' A File System object (for checking files/folders exist, copying, and deleting)
Dim objShell                ' A shell object (for accessing special folders)
Dim user_name               ' The user name of the currently logged in user
Dim i                       ' Dummy for looping


'****************************************************
'* Create the required desktop icons                *
'****************************************************

' Set the desktop folder location
Set objShell = WScript.CreateObject("WScript.Shell")
desktop_location = objShell.SpecialFolders.Item("Desktop")

' Set the location where the files to copy can be found
desktop_icon_store = "\\videss\Shortcuts\Desktop\"

'Check that the users desktop location exists
If (objFSO.FolderExists(desktop_location)) Then

    ' Delete all files in the desktop folder
    objFSO.DeleteFile(desktop_location & "*.*")

    ' Copy all files to the desktop folder
    objFSO.CopyFile desktop_icon_store & "*.*", desktop_location, True

End IF


'****************************************************
'* Reset the objects and exit                       *
'****************************************************

Set objFSO = Nothing
Set objShell = Nothing

WScript.Quit

1 个答案:

答案 0 :(得分:1)

这里有一个简单的答案,突然恍然大悟 - 尾随\

将代码更改为诀窍 -

desktop_location = objShell.SpecialFolders.Item("Desktop") & "\"