时间:2021-05-20
复制代码 代码如下:
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");
}
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了C#操作windows系统进程的方法。分享给大家供大家参考。具体如下:这段代码演示了如何根据进程名关闭进程和启动进程//////关闭进程///pr
效果如下:C#实现代码?12345678910111213141516171819202122232425262728293031323334353637usi
本文实例讲述了C#关闭指定名字进程的方法。分享给大家供大家参考。具体实现方法如下:publicstaticvoidstopNamedProcess(string
本文实例讲述了C#实现启动,关闭与查找进程的方法。分享给大家供大家参考,具体如下:运行效果截图如下:查找/列出进程很容易,但干掉进程得借助系统命令ntsd.ex
官方提供了curl、post、php、ruby的实现示例,并没有C#的官方示例。既然提供了post的方式,那么就可以用C#实现,下面是实现代码:ASP.net百