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