C# 打開文件或打開文件夾


直接打開指定的文件

System.Diagnostics.Process.Start(v_OpenFilePath); 

直接打開目錄

string v_OpenFolderPath = @"目錄路徑"; 
System.Diagnostics.Process.Start("explorer.exe", v_OpenFolderPath);  

System.Diagnostics.Process.Start(); 能做什么呢?它主要有以下幾個功能:

1、打開某個鏈接網址(彈窗)。

2、定位打開某個文件目錄。

3、打開系統特殊文件夾,如“控制面板”等。

那么它是怎么實現這幾個功能的呢?在講應用前,我們先來看看Process.Star()的構造方法。

 

名稱 說明
Process.Start () 啟動(或重用)此 Process 組件的 StartInfo 屬性指定的進程資源,並將其與該組件關聯。
Process.Start (ProcessStartInfo) 啟動由包含進程啟動信息(例如,要啟動的進程的文件名)的參數指定的進程資源,並將該資源與新的 Process 組件關聯。
Process.Start (String) 通過指定文檔或應用程序文件的名稱來啟動進程資源,並將資源與新的 Process 組件關聯。
Process.Start (String, String) 通過指定應用程序的名稱和一組命令行參數來啟動一個進程資源,並將該資源與新的 Process 組件相關聯。
Process.Start (String, String, SecureString, String) 通過指定應用程序的名稱、用戶名、密碼和域來啟動一個進程資源,並將該資源與新的 Process 組件關聯起來。
Process.Start (String, String, String, SecureString, String) 通過指定應用程序的名稱和一組命令行參數、用戶名、密碼和域來啟動一個進程資源,並將該資源與新的 Process 組件關聯起來。

 

System.Diagnostics.Process.Start("notepad.exe");        -- 打開記事本

 

System.Diagnostics.Process.Start("calc.exe ");                -- 打開計算器

 

System.Diagnostics.Process.Start("regedit.exe ");           -- 打開注冊表

 

System.Diagnostics.Process.Start("mspaint.exe ");        -- 打開畫圖板

 

System.Diagnostics.Process.Start("write.exe ");              -- 打開寫字板

 

System.Diagnostics.Process.Start("mplayer2.exe ");        --打開播放器

 

System.Diagnostics.Process.Start("taskmgr.exe ");          --打開任務管理器

 

System.Diagnostics.Process.Start("eventvwr.exe ");          --打開事件查看器

 

System.Diagnostics.Process.Start("winmsd.exe ");           --打開系統信息

 

System.Diagnostics.Process.Start("winver.exe ");              --打開Windows版本信息

 

System.Diagnostics.Process.Start("mailto: "+ address);    -- 發郵件

 


 

shutdown.exe:

 

參數:-s 關機   -r重啟   -f強行   -t 時間    -a 取消關機   -l 注銷    -i 顯示用戶界面

 

System.Diagnostics.Process.Start("shutdown.exe","-r");              -- 關閉並重啟計算機

 

System.Diagnostics.Process.Start("shutdown.exe","-s -f");          -- 關閉計算機

 

System.Diagnostics.Process.Start("shutdown.exe","-s -f 30");     -- 30s后關閉計算機

 

System.Diagnostics.Process.Start("shutdown.exe","-l");               --注銷計算機

 

System.Diagnostics.Process.Start("shutdown.exe","-a");              --撤銷關閉計算機

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM