There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
VBScript Noob Nees Help!


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
DaveY625's Avatar
Member with 44 posts.
 
Join Date: Nov 2007
22-Jul-2008, 02:37 PM #1
VBScript Noob Nees Help!
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's Avatar
Distinguished Member with 4,819 posts.
 
Join Date: Apr 2007
Location: India
Experience: Advanced
23-Jul-2008, 06:32 AM #2
this vbscript will delete all files for all user profiles under temp , cookies and temporary internet files folder

Code:
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's Avatar
Member with 44 posts.
 
Join Date: Nov 2007
23-Jul-2008, 10:53 AM #3
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's Avatar
Distinguished Member with 4,819 posts.
 
Join Date: Apr 2007
Location: India
Experience: Advanced
23-Jul-2008, 11:36 AM #4
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's Avatar
Member with 44 posts.
 
Join Date: Nov 2007
23-Jul-2008, 04:00 PM #5
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
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:11 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.