国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#控制IE進程關閉和緩存清理的實現代碼

2020-01-24 02:42:35
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

class IEUtil {
    public static void openIE(string url) {
        try {
            //System.Diagnostics.Process.Start(url);
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "iexplore.exe";
            p.StartInfo.Arguments = url;
            p.Start();
        } catch(Exception ex) {
            Log.logger("openIE" + url + "----------" + ex.Message);
        }
    }
    public static void closeAllIEProcess() {
        string defaultBrowserName = GetDefaultBrowerName();
        System.Diagnostics.Process[] procs = System.Diagnostics.Process.GetProcessesByName("IEXPLORE");
        foreach(System.Diagnostics.Process proc in procs) {
            proc.Kill();
        }
    }
    public static void CleanCookie() {
        try {
            string[] theFiles = System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Cookies), "*", System.IO.SearchOption.AllDirectories);
            foreach(string s in theFiles) FileDelete(s);
        } catch(Exception e) {
            Log.logger("Delete cookie error" + e.Message);
        }
    }
    static bool FileDelete(string path) {
        //first set the File's ReadOnly to 0
        //if EXP, restore its Attributes
        System.IO.FileInfo file = new System.IO.FileInfo(path);
        System.IO.FileAttributes att = 0;
        bool attModified = false;
        try {
            //### ATT_GETnSET
            att = file.Attributes;
            file.Attributes &= (~System.IO.FileAttributes.ReadOnly);
            attModified = true;
            file.Delete();
        } catch(Exception e) {
            if (attModified) file.Attributes = att;
            return false;
        }
        return true;
    }
    public static string GetDefaultBrowerName() {
        string mainKey = @"http/shell/open/command";
        string nameKey = @"http/shell/open/ddeexec/Application";
        string strRet = string.Empty;
        try {
            RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(nameKey);
            strRet = regKey.GetValue("").ToString();
        } catch {
            strRet = "";
        }
        return strRet;
    }
    /// <summary>
    /// 清除文件夾
    /// </summary>
    /// <param name="path">文件夾路徑</param>
    static void FolderClear(string path) {
        System.IO.DirectoryInfo diPath = new System.IO.DirectoryInfo(path);
        if (diPath.Exists) {
            foreach(System.IO.FileInfo fiCurrFile in diPath.GetFiles()) {
                FileDelete(fiCurrFile.FullName);
            }
            foreach(System.IO.DirectoryInfo diSubFolder in diPath.GetDirectories()) {
                FolderClear(diSubFolder.FullName);
                // Call recursively for all subfolders
            }
        }
    }
    /// <summary>
    /// 執行命令行
    /// </summary>
    /// <param name="cmd"></param>
    static void RunCmd(string cmd) {
        ProcessStartInfo p = new ProcessStartInfo();
        p.FileName = "cmd.exe";
        p.Arguments = "/c " + cmd;
        p.WindowStyle = ProcessWindowStyle.Hidden; // Use a hidden window
        Process.Start(p);
    }
    /// <summary>
    /// 刪除臨時文件
    /// </summary>
    public static void CleanTempFiles() {
        FolderClear(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
        RunCmd("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8");
    }
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 从化市| 海安县| 黄平县| 黔江区| 南靖县| 会理县| 光山县| 都江堰市| 金华市| 视频| 潜山县| 华安县| 出国| 防城港市| 沁源县| 宁强县| 临清市| 金乡县| 德保县| 通榆县| 建水县| 北宁市| 长顺县| 浦东新区| 曲靖市| 英吉沙县| 扬州市| 淮阳县| 茌平县| 齐齐哈尔市| 土默特右旗| 黑龙江省| 武冈市| 信阳市| 吉安县| 潼关县| 永清县| 樟树市| 华容县| 滨州市| 淮北市|