0

警告我的 VB 知识为零

所以今天早上我发现了这个方便的脚本:

InputFile = "C:\MachineList.Txt"
Const DeleteReadOnly = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(InputFile)
Do While Not (objFile.AtEndOfStream)
strComputer = objFile.ReadLine
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("\\" & strComputer & "\c$\Documents and Settings\all users\Desktop\Malwarebytes Anti-Malware.LNK")
Err.Clear
Loop

MsgBox "Done"

它做得很好。我面临的问题是快捷方式并不总是在所有用户下,或者他们的名字让我们称之为 user1

因此,我希望它通过 MachineList.txt 并浏览所有配置文件以搜索 Malwarebytes Anti-Malware.LNK。我已经看到了一些关于此的脚本,但我无法在很短的时间内围绕 VB 进行思考。我很感激任何意见。

4

1 回答 1

1

我假设你提供的结果是有效的路径......因此这应该有效:

InputFile = "C:\MachineList.Txt"
Const DeleteReadOnly = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(InputFile)
Do While Not (objFile.AtEndOfStream)
    strComputer = objFile.ReadLine
    For Each objsubfolder In objFSO.GetFolder("\\" & strComputer & "\c$\Documents and Settings\").subfolders
        If objFSO.FileExists(objsubfolder.Path & "\desktop\Malwarebytes Anti-Malware.LNK") Then
            objFSO.DeleteFile (objsubfolder.Path & "\desktop\Malwarebytes Anti-Malware.LNK")
        End If
        'To check another file uncomment this
        'Add as many of these as you like here
        'If objFSO.FileExists(objsubfolder.Path & "\desktop\Otherfile.LNK") Then
        '    objFSO.DeleteFile (objsubfolder.Path & "\desktop\Otherfile.LNK")
        'End If
    Next
Loop

MsgBox "Done"
于 2012-10-29T14:27:43.377 回答