PDA

View Full Version : Clear:Temporary Internet Files + Opened Website Address Names + DNSCache+Cookies+Temp



Erdin? E. Ka
01-07-2007, 07:31 PM
Hi everyone, :hi:

I want to create a Excel Toolbar about clearing in my Win.XP.Pro O.S.;

"Clear Temporary Internet Files",
"Clear Opened Website Address Names",
"Clear DNS Cache",
"Clear Cookies", and
"Clear Temp"

So, i need 5 different VBA macro for this. :think:

Any ideas? Or what should i do?

Thanks in advance. :friends:

Erdin? E. Ka
01-09-2007, 04:29 PM
I think my questions were a little complicated...:think: Or these are not possible... :(

Ken Puls
01-09-2007, 09:27 PM
Complicated, yes. Impossible though? If you say it is, then Ivan Moala will come in here with a pre built tool that he's had lying around for a year to say it isn't. ;)

Okay, seriously, it has to be possible, as there are utilities to do this kind of thing, right?

Now, I'm going to display my lack of knowledge on the inner workings of some of this stuff, but it would seem to me that you could attack most of these by finding the directories and clearing out the files. I'm not saying I would do this, though, and don't blame me if you do it and it blows up, okay? :)

Let's examine temp files, though. There is usually a windows temp file somewhere on your machine. If you can't determine the directory via an API or by reading the registry, you should be able to store it in a registry key, even if it means having the user input it manually to your UI. Then it should be as simple as just using FSO, Dir, or Shell commands to delete all the files and folders in it.

Temp interent files and cookies should be similar, I think. The other two I'm not sure on though.

Help at all?

Emily
01-09-2007, 10:00 PM
For clear Cache in Temporary Internet Files, please refer attached file

To clear IE History file, still not solution yet. Please read
http://www.xtremevbtalk.com/showthread.php?t=229608&highlight=delete+ie+history+folder


Try this IEHistoryX Shareware
http://www.sharewareconnection.com/iehistoryx.htm (http://www.sharewareconnection.com/iehistoryx.htm)

Erdin? E. Ka
01-11-2007, 06:48 AM
Complicated, yes. Impossible though? If you say it is, then Ivan Moala will come in here with a pre built tool that he's had lying around for a year to say it isn't. ;) ...

As in an Advertisement says: "Impossible is Nothing" :) I believe it. :p Also i believe Ivan can do it as well. Maybe someone else too.


...Okay, seriously, it has to be possible, as there are utilities to do this kind of thing, right?

Now, I'm going to display my lack of knowledge on the inner workings of some of this stuff, but it would seem to me that you could attack most of these by finding the directories and clearing out the files. I'm not saying I would do this, though, and don't blame me if you do it and it blows up, okay? :) ...

:fighting:Don't make me red-hot Ken!! I will set the board on fire!!! :p

Opps!!!...

Please be cool Ken, you can be sure that so easy to get along with me. :cloud9:


... Let's examine temp files, though. There is usually a windows temp file somewhere on your machine. If you can't determine the directory via an API or by reading the registry, you should be able to store it in a registry key, even if it means having the user input it manually to your UI. Then it should be as simple as just using FSO, Dir, or Shell commands to delete all the files and folders in it.

Temp interent files and cookies should be similar, I think. The other two I'm not sure on though.

Help at all?

Ok Ken, i'll keep your suggestions. Thanks a lot. If i couldn't solve it, i'll write again here.

Erdin? E. Ka
01-11-2007, 09:35 AM
For clear Cache in Temporary Internet Files, please refer attached file

To clear IE History file, still not solution yet. Please read
http://www.xtremevbtalk.com/showthread.php?t=229608&highlight=delete+ie+history+folder


Try this IEHistoryX Shareware
http://www.sharewareconnection.com/iehistoryx.htm (http://www.sharewareconnection.com/iehistoryx.htm)


Hi Emily,

Thank you for your kindly helps. :hi:

Ken Puls
01-11-2007, 10:00 AM
If i couldn't solve it, i'll write again here.
And if you can solve it, can I assume that you'll submit it to the KB? ;)

Zack Barresse
01-11-2007, 11:27 AM
Here is a way of finding the Temp folder...

Option Explicit

Const WindowsFolder = 0
Const SystemFolder = 1
Const TemporaryFolder = 2

Sub ShellScriptExamples()

Dim objShell, objEnviron, objUser, objProcess, strTemp
Set objShell = CreateObject("WScript.Shell")
Set objEnviron = objShell.Environment
Set objUser = objShell.Environment("User")
Set objProcess = objShell.Environment("Process")

strTemp = objEnviron("TEMP")
strTemp = Replace(strTemp, "%SystemRoot%", objProcess("SYSTEMROOT"), 1, -1, vbTextCompare)

End Sub

Or in a function...

Function TempFolderPath() As String

