星期日, 2月 24, 2008

c# 執行檔案

const int ERROR_FILE_NOT_FOUND = 2;
const int ERROR_ACCESS_DENIED = 5;

try
{
process1.StartInfo.FileName = Path;
process1.StartInfo.CreateNoWindow = true;
process1.Start();
}
catch (Win32Exception ee)
{
if (ee.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
Console.WriteLine(ee.Message + ". Check the path.");
}

else if (ee.NativeErrorCode == ERROR_ACCESS_DENIED)
{
// Note that if your word processor might generate exceptions
// such as this, which are handled first.
Console.WriteLine(ee.Message +
". You do not have permission to print this file.");
}
}

沒有留言: