# VBScript Noob Nees Help!



## DaveY625 (Nov 20, 2007)

I need to make a script allowing me to clear the temporary internet files folder, the temp folder, and the cookies folder in the Documents and Settings folder for each profile on the drive letter submitted in an html I made. It needs to be a loop. 

I have this script I copied off the Microsoft.com website to work off of:

Const COOKIES = &H21&
Const TEMPORARY_INTERNET_FILES = &H20&

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(COOKIES)
Set objFolder = objShell.Namespace(TEMPORARY_INTERNET_FILES)
Set objFolderItem = objFolder.Self
strPath = objFolderItem.Path & "\*.*"

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(strPath)


----------



## devil_himself (Apr 7, 2007)

this vbscript will delete all files for all user profiles under temp , cookies and temporary internet files folder


```
Option Explicit

' Variables

Dim objWSH, sProfile, objFolder
Dim objFSO, sProfileRoot, objProfileFolder
Dim sTemp, sWindows

' Object Initialisation
 
set objFSO=CreateObject("Scripting.FileSystemObject")
 
' Get user profile root folder

set objWSH    = CreateObject("WScript.Shell")
sTemp = objWSH.ExpandEnvironmentStrings("%TEMP%")
sWindows = objWSH.ExpandEnvironmentStrings("%WINDIR%")
sProfile = objWSH.ExpandEnvironmentStrings("%USERPROFILE%")
sProfileRoot=objFSO.GetFolder(sProfile).ParentFolder.Path
set objWSH=nothing

' Main Code
 
set objProfileFolder=objFSO.GetFolder(sProfileRoot)
for each objFolder in objProfileFolder.SubFolders
        select case LCase(objFolder.Name)
                case "all users":
                case "default user":
                case "localservice":
                case "networkservice":
                case else:
                        sProfile=sProfileRoot & "\" & objFolder.Name
                        DeleteFolderContents sProfile & "\Local Settings\Temp"
			DeleteFolderContents sProfile & "\Local Settings\Temporary Internet Files"
			DeleteFolderContents sProfile & "\Cookies"

        end select
next

DeleteFolderContents sTemp
DeleteFolderContents sTemp

' Function
 
sub DeleteFolderContents(strFolder)
        ' Deletes all files in the specified folder and subfolders, but doesn't delete folders
        dim objFolder, objFile, objSubFolder
        on error resume next
        
        set objFolder=objFSO.GetFolder(strFolder)
        if Err.Number<>0 then
                Err.Clear
                Exit sub
        end if
        for each objSubFolder in objFolder.SubFolders
                objSubFolder.Delete true
        next
        for each objFile in ObjFolder.Files
                objFile.Delete true
        next
        Err.Clear
        
end sub
```


----------



## DaveY625 (Nov 20, 2007)

wow man, thanks! Is there anyway i can write it into the code not delete any profiles from the C: drive? I only want to delete other drives. if not, its ok


----------



## devil_himself (Apr 7, 2007)

what you mean by other drives ... does other drives have 'documents and settings' folder ?
what is the location of the folders on other drives you want to empty ?


----------



## DaveY625 (Nov 20, 2007)

its alright nvm, the code you gave me works fine for what i wanted to do.

yes, the other drives are other computer's HDDs that i be will plugging into a main computer. these drives will have Documents and Settings on them, etc. But its alright, thanks for your help. 

I mean, what would be awesome is if you could help me with this other script I am trying to write. See, I want a script that detects what fixed has the most free space on it and tells the user what disc that is. Here is what I have derived so far:


Option Explicit
Dim objWMIService, objItem, colItems, strComputer

On Error Resume Next
strComputer = "."

Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk")

For Each objItem in colItems
Wscript.Echo "Computer: " & objItem.SystemName & VbCr & _ 
" ==================================" & VbCr & _ 
"Drive Letter: " & objItem.Name & vbCr & _ 
"Drive Type: " & objItem.DriveType & vbCr & _ 
"Media Type: " & objItem.MediaType & vbCr & _ 
"Size: " & Int(objItem.Size /1073741824) & " GB" & vbCr & _ 
"Free Space: " & Int(objItem.FreeSpace /1073741824) & _
" GB" & vbCr & _ 
"" 
Next

WSCript.Quit


----------

