PowerShell 自定义Windows登陆窗口背景


我们一般喜欢自定义个性化的Windows桌面的背景图片,偶尔才会更改登陆界面背景。windows 登陆界面的背景图片可以通过改注册表和替换图片文件完成。下面的PowerShell脚本可以帮助重置和更改登陆界面背景(需要管理员权限)。

既然中秋节15的月亮16圆,那么改成月亮留作纪念:
change-login-screen
下面贴出脚本文件:

<#
 # This function can rest or change logon UI background iamge
 # Sample 1: Change-LogonUIBackground -Reset
 # Sample 2:Change-LogonUIBackground -BackgroundImagePath C:\Users\mosser\Desktop\8-15-moon.jpg
#>
function Change-LogonUIBackground
{
   param([switch]$Reset,[Io.Fileinfo]$BackgroundImagePath)
   $LogonUIBackgroundPath = "$env:windir\System32\oobe\info\backgrounds"
   $LogonUIBackgroundPathRegPath = "hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background"
   if($Reset)
   {
    Set-ItemProperty -Path $LogonUIBackgroundPathRegPath  -Name OEMBackground -Value 0
   }
   else
   { #validate file exists
     if( -not ( $BackgroundImagePath.Exists ))
     {
        Write-Warning "File: $BackgroundImagePath not exists."
        return
     }
     #validate file is jpg image
     elseif( $BackgroundImagePath.Extension -ne ".jpg")
     {
        Write-Warning "File: $BackgroundImagePath not exists."
        return
     }
     #The length of background file must less than 254 KB
     elseif( $BackgroundImagePath.Length / 1kb -ge 254)
     {
        Write-Warning "File: $BackgroundImagePath must less than 254KB."
        return
     }
     else 
     {
        if( -not ( test-path $LogonUIBackgroundPath ) )
        {
            mkdir $LogonUIBackgroundPath | Out-Null
        }
        Copy-Item $BackgroundImagePath $LogonUIBackgroundPath
        Rename-Item "$LogonUIBackgroundPath\$($BackgroundImagePath.Name)" "backgroundDefault.jpg" -Force
        Set-ItemProperty -Path $LogonUIBackgroundPathRegPath  -Name OEMBackground -Value 1
        Write-Host "done! you preview it by Ctrl-L"
    }
   }
}

参考链接:Change windows Login Screen using Powershell

本文链接: https://www.pstips.net/change-windows-login-screen-using-powershell.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

关于 Mooser Lee

我是一个Powershell的爱好者,创建了PowerShell中文博客,热衷于Powershell技术的搜集和分享。本站部分内容来源于互联网,不足之处敬请谅解,并欢迎您批评指正。

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注