2013-06-03 56 views
2

我們如何獲取用戶在WIndows 7和Windows 8中使用的個人資料圖片? (我主要希望這個Windows 8)。到目前爲止,我只看到了一堆論壇帖子,說它不能完成,但我看到應用程序向左和向右,可以做到這一點。在Windows Vista上獲取默認用戶帳戶配置文件圖片> 8

+1

http://code.msdn.microsoft.com/windowsapps/Account-picture-name-sample-912baff1 – jbabey

+0

@jbabey - 當然,這應該是一個答案,而不是評論。 –

+0

已完成足夠的研究,但沒有發現任何Windows 7及更低版本。我不再擁有Windows 7(或Vista),所以我需要知道我找到的代碼可以工作,而不是依賴人們寫的答案,他們聲稱這不是獲取個人資料圖片的保證方式。感謝您的鏈接;它沒有顯示任何結果。 –

回答

2

根據Serge - appTranslator

blog post顯示瞭如何設置用戶瓦片(圖片)。在接近結尾的評論中(Michael Anthony,4月10日,22:45),評論者描述瞭如何獲得照片。我已將這些信息收集到C#代碼片段中。請記住,這是基於未記錄的Windows Shell功能。

using System; 
    using System.Text; 
    using System.Drawing; 

    [DllImport("shell32.dll", EntryPoint = "#261", 
       CharSet = CharSet.Unicode, PreserveSig = false)] 
    public static extern void GetUserTilePath(
     string username, 
     UInt32 whatever, // 0x80000000 
     StringBuilder picpath, int maxLength); 

    public static string GetUserTilePath(string username) 
    { // username: use null for current user 
     var sb = new StringBuilder(1000); 
     GetUserTilePath(username, 0x80000000, sb, sb.Capacity); 
     return sb.ToString(); 
    } 

    public static Image GetUserTile(string username) 
    { 
     return Image.FromFile(GetUserTilePath(username)); 
    } 

請注意,該外殼函數創建文件\用戶\ USER < > \ AppData的... \ USER <.BMP>並返回其文件名。

另外,我在Win7上測試過它。我不知道它與以前的Windows版本的兼容性。

Credits to Joco and Michael Anthony

+0

非常感謝你@One Man Crew!非常感謝:-) –

+0

@One Man Crew這非常有幫助! – user2068793

相關問題