日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C#ASP.NET执行BAT批处理代码

發布時間:2024/1/17 C# 58 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#ASP.NET执行BAT批处理代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? ?因公司內網服務器的軟加密服務進程會不定時的卡死,需要手工關閉進程再啟動,每次出現類似問題總要用遠程服務器或者進入機房操作機器,但有時是晚上不是很方便,但遠程的密碼和機房鑰匙又不方便給他人,因此想到以下解決方法。
??? 做一個BAT批處理文件來通過stop/start來關閉和啟動服務,正好服務器上已有IIS+.NET2.0,就寫了一個aspx頁面,讓員工發現無法使用時,通過訪問該網頁點擊bottom事件執行BAT文件來解決。
??? 以下是C#源代碼
??? using System;
??? using System.Collections.Generic;
??? using System.Web;
??? using System.Web.UI;
??? using System.Web.UI.WebControls;
??? namespace WebApplication3
??? {
??? public partial class _Default : System.Web.UI.Page
??? {
??? protected void Page_Load(object sender, EventArgs e)
??? {
??? }
??? protected void Button1_Click(object sender, EventArgs e)
??? {
??? System.Diagnostics.ProcessStartInfo pro = new System.Diagnostics.ProcessStartInfo("cmd.exe");
??? pro.UseShellExecute = false;
??? pro.RedirectStandardOutput = true;
??? pro.RedirectStandardError = true;
??? pro.Arguments = "/K D:\\jiamiError\\test.bat";
??? pro.WorkingDirectory = "D:\\jiamiError\\";
??? System.Diagnostics.Process proc = System.Diagnostics.Process.Start(pro);
??? System.IO.StreamReader sOut = proc.StandardOutput;
??? proc.Close();
??? string results = sOut.ReadToEnd()。Trim();
??? sOut.Close();
??? string fmtStdOut = "<font face=courier size=0>{0}</font>";
??? this.Response.Write(String.Format(fmtStdOut, results.Replace(System.Environment.NewLine, "<br>")));
??? /*Response.Write("<script>alert('修復成功!'); </script>");*/
??? /*Response.Redirect("Success.html");*/
??? }
??? }
??? }

轉載于:https://blog.51cto.com/3403450/953702

總結

以上是生活随笔為你收集整理的C#ASP.NET执行BAT批处理代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。