//下面是.Net得sdk里的using System; using System.Diagnostics; using System.ComponentModel;namespace MyProcessSample { /// <summary> /// Shell for the sample. /// </summary> public class MyProcess { // These are the Win32 error code for file not found or access denied. const int ERROR_FILE_NOT_FOUND =2; const int ERROR_ACCESS_DENIED = 5; /// <summary> /// Prints a file with a .doc extension. /// </summary> public void PrintDoc() { Process myProcess = new Process();
try { // Get the path that stores user documents. string myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); myProcess.StartInfo.FileName = myDocumentsPath + "\\MyFile.doc"; myProcess.StartInfo.Verb = "Print"; myProcess.StartInfo.CreateNoWindow = true; myProcess.Start(); } catch (Win32Exception e) { if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND) { Console.WriteLine(e.Message + ". Check the path."); } else if (e.NativeErrorCode == ERROR_ACCESS_DENIED) { // Note that if your word processor might generate exceptions // such as this, which are handled first. Console.WriteLine(e.Message + ". You do not have permission to print this file."); } } } public static void Main() { MyProcess myProcess = new MyProcess(); myProcess.PrintDoc(); } } }
/// 启动外部程序
/// </summary>
/// <param name="_FileName">外部程序名--比如说"Note.exe"</param>
/// <param name="_WorkingDirectory">外部程序工作目录--比如说"C:\"</param>
public void StartEXE(string _FileName,string _WorkingDirectory)
{
//声明一个程序信息类
ProcessStartInfo Info = new ProcessStartInfo(); //设置外部程序名
Info.FileName = _FileName; //设置外部程序工作目录
Info.WorkingDirectory = "@" + _WorkingDirectory; //声明一个程序类
Process Proc ;
try
{
//
//启动外部程序
//
Proc = Process.Start(Info);
}
catch(Win32Exception h)
{
throw new Exception("系统找不到指定的程序文件。\r{0}", h);
}
}
System.Diagnostics.Process.Start(@"c:\test.html");
using System.Diagnostics;
using System.ComponentModel;namespace MyProcessSample
{
/// <summary>
/// Shell for the sample.
/// </summary>
public class MyProcess
{
// These are the Win32 error code for file not found or access denied.
const int ERROR_FILE_NOT_FOUND =2;
const int ERROR_ACCESS_DENIED = 5; /// <summary>
/// Prints a file with a .doc extension.
/// </summary>
public void PrintDoc()
{
Process myProcess = new Process();
try
{
// Get the path that stores user documents.
string myDocumentsPath =
Environment.GetFolderPath(Environment.SpecialFolder.Personal); myProcess.StartInfo.FileName = myDocumentsPath + "\\MyFile.doc";
myProcess.StartInfo.Verb = "Print";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
}
catch (Win32Exception e)
{
if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
Console.WriteLine(e.Message + ". Check the path.");
} else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
{
// Note that if your word processor might generate exceptions
// such as this, which are handled first.
Console.WriteLine(e.Message +
". You do not have permission to print this file.");
}
}
}
public static void Main()
{
MyProcess myProcess = new MyProcess();
myProcess.PrintDoc();
}
}
}