我无法删除桌面上的文件(所有用户),但我可以删除没有脚本

它在wshShell.Run上崩溃。

你可以看到我运行了一个WScript.Echo,它打印了文件名的位置。 当我运行它时,它说“系统找不到指定的文件”

我尝试objFile.delete,但它说权限被拒绝。 如果我在命令提示符下执行“del”,它将起作用。

For Each objFile In colFiles bMatch = objRE.Test(objFile.Name) If bMatch Then WScript.Echo objFile.Name WScript.Echo objFile.Path Set wshShell = WScript.CreateObject ("WSCript.shell") wshShell.Run "del " & objFile.Path, 1, True Set wshShell = Nothing End If Next 

产量

 Lotus Notes 8.5.lnk C:\Users\Public\Desktop\Lotus Notes 8.5.lnk (null) (79, 3) : (null) 

——————更新——————下面的作品完美,如果它在用户桌面上(而不是AllUsersDesktop)。 我试图从AllUsersDesktop中删除它

 For Each objFile In colFiles bMatch = objRE.Test(objFile.Name) If bMatch Then objFile.Delete End If Next 

应用下面的代码后,我得到这个错误

 Lotus Notes 8.5.lnk C:\Users\Public\Desktop\Lotus Notes 8.5.lnk (null) (81, 3) : (null) 

代码:(更新于5月23日)

 Set objShell = CreateObject("WScript.Shell") strCurrentDirectory = objShell.SpecialFolders("AllUsersDesktop") Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.Namespace(strCurrentDirectory) Set objFolderItem = objFolder.Self Set objFolder = objFS.GetFolder(strCurrentDirectory) Set colFiles = objFolder.Files Set objRE = New RegExp objRE.Global = True objRE.IgnoreCase = True objRE.Pattern = "notes" For Each objFile In colFiles bMatch = objRE.Test(objFile.Name) If bMatch Then WScript.Echo objFile.Name WScript.Echo objFile.Path Set wshShell = WScript.CreateObject ("WSCript.shell") wshShell.Run "del """ & objFile.Path & """", 1, True Set wshShell = Nothing End If Next 

这应该做到这一点:

 wshShell.Run "del """ & objFile.Path & """", 1, True 

路径中有一个空格,所以应该用双引号括起来,比如"del \"" & objFile.Path & "\"" ,或者任何用于转义的VB语法。