清除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;

转载于:https://www.cnblogs.com/tanjian/articles/1633225.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值