启动和停止本地系统进程
1
using System;
2
using System.Drawing;
3
using System.Collections;
4
using System.ComponentModel;
5
using System.Windows.Forms;
6
using System.Data;
7
// 添加新的命名空间。
8
using System.Text;
9
using System.Diagnostics;
10
using Microsoft.Win32;
11![]()
12
namespace StartMSWordApp
13
{
14
/// <summary>
15
/// 启动和停止本地系统进程。
16
/// </summary>
17
public class Form1 : System.Windows.Forms.Form
18
{
19
private System.Windows.Forms.Button button1;
20
private System.Windows.Forms.RichTextBox richTextBox1;
21
private System.Windows.Forms.TextBox textBox1;
22
private System.Windows.Forms.Label label1;
23
private System.Windows.Forms.Button button2;
24
private System.Windows.Forms.OpenFileDialog openFileDialog1;
25
/// <summary>
26
/// 必需的设计器变量。
27
/// </summary>
28
private System.ComponentModel.Container components = null;
29![]()
30
public Form1()
31
{
32
//
33
// Windows 窗体设计器支持所必需的
34
//
35
InitializeComponent();
36![]()
37
//
38
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
39
//
40
}
41![]()
42
/// <summary>
43
/// 清理所有正在使用的资源。
44
/// </summary>
45
protected override void Dispose( bool disposing )
46
{
47
if( disposing )
48
{
49
if (components != null)
50
{
51
components.Dispose();
52
}
53
}
54
base.Dispose( disposing );
55
}
56![]()
57
Windows Form Designer generated code
137![]()
138
/// <summary>
139
/// 应用程序的主入口点。
140
/// </summary>
141
[STAThread]
142
static void Main()
143
{
144
Application.Run(new Form1());
145
}
146
public Process myProcess;
147
private void button1_Click(object sender, System.EventArgs e)
148
{
149
try
150
{
151
if(textBox1.Text.Length != 0)
152
{
153
myProcess = Process.Start(textBox1.Text);
154
myProcess.WaitForExit();
155
}
156
}
157
catch (Exception ee)
158
{
159
richTextBox1.Text += "异常:"+ee.ToString()+"\n";
160
}
161
}
162![]()
163
private void button2_Click(object sender, System.EventArgs e)
164
{
165
if(openFileDialog1.ShowDialog() == DialogResult.OK)
166
{
167
textBox1.Text = openFileDialog1.FileName;
168
}
169
}
170
}
171
}
172![]()
using System;2
using System.Drawing;3
using System.Collections;4
using System.ComponentModel;5
using System.Windows.Forms;6
using System.Data;7
// 添加新的命名空间。8
using System.Text;9
using System.Diagnostics;10
using Microsoft.Win32;11

12
namespace StartMSWordApp13
{14
/// <summary>15
/// 启动和停止本地系统进程。16
/// </summary>17
public class Form1 : System.Windows.Forms.Form18
{19
private System.Windows.Forms.Button button1;20
private System.Windows.Forms.RichTextBox richTextBox1;21
private System.Windows.Forms.TextBox textBox1;22
private System.Windows.Forms.Label label1;23
private System.Windows.Forms.Button button2;24
private System.Windows.Forms.OpenFileDialog openFileDialog1;25
/// <summary>26
/// 必需的设计器变量。27
/// </summary>28
private System.ComponentModel.Container components = null;29

30
public Form1()31
{32
//33
// Windows 窗体设计器支持所必需的34
//35
InitializeComponent();36

37
//38
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码39
//40
}41

42
/// <summary>43
/// 清理所有正在使用的资源。44
/// </summary>45
protected override void Dispose( bool disposing )46
{47
if( disposing )48
{49
if (components != null) 50
{51
components.Dispose();52
}53
}54
base.Dispose( disposing );55
}56

57
Windows Form Designer generated code137

138
/// <summary>139
/// 应用程序的主入口点。140
/// </summary>141
[STAThread]142
static void Main() 143
{144
Application.Run(new Form1());145
}146
public Process myProcess;147
private void button1_Click(object sender, System.EventArgs e)148
{149
try150
{151
if(textBox1.Text.Length != 0)152
{153
myProcess = Process.Start(textBox1.Text);154
myProcess.WaitForExit();155
}156
} 157
catch (Exception ee) 158
{ 159
richTextBox1.Text += "异常:"+ee.ToString()+"\n";160
} 161
}162

163
private void button2_Click(object sender, System.EventArgs e)164
{165
if(openFileDialog1.ShowDialog() == DialogResult.OK)166
{167
textBox1.Text = openFileDialog1.FileName;168
}169
} 170
}171
}172



浙公网安备 33010602011771号