Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the API call to delete Cookies and Temporary Internet Files of 1

Status
Not open for further replies.

maupiti

Programmer
Oct 27, 2003
240
US
What is the API call to delete Cookies and Temporary Internet Files of a current user?

Tools --> Internet Options --> General TAB -->
Delete Cookies
Delete Files
 
You should be able to manage something with the SHGetSpecialFolderLocation API
Here's a couple of constants:

Public Const CSIDL_INTERNET_CACHE = &H20
Public Const CSIDL_COOKIES = &H21
Public Const CSIDL_HISTORY = &H22

 
Here's a full example of SHGetSpecialFolderLocation. Then use Kill to delete the files or the SHFileOperation API to send them to the recycle bin.
Code:
Public Type SHORTITEMID
    cb As Long
    abID As Integer
End Type

Public Type ITEMIDLIST
    mkid As ShortItemId
End Type

Declare Public Function SHGetPathFromIDList Lib _
"shell32.dll" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

Declare Public Function SHGetSpecialFolderLocation Lib _
"shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder _
As Long, pidl As ITEMIDLIST) As Long

Public Const CSIDL_DESKTOP = &H0 'Desktop
Public Const CSIDL_INTERNET = &H1 'Internet Explorer (icon on desktop)
Public Const CSIDL_PROGRAMS = &H2 'Start Menu\Programs
Public Const CSIDL_CONTROLS = &H3 'My Computer\Control Panel
Public Const CSIDL_PRINTERS = &H4 'My Computer\Printers
Public Const CSIDL_PERSONAL = &H5 'My Documents
Public Const CSIDL_FAVORITES = &H6 '<user name>\Favorites
Public Const CSIDL_STARTUP = &H7 'Start Menu\Programs\Startup
Public Const CSIDL_RECENT = &H8 '<user name>\Recent
Public Const CSIDL_SENDTO = &H9 '<user name>\SendTo
Public Const CSIDL_BITBUCKET = &HA '<desktop>\Recycle Bin
Public Const CSIDL_STARTMENU = &HB '<user name>\Start Menu
Public Const CSIDL_DESKTOPDIRECTORY = &H10 '<user name>\Desktop
Public Const CSIDL_DRIVES = &H11 'My Computer
Public Const CSIDL_NETWORK = &H12 'Network Neighborhood
Public Const CSIDL_NETHOOD = &H13 '<user name>\nethood
Public Const CSIDL_FONTS = &H14 'Windows\fonts
Public Const CSIDL_TEMPLATES = &H15
Public Const CSIDL_COMMON_STARTMENU = &H16 'All Users\Start Menu
Public Const CSIDL_COMMON_PROGRAMS = &H17 'All Users\Programs
Public Const CSIDL_COMMON_STARTUP = &H18 'All Users\Startup
Public Const CSIDL_COMMON_DESKTOPDIRECTORY = &H19 'All Users\Desktop
Public Const CSIDL_APPDATA = &H1A '<user name>\Application Data
Public Const CSIDL_PRINTHOOD = &H1B '<user name>\PrintHood
Public Const CSIDL_LOCAL_APPDATA = &H1C '<user name>\Local Settings\Applicaiton Data (non roaming)
Public Const CSIDL_ALTSTARTUP = &H1D 'non localized startup
Public Const CSIDL_COMMON_ALTSTARTUP = &H1E 'non localized common startup
Public Const CSIDL_COMMON_FAVORITES = &H1F
Public Const CSIDL_INTERNET_CACHE = &H20
Public Const CSIDL_COOKIES = &H21
Public Const CSIDL_HISTORY = &H22
Public Const CSIDL_COMMON_APPDATA = &H23 'All Users\Application Data
Public Const CSIDL_WINDOWS = &H24 'Windows Directory
Public Const CSIDL_SYSTEM = &H25 'System Directory
Public Const CSIDL_PROGRAM_FILES = &H26 'C:\Program Files
Public Const CSIDL_MYPICTURES = &H27 'C:\Program Files\My Pictures
Public Const CSIDL_PROFILE = &H28 'USERPROFILE
Public Const CSIDL_SYSTEMX86 = &H29 'x86 system directory on RISC
Public Const CSIDL_PROGRAM_FILESX86 = &H2A 'x86 C:\Program Files on RISC
Public Const CSIDL_PROGRAM_FILES_COMMON = &H2B 'C:\Program Files\Common
Public Const CSIDL_PROGRAM_FILES_COMMONX86 = &H2C 'x86 Program Files\Common on RISC
Public Const CSIDL_COMMON_TEMPLATES = &H2D 'All Users\Templates
Public Const CSIDL_COMMON_DOCUMENTS = &H2E 'All Users\Documents
Public Const CSIDL_COMMON_ADMINTOOLS = &H2F 'All Users\Start Menu\Programs\Administrative Tools
Public Const CSIDL_ADMINTOOLS = &H30 '<user name>\Start Menu\Programs\Administrative Tools
Public Const CSIDL_CONNECTIONS = &H31 'Network and Dial-up Connections
'_____________________________

Public Function fGetSpecialFolder(Byval lngCSIDL As Long) As String

 '--- Given a CSIDL constant, returns the path to a special folder

 Dim udtIDL As ITEMIDLIST
 Dim lngRtn As Long         'Return value
 Dim strFolder As String    'Buffer returned folder

 lngRtn = SHGetSpecialFolderLocation(Me.hWnd, _
 lngCSIDL, udtIDL)
 If lngRtn = 0 Then
  strFolder = Space$(260)
  lngRtn = SHGetPathFromIDList( _
  ByVal udtIDL.mkid.cb, ByVal strFolder)
  If lngRtn Then
   fGetSpecialFolder = Left$(strFolder, _
   InStr(1, strFolder, Chr$(0)) - 1)
  End If
 End If

End Function

Paul Bent
Northwind IT Systems
 
Hi paulbent. I used your code above to obtain the path to the temporary files as in
C:\Documents and Settings\Administrator\Local SettingsTemporary internet Files
Then I delete all files, but none was deleted. I then
created a text file named abc.txt and put it into this
directory, and this file got deleted, but not the internet cache. Apparently, the Scripting.FileSystemObject object
does not recognize the internet cache as conventional file.

The code below is the delete routine.

DrJavaJoe, do you know how to fix this ?

=====================================================
Private Sub Delete_Temporary_Files_Click()
Dim Temporary_File_Path As String

Temporary_File_Path = fGetSpecialFolder(CSIDL_INTERNET_CACHE) & &quot;\&quot;
Call Delete_Files(Temporary_File_Path)
End Sub

///////////////////////////////////////////////////

Public Sub Delete_Files(Temporary_File_Path)
On Error GoTo ErrorHandler


'Declare File System Variables
Dim object_File As Scripting.File
Dim object_FileSystem As Scripting.FileSystemObject
Dim object_Folder As Scripting.Folder


Set object_FileSystem = New Scripting.FileSystemObject
Set object_Folder = object_FileSystem.GetFolder(Temporary_File_Path) 'A:\WebOffice_VPN
MsgBox &quot;In Delete_Files Prodecure Temporary_File_Path = &quot; & Temporary_File_Path
MsgBox &quot;In Delete_Files Prodecure object_Folder = &quot; & object_Folder & &quot;\&quot;


For Each object_File In object_Folder.Files
object_FileSystem.DeleteFile Temporary_File_Path & &quot;\abc.txt&quot;

'If InStr(object_File.Name, &quot;Cookie&quot;) = 0 Then
' object_FileSystem.DeleteFile Temporary_File_Path & &quot;\&quot; & object_File.Name
'End If
Next object_File

End Sub
 
Hi DrJavaJoe. I am aware of that solution earlier this morning, but for the sake of learning I was just wondering why the Scripting.FileSystemObject does not delete internet cache file ?

The solution on the web site that you mentioned is a very good one. The problem here is it load eveything into a list. This use up processing time and memory. It is good for the purpose of seeing it. In my case, I don 't need to see it. I just need to delete it. Also, it makes the program a few Kilobytes larger because you have to have a list view object.

Of course, this is nothing since nowaday, since CPU and memory are cheap. However, a liitle bit does adds up. I am from the old conservative school of making codes efficient, fast and small.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top