-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForm1.cs
80 lines (70 loc) · 2.12 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace SYSTEMCommandPrompt
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnOpenCommandPromptSYSTEM_Click(object sender, EventArgs e)
{
txtOutput.Clear();
TextWriter tw = new TextBoxWriter(txtOutput);
btnOpenCommandPromptSYSTEM.Enabled = false;
SystemCommandPromptLauncher launcher = new SystemCommandPromptLauncher(tw);
Thread t = new Thread(DoLaunch);
t.Name = "SystemCommandPromptLauncher";
t.Start(launcher);
}
bool closeRequested;
protected override void OnFormClosing(FormClosingEventArgs e)
{
if (!btnOpenCommandPromptSYSTEM.Enabled)
{
e.Cancel = true;
txtOutput.AppendText("Application will close shortly...\r\n");
closeRequested = true;
}
base.OnFormClosing(e);
}
void DoLaunch(object arg)
{
SystemCommandPromptLauncher launcher = (SystemCommandPromptLauncher)arg;
Exception failure = null;
try
{
launcher.LaunchIt();
}
catch (Exception ex)
{
failure = ex;
}
BeginInvoke((MethodInvoker)delegate ()
{
AfterLaunch(failure);
});
}
void AfterLaunch(Exception ex)
{
if (ex != null)
MessageBox.Show(this, ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
btnOpenCommandPromptSYSTEM.Enabled = true;
txtOutput.AppendText("Done!\r\n");
if (closeRequested)
this.Close();
}
}
}