windows – 在域上登录用户图片

如何在整个域中为 Windows 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,picpath);
}
"@


Add-Type -MemberDeFinition $code -NameSpace Shell32 -Name ChangeUserTile

这意味着你可以在同一个脚本中调用它,就像:

[Shell32.ChangeUserTile]::ChangeUserPicture(<username>,<pathtoimage>)

我已经使用以下作为登录脚本,也可以从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",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应用程序,它做同样的事情,但具有更好的性能 – 在登录时非常关键.

它还让我可以选择在启动时调用并为尚未登录到机器的用户设置图像,这对于新用户来说是一个很好的补充,他们必须在指定的PC上看到他们的脸,而不是认橙花!

值得指出的是,对于Windows 8起,我们必须完全重新设计 – 现在有一种来自MS的全新机制.

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...