zonble’s promptbook

2008 年 3 月 18 日

我的電腦 在使用 .Net Framwork 時讀取 MediaPath 目錄中的內容(續)

(續前篇)Windows 系統中,關於系統音效檔案位置的相關資訊,是寫在 Registry 中,不過,如果是照著前篇實作,應該(會像我一樣)很快就會發現一個問題:在 Windows Vista 裡頭,這段資訊的寫法,與 Windows XP 不太一樣:Windows XP 寫在 MediaPath 這個字串值裡頭,Windows Vista 則是寫在 MediaPathUnexpanded 裡頭。

所以,要抓取 Windows Vista 的系統音效目錄,要用下面這段 code:

RegistryKey registryKey = Registry.LocalMachine;
registryKey = registryKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion", false);
string MediaPathUnexpanded = registryKey.GetValue("MediaPathUnexpanded").ToString();
m_mediaPath = Environment.ExpandEnvironmentVariables(MediaPathUnexpanded);

另外,就是要判斷現在到底是在 Windows Vista 上,還是 XP 上:

public static bool IsVistaOrLater
{
get
{
return Environment.OSVersion.Platform ==
PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 6;
}
}

public static bool IsXp
{
get
{
return Environment.OSVersion.Platform ==
PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 5;
}
}

文章分類: — zonble @ 4:58 am #

3 項留言回應 »

  1. 在twitter上看到,
    可以買這個來用你的ADB鍵盤。

    來自 喵。 的 迴響留言 — 2008 年 3 月 24 日 @ 4:00 pm

  2. http://rubyurl.com/YcLr

    來自 喵。 的 迴響留言 — 2008 年 3 月 24 日 @ 5:31 pm

  3. 請複製貼上。

    來自 喵。 的 迴響留言 — 2008 年 3 月 24 日 @ 5:32 pm

留言回應

XHTML: 您可以使用的 HTML 語法如下: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Powered by WordPress 2.6.2, Yichi.org,
ideas and cares
.

Weizhong Yang(a.k.a zonble)
Email:zonble@gmail.com
AIM: zonble@man.com