private void OpenNotepad()
{
//声明一个程序信息类
System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
//设置外部程序名
Info.FileName = "notepad.exe";
//设置外部程序的启动参数(命令行参数)为test.txt
Info.Arguments = "test.txt";
//设置外部程序工作目录为 C:/
Info.WorkingDirectory = "C://";
//声明一个程序类
System.Diagnostics.Process Proc;
try
{
//启动外部程序
Proc = System.Diagnostics.Process.Start(Info);
}
catch (System.ComponentModel.Win32Exception exc)
{
MessageBox.Show("系统找不到指定的程序文件。/r{0}", exc.Message);
return;
}
}
private void BindProcess()
{
try
{
Process[] processOnComputer = Process.GetProcesses();
foreach (Process p in processOnComputer)
{
//进程名,物理内存,路径
this.listBox1.Items.Add(p.ProcessName + "---" + p.WorkingSet64.ToString() + "---" + p.MainModule.FileName);
}
this.Text = processOnComputer.Length.ToString();
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}//获取系统文件夹
string folder = System.Environment.GetFolderPath(Environment.SpecialFolder.System);
[转]C# 常用代码
最新推荐文章于 2025-04-09 06:34:16 发布