"Babu VT" <babuvt@xxxxxx> wrote in message
news:uFeetFN%23JHA.1248@xxxxxx
Quote:
> Hi,
> I'm trying to clean "$NTUninstall..." folders from remote machines and
> found the below snippet useful.Unfortunately it isn't deleting any
> folders.Can someone point me where is the fault... I can't use FSO objects
> since I need to delete folders in multiple machines where C$ shares might
> not be available.
>
> strComputer ="."
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
> strQueryString1 = "Select * from Win32_Directory where Name = '" &
> OSRootDir & "'"
> Set colSubfolders = objWMIService.ExecQuery (strQueryString1)
> For Each objFolder in colSubfolders
> If Instr( UCase(objFolder.Name), "$NTUNINSTALL" ) > 0 then
> strReport = strReport & "Deleted :" & strcomputer & ":" & objFolder.Name
> & " uninstall folder" & vbCrLf
> objFolder.delete
> End If
>
> Next
You need to assign a value to OSRootDir, e.g. "c:\\Windows". Alternatively
this Scripting Guy item might help:
How Can I Delete a Folder and All Its Subfolders?
http://www.microsoft.com/technet/scr...5/hey0405.mspx