a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > 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");
    }
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 亚洲精品中文字幕乱码无线 | 午夜视频网| 亚洲国产视频一区 | 成人精品一区 | 操人网址 | 黄页网站大全在线观看 | 精品国产乱码久久久久久久 | 国产日韩精品一区二区在线观看播放 | 亚洲777| 日本不卡网站 | 99精品久久99久久久久 | 亚洲精品视频一区二区三区 | 亚洲一区二区三区四区在线 | 红杏aⅴ成人免费视频 | 欧美精品一区三区 | 欧美成人在线网站 | 成人在线播放 | 精品国产不卡一区二区三区 | 精品视频一区二区三区 | 午夜寂寞网站 | 超碰超碰97 | 欧美韩一区二区 | 国产精品久久久久一区二区三区 | 视频一区二区三区中文字幕 | 成人一级片视频 | 国产精品久久国产精品 | 日本三级电影天堂 | 欧美日韩免费一区二区三区 | 日韩一区二区在线观看视频 | 欧美一二三区在线 | 免费a视频在线 | 成人午夜电影网 | 国产精选一区二区三区 | 国产精品一二三区 | 久久二区三区 | 国产精品一区二区无线 | 精品欧美一区二区三区 | 秋霞久久 | 天天爽夜夜春 | 欧美一区二区国产 | 亚洲综合在线一区 |