Sử Dụng Lệnh Command Window Trong C# | NguoiLeoNui's Blog

Hi, bạn đang xây dựng một phần mềm có đụng chạm tới hệ thống Window, thao tác copy, paste file, hoặc là chạy một phần mềm khác. Vậy làm thế nào để chạy chúng, đơn giản là chúng ta sẽ sử dụng lệnh command window. Nào chúng ta hay cũng bắt đầu

Chúng ta sẽ sử dụng lớp

  • Process
  • ProcessInfo

Hai lớp này nằm trong System.Diagnostics

Hãy chèn lệnh này vào code của bạn using System.Diagnostics

Code:

public void excuteCmd(String command) { ProcessStartInfo procStart= new ProcessStartInfo(“cmd”,”/c “+command); //Khởi tạo lớp processStartInfo, //Tham số đầu là chương chạy //Tham số thứ 2 là lệnh command “/c “+command

//Thuộc tính của Process procStart.RedirectStandardOutput = true; //Trả về giá trị procStart.UseShellExecute = false; procStart.CreateNoWindow = true;//Không hiện cửa sổ window khi chạy Process proc=new Process(); String result = proc.StandardOutput.ReadToEnd();//Trả về giá trị từ lệnh command System.Writeln(resullt); }

Chúc bạn thành công

Share this:

  • X
  • Facebook
Like Loading...

Related

Post navigation

Hiển thị CloseButton trong XtraTab (Devxpress)

Leave a comment Cancel reply

Δ

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use. To find out more, including how to control cookies, see here: Cookie Policy
  • Comment
  • Reblog
  • Subscribe Subscribed
    • NguoiLeoNui's Blog
    • Sign me up
    • Already have a WordPress.com account? Log in now.
    • NguoiLeoNui's Blog
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Copy shortlink
    • Report this content
    • View post in Reader
    • Manage subscriptions
    • Collapse this bar
%d Design a site like this with WordPress.comGet started

Từ khóa » Chạy Lệnh Cmd Trong C#