tech-man Posted May 20, 2019 Posted May 20, 2019 Hello We've taken a few scripts and tried to make them fit our needs, basically a BGInfo alternative. However the script seems to be intermittent, it always seems to create the end result image but the script seems to fail to set the registry keys / apply the created wallpaper to the user. I would be grateful if someone with vastly more Powershell knowledge than me could have a look to see if we are doing this in the best ways etc. ThanksSetWallpaper.ps1
DJ-1701 Posted May 21, 2019 Posted May 21, 2019 So basically you are trying to get the wallpaper with the text overlay of Full Name, E-mail and Username as the user's login wallpaper with no box around it? Have you set Group Policy to point to the file that is being generated for the wallpaper? Go to User Configuration -> Policies -> Administrative Templates -> Desktop -> Desktop -> Desktop Wallpaper, and enable the policy, specifying the location as %temp%\Default.jpg and setting the wallpaper style to Stretch.
tech-man Posted May 21, 2019 Author Posted May 21, 2019 We had not got that set as the script seemed to be doing it, all be it, intermittently. I'll set this and see how it runs. It seems the script is somehow crashing before it gets to the registry settings / the .net wallpaper refresh section. It seems to consistently create the jpg though.
DJ-1701 Posted May 21, 2019 Posted May 21, 2019 (edited) Well, it does seem a couple of things are more complicated then they need to be. Out of interest, do your AD users have an e-mail address in their AD account field like the image attached? Edited May 21, 2019 by DJ-1701
DJ-1701 Posted May 22, 2019 Posted May 22, 2019 Could try giving this a go. # Reads first command line argument into Group variable. [cmdletBinding()] Param ( $group ) # Checks that the group parameter is not empty - will not run the rest of the script if not. If ([string]::IsNullOrEmpty($group)) { Write-Host "Please provide a value for the parameter: Group" Exit } $DisplayName = ([ADSISEARCHER]"SAMAccountName=$($env:Username)").Findone().Properties.displayname $UserEmail = ([ADSISEARCHER]"SAMAccountName=$($env:Username)").Findone().Properties.mail $ComputerName = $env:computername # Text for the wallpaper. $TextLabel = "$DisplayName`r`n$UserEmail`r`n$ComputerName" $TextSizePoint = 22 # Text colour. $TextRed = 255 $TextGreen = 255 $TextBlue = 255 # Wallpaper source folder. $LocalSource = "C:\Wallpapers\Desktop" # Completed wallpaper destination location. $DestinationFile = "$env:temp\default.jpg" # Clear theme cache files. Remove-Item -Path "$($env:APPDATA)\Microsoft\Windows\Themes\*" -Recurse -Force -ErrorAction SilentlyContinue # Ensure image is set to Stretch to screen resolution and not tile. Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop' -Name WallpaperStyle -Value "2" -Force Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop' -Name TileWallpaper -Value "0" -Force If (!(Test-Path($LocalSource))) { Write-Host "$LocalSource does not exist." Exit } # Find current screen resolution. [void] [system.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $RegistryPath = "HKLM:\Software\MachineData" $Horizontal = [int]([system.Windows.Forms.Screen]::PrimaryScreen[0]).Bounds.Width $Vertical = [int]([system.Windows.Forms.Screen]::PrimaryScreen[0]).Bounds.Height $Ratio = "$Horizontal`x$Vertical" $SourceFile = "$LocalSource\$Group$Ratio.jpg" If (!(Test-Path($SourceFile))) { Write-Host "$SourceFile does not exist." Exit } # Use .Net Framework to create a class to update and refresh the Wallpaper. Add-Type @” using System; using System.Runtime.InteropServices; using Microsoft.Win32; namespace Wallpaper { public class UpdateImage { [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni); public static void Refresh(string path) { SystemParametersInfo( 20, 0, path, 0x01 | 0x02 ); } } } “@ # Enable the creation of images. Add-Type -AssemblyName System.Drawing # Select a font, size and style. $TextSizePixels=$TextSizePoint/0.75 $Font = New-Object System.Drawing.Font("Arial",$TextSizePixels,[Drawing.FontStyle]'Bold',"Pixel") # Get source image from source file. $SourceImage = [system.Drawing.Image]::FromFile($SourceFile) # Create a new bitmap at the primary monitor resolution to construct an image. $Bitmap = New-Object System.Drawing.Bitmap($Horizontal,$Vertical) # Create image for editing. $Image = [system.Drawing.Graphics]::FromImage($Bitmap) # Ensure the image is clear. $Image.Clear([system.Drawing.Color]::FromArgb(255,255,255,255)) # Set the ARGB values required for the text. $TextARGB = [system.Drawing.Color]::FromArgb(255,$TextRed,$TextGreen,$TextBlue) # Set area for text placement. $Rectangle = [system.Drawing.RectangleF]::FromLTRB(0, 60, $Horizontal-30, $Vertical) # Set alignment format for the font. $FormatFont = [system.Drawing.StringFormat]::GenericDefault $FormatFont.Alignment = [system.Drawing.StringAlignment]::Far $FormatFont.LineAlignment = [system.Drawing.StringAlignment]::Near # Set up the brush colours for drawing text box and text string. $TextBrushColour = New-Object Drawing.SolidBrush $TextARGB # Draw image. $Image.DrawImage($SourceImage,0,0, $Horizontal, $Vertical) # Draw text. $Image.DrawString($TextLabel,$Font,$TextBrushColour,$Rectangle,$FormatFont) # Save edited bitmap to file. $Bitmap.Save($DestinationFile,[system.Drawing.Imaging.ImageFormat]::Jpeg) # Clean up and remove objects. $SourceImage.Dispose() $Bitmap.Dispose() $Image.Dispose() $SourceDestinationFile # Open saved file. #Invoke-Item $DestinationFile # Update wallpaper. [Wallpaper.UpdateImage]::Refresh($DestinationFile)
Boredguy Posted May 24, 2019 Posted May 24, 2019 BGinfo only generates 1024x768 images if you want it for a logon screen based on our experience.
tech-man Posted May 24, 2019 Author Posted May 24, 2019 and it's very old and difficult to work with.
DJ-1701 Posted May 24, 2019 Posted May 24, 2019 and it's very old and difficult to work with. How goes your endeavour?
tech-man Posted May 24, 2019 Author Posted May 24, 2019 I havent had chance to do much yet, will try the new script next week... doing battle with printer woes at the moment! After reading the script properly, I moved the registry / delete to the top, which has improved the situation for now. 1
supportman Posted May 24, 2019 Posted May 24, 2019 and it's very old and difficult to work with. We use a local group policy to change the logon image but BGinfo for the users desktop. I just set it up BGinfo on windows 10 for our new images, seemed to work fine for us just as it did with Windows XP and 7. But I guess whatever works best in your environment. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now