|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Delete Folders using WMII'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
Show quote
Hide quote
"Babu VT" <bab***@hotmail.com> wrote in message You need to assign a value to OSRootDir, e.g. "c:\\Windows". Alternatively news:uFeetFN%23JHA.1248@TK2MSFTNGP04.phx.gbl... > 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 this Scripting Guy item might help: How Can I Delete a Folder and All Its Subfolders? http://www.microsoft.com/technet/scriptcenter/resources/qanda/apr05/hey0405.mspx Babu VT wrote:
Show quoteHide quote > Hi, Rather than just deleting the uninstalls, I prefer to check the age of> 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 the folders just to be sure it is safe to remove them. That is why I wrote the following which will only delete the folders if they are more than 2 weeks old. [code] '======================================================================= === ' ' NAME: CleanHotfixUninstalls.vbs ' ' AUTHOR: Mark D. MacLachlan , The Spider's Parlor ' URL : http://www.thespidersparlor.com ' COPYRIGHT (c) 2008 All rights reserved ' DATE : 05/07/2008 ' ' COMMENT: ' ' This script will enumerate Uninstall folders under the Windows directory ' and delete them if they are more than two weeks old ' ' ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO ' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A ' PARTICULAR PURPOSE. ' ' IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS ' BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY ' DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, ' WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ' ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE ' OF THIS CODE OR INFORMATION. '===================================== Dim fso, WshShell Dim oFolder, oSubFolder Set fso = CreateObject("Scripting.FileSystemObject") Set WshShell=CreateObject("WScript.Shell") WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%") Path = WinDir Set oFolder = fso.GetFolder(Path) Set colSubfolders = oFolder.Subfolders For Each oSubfolder in colSubfolders If Left(oSubFolder.Name,1) = "$" Then If Right(oSubFolder.Name,1) = "$" Then 'If DateDiff("d", oSubFolder.DateCreated,Now) > 14 Then fso.DeleteFolder(oSubFolder) 'End If End If End If Next Set oSubFolder = Nothing Set oFolder = Nothing Set fso = Nothing [/code] -- Just realized the posted version had the two week check commented out.
[code] '======================================================================= === ' ' NAME: CleanHotfixUninstalls.vbs ' ' AUTHOR: Mark D. MacLachlan , The Spider's Parlor ' URL : http://www.thespidersparlor.com ' COPYRIGHT (c) 2008 All rights reserved ' DATE : 05/07/2008 ' ' COMMENT: ' ' This script will enumerate Uninstall folders under the Windows directory ' and delete them if they are more than two weeks old ' ' ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO ' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A ' PARTICULAR PURPOSE. ' ' IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS ' BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY ' DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, ' WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ' ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE ' OF THIS CODE OR INFORMATION. '===================================== Dim fso, WshShell Dim oFolder, oSubFolder Set fso = CreateObject("Scripting.FileSystemObject") Set WshShell=CreateObject("WScript.Shell") WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%") Path = WinDir Set oFolder = fso.GetFolder(Path) Set colSubfolders = oFolder.Subfolders For Each oSubfolder in colSubfolders If Left(oSubFolder.Name,1) = "$" Then If Right(oSubFolder.Name,1) = "$" Then If DateDiff("d", oSubFolder.DateCreated,Now) > 14 Then fso.DeleteFolder(oSubFolder) End If End If End If Next Set oSubFolder = Nothing Set oFolder = Nothing Set fso = Nothing [/code] Sorry for the repost, but I noticed I had the date checks commented out
on the previously posted version. [code] '======================================================================= === ' ' NAME: CleanHotfixUninstalls.vbs ' ' AUTHOR: Mark D. MacLachlan , The Spider's Parlor ' URL : http://www.thespidersparlor.com ' COPYRIGHT (c) 2008 All rights reserved ' DATE : 05/07/2008 ' ' COMMENT: ' ' This script will enumerate Uninstall folders under the Windows directory ' and delete them if they are more than two weeks old ' ' ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO ' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A ' PARTICULAR PURPOSE. ' ' IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS ' BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY ' DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, ' WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ' ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE ' OF THIS CODE OR INFORMATION. '===================================== Dim fso, WshShell Dim oFolder, oSubFolder Set fso = CreateObject("Scripting.FileSystemObject") Set WshShell=CreateObject("WScript.Shell") WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%") Path = WinDir Set oFolder = fso.GetFolder(Path) Set colSubfolders = oFolder.Subfolders For Each oSubfolder in colSubfolders If Left(oSubFolder.Name,1) = "$" Then If Right(oSubFolder.Name,1) = "$" Then If DateDiff("d", oSubFolder.DateCreated,Now) > 14 Then fso.DeleteFolder(oSubFolder) End If End If End If Next Set oSubFolder = Nothing Set oFolder = Nothing Set fso = Nothing [/code]
Scripting Language
DNS suffix search list... Robocopy - not providing destination in log output issue on scripting syntax on x64 Finding password protected files auto add sutdents to AD 2008 WMI & Eventlogs How to make goto when nowhere to go ? grab a String (server name) from log Script to diable the C:$ share |
|||||||||||||||||||||||