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");
}
}
总结
以上是内存溢出为你收集整理的C#控制IE进程关闭和缓存清理的实现代码全部内容,希望文章能够帮你解决C#控制IE进程关闭和缓存清理的实现代码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)