清除Cookies
/// <summary>
/// 清除Cookies
/// </summary>
void ClearCookies()
{
const int cookies = 33;
Shell32.Folder objFolder;// 需要引用 Shell32.dll
Shell32.FolderItems objFolderItems;
Shell32.ShellClass objShell;
objShell = new Shell32.ShellClass();
objFolder = objShell.NameSpace(cookies);
objFolderItems = objFolder.Items();
foreach (Shell32.FolderItem objFolderItem in objFolderItems)
{
if (!"index.dat".Equals(objFolderItem.Name.ToLower()))
{
System.IO.File.Delete(objFolderItem.Path.ToString());
}
}
}
代码很简单,没什么好说的.
就是把Cookies文件夹里面的内容都删除了,因为文件"index.dat"是不能删除的,所以排除在外.
另:
Shell32.ShellClass.NameSpace(object vDir)可以获取很多系统目录,参数的枚举值如下:
typedef enum {
ssfALTSTARTUP = 0x1d,
ssfAPPDATA = 0x1a,
ssfBITBUCKET = 0xa,
ssfCOMMONALTSTARTUP = 0x1e,
ssfCOMMONAPPDATA = 0x23,
ssfCOMMONDESKTOPDIR = 0x19,
ssfCOMMONFAVORITES = 0x1f,
ssfCOMMONPROGRAMS = 0x17,
ssfCOMMONSTARTMENU = 0x16,
ssfCOMMONSTARTUP = 0x18,
ssfCONTROLS = 0x3,
ssfCOOKIES = 0x21,
ssfDESKTOP = 0x0,
ssfDESKTOPDIRECTORY = 0x10,
ssfDRIVES = 0x11,
ssfFAVORITES = 0x6,
ssfFONTS = 0x14,
ssfHISTORY = 0x22,
ssfINTERNETCACHE = 0x20,
ssfLOCALAPPDATA = 0x1c,
ssfMYPICTURES = 0x27,
ssfNETHOOD = 0x13,
ssfNETWORK = 0x12,
ssfPERSONAL = 0x5,
ssfPRINTERS = 0x4,
ssfPRINTHOOD = 0x1b,
ssfPROFILE = 0x28,
ssfPROGRAMFILES = 0x26,
ssfPROGRAMS = 0x2,
ssfRECENT = 0x8,
ssfSENDTO = 0x9,
ssfSTARTMENU = 0xb,
ssfSTARTUP = 0x7,
ssfSYSTEM = 0x25,
ssfTEMPLATES = 0x15,
ssfWINDOWS = 0x24
} ShellSpecialFolderConstants;