Pages

Showing posts with label script to delete folder from user profile. Show all posts
Showing posts with label script to delete folder from user profile. Show all posts

Friday, 8 June 2012

VBScript to Delete User folders or files on Windows 7

Following script deletes folder by searching each user profile on windows7





Dim FSfolder 
Dim subfolder 
Dim i 


set objshell = CreateObject("Wscript.shell") 
Set FSO = CreateObject("Scripting.FileSystemObject")
Profile = strSysDrive & "C:\Users"
Set FSfolder = FSO.GetFolder(Profile) 'getting the user profile folders




'starting of the loop to delete the HKCUs


For Each subfolder In FSfolder.SubFolders


   If (subfolder.Name <> "All Users" And  subfolder.Name <> "Default User"_
   and subfolder.Name <> "LocalService" and subfolder.Name <> "NetworkService") Then


folder1=Profile & "\" & subfolder.Name & "\AppData\Local\TechSmith\Snagit"




DeleteThisFolder(folder1)




   end if


Next 


'*******************************************************************************************************


Function DeleteThisFolder(FolderName)


    If FSO.FolderExists(FolderName) Then
    objshell.Run "CMD.EXE /C RD /S /Q """ & FolderName & """",0,True 
    End If


End Function