利用shell32來完成,如下所示

 

//fileinfo 為檔案的路徑

private void ExeFile(string fileinfo)

        {

            if (File.Exists(fileinfo))

            {

                try

                {                                                   

                    System.Diagnostics.Process.Start(fileinfo);                  

                    

                }

                catch (Exception ex)

                {

 

                    Console.WriteLine("ExeFile ex:"+ex.Message);

                    System.Diagnostics.Process p = new System.Diagnostics.Process();

                    string filecommand="C:\\WINDOWS\\system32\\shell32.dll,OpenAs_RunDLL C:\\WINDOWS\\system32\\shell32.dll,OpenAs_RunDLL "+fileinfo;

                    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("rundll32.exe", filecommand);

                    p.StartInfo = psi;

                    p.Start();

                    

                }

                

            }

            else

            {

                //TODO:檔案不存在

                if (!DOFILEISEXISTSSWITCH)

                {

                    ....

                }

            }

        }

arrow
arrow
    全站熱搜

    狼翔月影 發表在 痞客邦 留言(0) 人氣()