C#擷取使用者案頭等特殊系統路徑

來源:互聯網
上載者:User

不同的作業系統,案頭的路徑不盡相同,而且隨著使用者安裝位置的不同也不同。
C#可以從Windows註冊表讀取得到使用者的特殊檔案夾(案頭、收藏夾等等)的位置。
代碼如下:

using Microsoft.Win32;namespace JPGCompact{    public partial class MainForm : Form    {        private void Test()        {            RegistryKey folders;            folders = OpenRegistryPath(Registry.CurrentUser, @"\software\microsoft\windows\currentversion\explorer\shell folders");            // Windows使用者案頭路徑            string desktopPath = folders.GetValue("Desktop").ToString();            // Windows使用者字型目錄路徑            string fontsPath = folders.GetValue("Fonts").ToString();            // Windows使用者近端分享路徑            string nethoodPath = folders.GetValue("Nethood").ToString();            // Windows使用者我的文件路徑            string personalPath = folders.GetValue("Personal").ToString();            // Windows使用者開始菜單程式路徑            string programsPath = folders.GetValue("Programs").ToString();            // Windows使用者存放使用者最近訪問文檔捷徑的目錄路徑            string recentPath = folders.GetValue("Recent").ToString();            // Windows使用者發送到目錄路徑            string sendtoPath = folders.GetValue("Sendto").ToString();            // Windows使用者開始菜單目錄路徑            string startmenuPath = folders.GetValue("Startmenu").ToString();            // Windows使用者開始菜單啟動項目錄路徑            string startupPath = folders.GetValue("Startup").ToString();            // Windows使用者收藏夾目錄路徑            string favoritesPath = folders.GetValue("Favorites").ToString();            // Windows使用者網頁曆史目錄路徑            string historyPath = folders.GetValue("History").ToString();            // Windows使用者Cookies目錄路徑            string cookiesPath = folders.GetValue("Cookies").ToString();            // Windows使用者Cache目錄路徑            string cachePath = folders.GetValue("Cache").ToString();            // Windows使用者應用程式資料目錄路徑            string appdataPath = folders.GetValue("Appdata").ToString();            // Windows使用者列印目錄路徑            string printhoodPath = folders.GetValue("Printhood").ToString();        }        private RegistryKey OpenRegistryPath(RegistryKey root, string s)        {            s = s.Remove(0, 1) + @"\";            while (s.IndexOf(@"\") != -1)            {                root = root.OpenSubKey(s.Substring(0, s.IndexOf(@"\")));                s = s.Remove(0, s.IndexOf(@"\") + 1);            }            return root;        }    }}
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.