Dim objShell, objEnviron, objUser, objProcess, strTemp
Set objShell = CreateObject("WScript.Shell")
Set objEnviron = objShell.Environment
Set objUser = objShell.Environment("User")
Set objProcess = objShell.Environment("Process")
strTemp = objEnviron("TEMP")
TempFolderPath = Replace(strTemp, "%SystemRoot%", objProcess("SYSTEMROOT"), 1, -1, vbTextCompare)

End Function

HTH

Emily
01-11-2007, 08:14 PM
firefytr,

IE History folder in \Documents and Settings\User\Local Settings\History
seems cannot be found in VBA.

excelliot
01-11-2007, 11:25 PM
I have downloaded above file & tried using that bit it is not able to delete "visited:" file & "Cookie:" shown in the list nor it is able to select one file & delete it. I am using MS Office Pro 2003 edition.

Ivan F Moala
01-12-2007, 01:22 AM
firefytr,

IE History folder in \Documents and Settings\User\Local Settings\History
seems cannot be found in VBA.

No you need to use APIs to get this....scripting is limited in what it gives you.

The CSIDL constant for that folder is &H22


NB: Below code for type should read

Private Type SH_ITEMID
cb As Long
abID As Byte
End Type

Private Type ITEMIDLIST
mkid As SH_ITEMID
End Type

WITHOUT THE underscore .....




'//
'// CSIDL values provide a unique system-independent way to identify special folders
'// used frequently by applications, but which may not have the same name or location
'// on any given system. For example, the system folder may be
'// "C:\Windows\System" on one system and "C:\Winnt\System32" on another, typically Work :-)

'// Tip:
'// Enum the CSIDL constants for easier data changing
'// Make sure Auto List Member is Ticked —
'// Displays a list that contains information that would logically complete the statement
'// at the current insertion point.
'// eg Typing in SpecFolders gives you all the Constants below

'// Here is The List I was able to gather = 53
'// Some of which may NOT be avail for your OS
'// Make it Public so it is avail to All your Modules
'//

Public Enum SpecFolders
CSIDL_APPDATA = &H1A
CSIDL_BITBUCKET = &HA
CSIDL_COMMON_DESKTOPDIRECTORY = &H19
CSIDL_COMMON_DOCUMENTS = &H2E
CSIDL_COMMON_FAVORITES = &H1F
CSIDL_COMMON_PROGRAMS = &H17
CSIDL_COMMON_STARTMENU = &H16
CSIDL_COMMON_STARTUP = &H18
CSIDL_COMMON_TEMPLATES = &H2D
CSIDL_COMMONALTSTARTUP = &H1E
CSIDL_COMMONAPPDATA = &H23
CSIDL_COMMONDESKTOP = &H0
CSIDL_COMMONMYMUSIC = &H35
CSIDL_COMMONMYPICTURES = &H36
CSIDL_COMMONMYVIDEOS = &H37
CSIDL_COMMONSTARTADMIN = &H2F
CSIDL_CONNECTIONS = &H31
CSIDL_CONTROLS = &H3
CSIDL_DRIVES = &H11
CSIDL_FAVORITES = &H6
CSIDL_FONTS = &H14
CSIDL_LOCALALTSTARTUP = &H1D
CSIDL_LOCALAPPDATA = &H1C
CSIDL_LOCALAPPMSCDBURNING = &H3B
CSIDL_LOCALCOOKIES = &H21
CSIDL_LOCALDESKTOPDIRECTORY = &H10
CSIDL_LOCALHISTORY = &H22
CSIDL_LOCALINTERNETCACHE = &H20
CSIDL_LOCALMYVIDEOS = &HE
CSIDL_LOCALSTARTADMIN = &H30
CSIDL_MSHOME = &H3D
CSIDL_MYMUSIC = &HD
CSIDL_MYPICTURES = &H27
CSIDL_NETHOOD = &H13
CSIDL_NETWORK = &H12
CSIDL_PERSONAL = &H5
CSIDL_PRINTERS = &H4
CSIDL_PRINTHOOD = &H1B
CSIDL_PROFILE = &H28
CSIDL_PROGRAM_FILES = &H26
CSIDL_PROGRAM_FILES_COMMON = &H2B
CSIDL_PROGRAM_FILES_COMMONX86 = &H2C
CSIDL_PROGRAM_FILESX86 = &H2A
CSIDL_PROGRAMS = &H2
CSIDL_RECENT = &H8
CSIDL_RESOURCES = &H39
CSIDL_SENDTO = &H9
CSIDL_STARTMENU = &HB
CSIDL_STARTUP = &H7
CSIDL_SYSTEM = &H25
CSIDL_SYSTEMX86 = &H29
CSIDL_TEMPLATES = &H15
CSIDL_WINDOWS = &H24
End Enum
'
'
'
'//

Private Type ****EMID
cb As Long
abID As Byte
End Type

Private Type ITEMIDLIST
mkid As ****EMID
End Type

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

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

Const MAX_PATH = 260

Sub API_GetSpecialFolder()
Dim Tmp As String
'// lets get the users special folder
Tmp = GetSpecialfolder(SpecFolders.CSIDL_LOCALHISTORY)
MsgBox "LOCAL HISTORY PATH:=" & Tmp
End Sub

