2021. 1. 25. 08:24ㆍ개발/C#
using System;
using System.Windows.Forms;
using System.Diagnostics;
namespace MagicBox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
listBox1.Items.Add("인터넷");
listBox1.Items.Add("계산기");
listBox1.Items.Add("CMD");
listBox1.Items.Add("Microsoft Excel");
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string a = listBox1.SelectedItem.ToString();
if (a == null)
{
MessageBox.Show("아무 것도 선택되지 않았습니다!");
}
if (a == "계산기")
{
Process.Start("calc.exe");
}
if (a == "CMD")
{
Process.Start("cmd.exe");
}
if (a == "Microsoft Excel")
{
Process.Start("Excel.exe");
}
if (a == "인터넷")
{
Process.Start("explorer.exe", "http://www.naver.com");
}
}
catch
{
MessageBox.Show("아무 것도 선택되지 않았습니다!");
}
}
private void button2_Click(object sender, EventArgs e)
{
//Process.Start("cmd.exe", "/C" + " " + textBox2.Text);
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.Arguments = "/C " + textBox1.Text;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
string txt = cmd.StandardOutput.ReadToEnd();
textBox2.Text = txt;
}
}
}
'개발 > C#' 카테고리의 다른 글
# 실행중인 프로세스 정보 가져오기 / 특정 프로세스 경로 가져오기 (0) | 2021.01.25 |
---|---|
# 일기 쓰고 텍스트 파일로 저장하는 간단한 프로그램 예제 (0) | 2021.01.25 |
# 구독자 조회 프로그램 예제 (0) | 2021.01.25 |
# 메뉴 고르기 프로그램 예제 코드 (0) | 2021.01.25 |
# 알람 시계 만들기 (0) | 2021.01.25 |