• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1833
  • Last Modified:

Delete 'Low' folder in Windows Vista using VBScript.

Hi guys. I have a problem deleting a folder in Windows Vista using VBScript. I want to delete the 'Low' folder under %userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\

This 'Low' folder is a super hidden folder. I have written a script which can delete a folder with subfolders inside it. But it does not work on 'Low'.

Thanks in advance.

::Pranav::
0
cyberpranav
Asked:
cyberpranav
  • 4
  • 4
1 Solution
 
RobSampsonCommented:
Pranav, as far I as I understand, whether a folder is hidden or not, as long as you have the NTFS permissions to access is, you should be able to explicitly delete it.
'=============
Set objNetwork = CreateObject("WScript.Network")
strUserName = objNetwork.UserName
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFolderToDelete = "C:\Documents and Settings\" & strUserName & "\AppData\Local\Microsoft\Windows\Temporary Internet Files\Low"
If objFSO.FolderExists(strFolderToDelete) = True Then
   objFSO.DeleteFolder strFolderToDelete, True
Else
   MsgBox "Folder does not exist"
End If
Set objFSO = Nothing
Set objNetwork = Nothing
'=============

That's a VBS file by the way.  Just create a text file, paste that in, and rename the extension from txt to vbs, then double-click it to delete the folder.

Regards,

Rob.
0
 
cyberpranavAuthor Commented:
Hi Rob. Thanks for the solution. After posting my question I too set out to write a VBScript which would do that. I have written a script below which works fine. This script deletes all files under Temporary Internet Files, including the Low folder.

Const TEMPORARY_INTERNET_FILES = &H20&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(TEMPORARY_INTERNET_FILES)
Set objFolderItem = objFolder.Self
strPath = objFolderItem.Path & "\*.*"
strPath1 = objFolderItem.Path & "\Low"
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(strPath)
If objFSO.FolderExists(strPath1) = True Then
   objFSO.DeleteFolder (strPath1)
Else
   MsgBox "Low does not exist."
End If

Now the funny part is....I am not able to delete the cookies using almost same technique,

Const COOKIES = &H21&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(COOKIES)
Set objFolderItem = objFolder.Self
strPath = objFolderItem.Path & "\*.*"
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(strPath)

When I run this script, I get a permission denied error. I tried running this under the Admin command prompt, but I get the same 'Permission Denied' error. But I can delete the 'Low' folder under the cookie folder without any problems.

Do you have any idea why?

::Pranav::
0
 
RobSampsonCommented:
With the cookies part, can you do this:
strPath = objFolderItem.Path & "\*"
objFSO.DeleteFile(strPath, True)

If that doesn't work, you may have to manually go through the files, because the Index.dat is always in use I think.

Try
Const COOKIES = &H21&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(COOKIES)
Set objFolderItem = objFolder.Self
Set objFSO = CreateObject("Scripting.FileSystemObject")
For each objFile In objFSO.GetFolder(objFolderItem.Path)
   If LCase(objFile.Name) <> "index.dat" Then
      objFSO.DeleteFile(objFile.Path, True)
   End If
Next

Regards,

Rob.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
cyberpranavAuthor Commented:
Thanks Rob for the code...I am getting a "Object doesnt suppor this property or method." error on line 6 of the script. Any idead why? I have a hunch that we cannot sift through files using that syntax...

Thanks.

::Pranav::
0
 
RobSampsonCommented:
Whooops, yeah I didn't test it....change
For each objFile In objFSO.GetFolder(objFolderItem.Path)

to
For each objFile In objFSO.GetFolder(objFolderItem.Path).Files

and it should be OK.

Regards,

Rob.
0
 
cyberpranavAuthor Commented:
Thats cool Rob. The script runs beautifully. Thanks a lot for your help.

Cheers...

::Pranav::
0
 
RobSampsonCommented:
Great! No problem....trust an "in use" file to always get in your way!  ;-)

Rob.
0
 
cyberpranavAuthor Commented:
Yes...you are right. I should have thought of that. Thanks a lot!

Cheers...

::Pranav::
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now