Function GetSpecialfolder(CSIDL As Long) As String
Dim r As Long
Dim IDL As ITEMIDLIST
Dim strPath As String

r = SHGetSpecialFolderLocation(0, CSIDL, IDL)
If r = 0 Then
'// Create a buffer MAX
strPath = Space(MAX_PATH)
'// Get the path from the IDList
r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal strPath)
'// Remove the strings padded with chr(0)'s
GetSpecialfolder = Left(strPath, InStr(strPath, Chr(0)) - 1)
Exit Function
End If
GetSpecialfolder = vbNullString
End Function

Emily
01-12-2007, 02:42 AM
Thanks Ivan

But I cannot use Kill or Rmdir to delete the sub-folder in History folder


Regards
Emily

Emily
01-12-2007, 03:30 AM
I have downloaded above file & tried using that bit it is not able to delete "visited:" file & "Cookie:" shown in the list nor it is able to select one file & delete it. I am using MS Office Pro 2003 edition.

Private Sub Command3_Click()
Dim i As Long
For i = 0 To List1.ListCount - 1
CacheFile = List1.List(i)
'Cookies Not Delete
If InStr(CacheFile, "Cookie") = 0 Then
Call DeleteUrlCacheEntry(CacheFile)
End If
Next i
' Refresh
GetCacheURLList
End Sub

matthewspatrick
01-12-2007, 12:07 PM
Here is a little recursive routine I use:




Sub PurgeTempInternetDir()
Dim FileCount As Long
Dim StartAt As Date
Dim EndAt As Date

StartAt = Now

DoPurge "C:\Documents and Settings\" & Environ("username") & "\Local Settings\" & _
"Temporary Internet Files", FileCount

EndAt = Now

MsgBox "Done; cleared " & Format(FileCount, "#,##0") & " files in " & _
Round(86400 * (EndAt - StartAt), 0) & " seconds"

End Sub
Sub DoPurge(ByVal FolderStr As String, ByRef FileCount As Long)
Dim fso As Object
Dim fld As Object
Dim subf As Object
Dim fil As Object
On Error Resume Next

Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(FolderStr)

Err.Clear

For Each fil In fld.Files
If LCase(fil.Name) <> "index.dat" And LCase(fil.Name) <> "desktop.ini" Then
fil.Delete
If Err = 0 Then
FileCount = FileCount + 1
Else
Err.Clear
End If
End If
Next

For Each subf In fld.SubFolders
DoPurge subf.Path, FileCount
Next

Set fil = Nothing
Set subf = Nothing
Set fld = Nothing
Set fso = Nothing

End Sub

stanl
01-12-2007, 03:15 PM
No offense meant to anyone... but with freeware products like Cleaner 4.0 and cCleaner... why would anyone want to even consider trying to write this stuff in VBA:banghead:

Stan

matthewspatrick
01-12-2007, 03:16 PM
In my case, Stan, it was just curiosity as to whether I could do it :)

Ken Puls
01-12-2007, 05:04 PM
No offense meant to anyone... but with freeware products like Cleaner 4.0 and cCleaner... why would anyone want to even consider trying to write this stuff in VBA:banghead:

Patrick sort of beat me to it, but I was going to say that in the pursuit of knowledge we don't necessarily have to have a practical purpose for it.

I'll stick with cCleaner myself as well. :)

excelliot
01-22-2007, 02:51 AM
Still i am not able to get rid off entries shown by "Cookies:" & "Visited:" in that window.

Erdin? E. Ka
02-21-2007, 06:07 PM
Hi everyone, finally i am back again... :whistle:

I miss you all, i am late but i found a code for one of this issue.

It's about DNS Cache clearing:


Sub FLUSH_DNS()
'Taken From: _
http://blogs.msdn.com/aaron_margosis/archive/2004/06/23/163229.aspx
On Error Resume Next
strComputer = "ITLWWS02"
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
vBatPath = "C:\temp\"
vBatFile = "flushdns.bat"
vLocBatFile = vBatPath & vBatFile
vRemBatFile = "\\" & strComputer & "\c$\temp\"
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists(vLocBatFile) Then fs.DeleteFile (vLocBatFile)
If fs.FileExists(vRemBatFile) Then fs.DeleteFile (vRemBatFile)

Set vOutputFile = fs.CreateTextFile(vLocBatFile, True)
vOutputFile.WriteLine "ipconfig /flushdns"
vOutputFile.WriteLine "echo flushdns Completed"
vOutputFile.WriteLine "echo flushdns Completed > c:\temp\flushdns.log"
fs.CopyFile vLocBatFile, vRemBatFile
CmdLine = vLocBatFile
Path = "c:\test"
Set objwbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objwbemServices = objwbemLocator.ConnectServer(strComputer, "", "", "", "", "", 0, Null)
Set Process = objwbemServices.Get("Win32_Process", 0, Null)
Process.Create CmdLine, Path, , ProcessID
wscript.echo "Complete"
End Sub


But, the problem is; doing nothing on my pc. while run the code... :think:

Loves... :hi: