如何更改loginWindows Vista,7,2008,2008R2计算机期间显示的每个个人用户的“用户头像”?
对于您提到的操作系统, shell32.dll中有一个未发布的函数就是票据。 使用它将不被Microsoft支持,但我在几个环境中没有任何问题。 入口点是#262 。
你可以导入它在PowerShell中使用,如下所示:
# Set user tile $code = @" [DllImport("shell32.dll", EntryPoint = "#262", CharSet = CharSet.Unicode, PreserveSig = false)] public static extern void SetUserTile(string username, int whatever, string picpath); public static void ChangeUserPicture(string username, string picpath) { SetUserTile(username, 0, picpath); } "@ Add-Type -MemberDefinition $code -NameSpace Shell32 -Name ChangeUserTile
这意味着你可以在同一个脚本中调用它,就像:
[Shell32.ChangeUserTile]::ChangeUserPicture(<username>,<pathtoimage>)
我已经使用以下作为一个login脚本,也从AD抓取图像:
# Set User Photo Script # Reads user's photo from AD and sets as users local display picture # Find User $search = [System.DirectoryServices.DirectorySearcher][System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().GetDirectoryEntry() $search.Filter = "(sAMAccountName=$env:username)" $user = $search.FindOne().GetDirectoryEntry() # Save image to %appdata% $user.thumbnailphoto | Set-Content $env:appdata\usertilecache.jpg -Encoding byte # Set user tile $code = @" [DllImport("shell32.dll", EntryPoint = "#262", CharSet = CharSet.Unicode, PreserveSig = false)] public static extern void SetUserTile(string username, int whatever, string picpath); public static void ChangeUserPicture(string username, string picpath) { SetUserTile(username, 0, picpath); } "@ Add-Type -MemberDefinition $code -NameSpace Shell32 -Name ChangeUserTile [Shell32.ChangeUserTile]::ChangeUserPicture(($env:userdomain + "\" + $env:username),($env:appdata + "\usertilecache.jpg")) # Tidy up Remove-Item ($env:appdata + "\usertilecache.jpg")
我应该指出,我已经转向使用编译后的.NET应用程序,但是它的性能要好得多 – 在login的时候至关重要。
它还使我可以select在启动时调用,并为尚未login到计算机的用户设置图像,这对于在分配的PC上看到他们的脸的新用户是一个很好的补充,而不是默认橙花!
也许值得指出的是,对于Windows 8以后,我们必须彻底重新devise – 现在MS有一个全新的机制。