cscの作法 その79

# 概要
cscの作法、調べてみた。
Processしてみた。

# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/60f882c0-efee-6de0-fe8c-9dba26e6c587.png)

# 参考にしたページ

https://qiita.com/kewpie134134/items/d70feef6319949120389

# コンパイル手順

```
>set PATH=C:\Windows\Microsoft.NET\Framework\v4.0.30319;%PATH%

>csc pro7.cs

```

# サンプルコード

```
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;

namespace WpfApp1
{
	public partial class Form1 : Form {
		Button button1;
		Button button2;
		Button button3;
		Button button4;
		Button button5;
		Button button6;
		Button button7;
		Button button8;
		Button button9;
		Button button10;
		public Form1() {
			ClientSize = new Size(400, 400);
			Text = "Note";
			button1 = new Button() {
				Location = new Point(10, 10),
				Size = new Size(80, 80),
				Text = "コンピューター名",
			}; 
			button2 = new Button() {
				Location = new Point(110, 10),
				Size = new Size(80, 80),
				Text = "ユーザー名",
			}; 
			button3 = new Button() {
				Location = new Point(210, 10),
				Size = new Size(80, 80),
				Text = "OS の情報",
			}; 
			button4 = new Button() {
				Location = new Point(10, 110),
				Size = new Size(80, 80),
				Text = "ペイント起動",
			}; 
			button5 = new Button() {
				Location = new Point(110, 110),
				Size = new Size(80, 80),
				Text = "メモ帳起動",
			}; 
			button6 = new Button() {
				Location = new Point(210, 110),
				Size = new Size(80, 80),
				Text = "メモ帳終了",
			}; 
			button7 = new Button() {
				Location = new Point(10, 210),
				Size = new Size(80, 80),
				Text = "PC画面のみ",
			}; 
			button8 = new Button() {
				Location = new Point(100, 210),
				Size = new Size(80, 80),
				Text = "複製表示",
			}; 
			button9 = new Button() {
				Location = new Point(190, 210),
				Size = new Size(80, 80),
				Text = "拡張表示",
			}; 
			button10 = new Button() {
				Location = new Point(280, 210),
				Size = new Size(80, 80),
				Text = "モニターのみ",
			}; 
			Controls.Add(button1);
			Controls.Add(button2);
			Controls.Add(button3);
			Controls.Add(button4);
			Controls.Add(button5);
			Controls.Add(button6);
			Controls.Add(button7);
			Controls.Add(button8);
			Controls.Add(button9);
			Controls.Add(button10);
			button1.Click += button1_Click;
			button2.Click += button2_Click;
			button3.Click += button3_Click;
			button4.Click += button4_Click;
			button5.Click += button5_Click;
			button6.Click += button6_Click;
			button7.Click += button7_Click;
			button8.Click += button8_Click;
			button9.Click += button9_Click;
			button10.Click += button10_Click;
		}
		private void button1_Click(object sender, EventArgs e) {
			MessageBox.Show(GetLocalMachineName());
		}
		public string GetLocalMachineName() {
			return Environment.MachineName;
		}
		private void button2_Click(object sender, EventArgs e) {
			MessageBox.Show(GetLocalUserName());
		}
		public string GetLocalUserName() {
			return Environment.UserName;
		}
		private void button3_Click(object sender, EventArgs e) {
			MessageBox.Show(GetOSName());
		}
		public string GetOSName() {
			return System.Environment.OSVersion.ToString();
		}
		private void button4_Click(object sender, EventArgs e) {
			System.Diagnostics.Process.Start(@"c:\Windows\System32\mspaint.exe");
		}
		private void button5_Click(object sender, EventArgs e) {
			System.Diagnostics.Process.Start(@"c:\Windows\System32\notepad.exe");
		}
		private void button6_Click(object sender, EventArgs e) {
			System.Diagnostics.Process[] ps = System.Diagnostics.Process.GetProcessesByName("notepad");
			foreach (System.Diagnostics.Process p in ps)
			{
				p.Kill();
			}
		}
		private void button7_Click(object sender, EventArgs e) {
			System.Diagnostics.Process.Start(@"c:\Windows\System32\DisplaySwitch.exe", "/internal");
		}
		private void button8_Click(object sender, EventArgs e) {
			System.Diagnostics.Process.Start(@"c:\Windows\System32\DisplaySwitch.exe", "/clone");
		}
		private void button9_Click(object sender, EventArgs e) {
			System.Diagnostics.Process.Start(@"c:\Windows\System32\DisplaySwitch.exe", "/extend");
		}
		private void button10_Click(object sender, EventArgs e) {
			System.Diagnostics.Process.Start(@"c:\Windows\System32\DisplaySwitch.exe", "/external");
		}
		[STAThread]
		static void Main() {
			Application.Run(new Form1());
		}
	}
}





```

以上。