PDA

View Full Version : سوال: اجرای چند خط دستور Command Prompt در سی شارپ



YasserDivaR
پنج شنبه 17 تیر 1395, 10:08 صبح
درود بر دوستان عزیز
یه سوال
این که چطوری میشه چند خط کد رو توسط Command Prompt در سی شارپ اجرا کرد
این کد اپدیت ویندوز رو تعمیر میکنه
net stop wuauserv
net stop cryptSvc
net stop bits
net stop msiserver
ren C:\Windows\SoftwareDistribution SoftwareDistribution.old
ren C:\Windows\System32\catroot2 catroot2.old
net start wuauserv
net start cryptSvc
net start bits
net start msiserver
pause

چطوری میشه این همه رو اجرا کنم بترتیب!

دقت کنید که یه دونه نیست چند تا دستوره که به ترتیب باید اجرا بشه!

Mahmoud.Afrad
پنج شنبه 17 تیر 1395, 15:58 عصر
string commands = @"..........";

ProcessStartInfo processInfo = new ProcessStartInfo("cmd.exe")
{
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true
};


Process p = new Process {StartInfo = processInfo};
p.Start();
p.StandardInput.WriteLine(commands);

YasserDivaR
پنج شنبه 17 تیر 1395, 18:03 عصر
string commands = @"..........";

ProcessStartInfo processInfo = new ProcessStartInfo("cmd.exe")
{
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true
};


Process p = new Process {StartInfo = processInfo};
p.Start();
p.StandardInput.WriteLine(commands);

ممنون از شما دوست عزیز ولی این که فقط یه خط رو میتونی بهش بدی
چجوری میشه کاری کرد همه رو اجرا کنه!

Mahmoud.Afrad
جمعه 18 تیر 1395, 00:10 صبح
چرا یک خط ؟! همه رو در متغیر کامند بزارید
string commands =
@"net stop wuauserv
net stop cryptSvc
net stop bits
net stop msiserver
del %WINDIR%\SoftwareDistribution
del %WINDIR%\system32\catroot2
net start wuauserv
net start cryptSvc
net start bits
net start msiserver
pause";