Jump to content

Recommended Posts

Posted
ok that's cool. but could you stop making the rest of us look bad?

 

To be honest, most of the work was done by @DJ-1701 when he created our 2 GIMP templates and put the instructions together, so all we do is tweak it each time a new school joins and recreate the files :D

 

Sometimes wish we could keep the same logon wallpaper instead of switching every fortnight, but does have the benefit of being visual indication that a computer hasn't been rebooted recently

  • Thanks 1
Posted (edited)
This is a quick shot from here

 

[ATTACH=CONFIG]71794[/ATTACH]

 

Mine somewhat similar to this. Background colour matches the primary school colours. Bginfo bottom right. Logo top right on Lock Screen and center or top right on the desktop. Support contact details bottom centre of screen

 

Nice touch on the don’t move from this location. Do they abide by this note? [emoji23]

 

I’m going to put a note on my desktop “if I find who stealing the internals of any pc I will chop off your hands”

 

Some of my schools it’s not so much the moving the equipment I have a problem with but stealing the internals to sell I presume. Got two school that we originally zip tied then they responded by cutting the zip tie off baring in mind the kids should have access to scissor or sharp blades. We upgrade this to mini padlock which in hindsight really we should have cheaped out on as they just yanked the padlock off with leverage assume again a screwdriver maybe and again what are kids doing with implements in class like that. We now got sturdier padlocks which seem to be holding better.

 

My not so Ferrell schools walk around and move their computer like they were laptops switching offices every two minutes. No word of a lie we are switching them to laptops and docks strongly on this reason alone

Edited by dapaulio
Posted

A couple of people have asked, so here is the script that I have run on startup from a network share.

 

The background images are unique by campus and are called based on IP address. We also have separate "Admin" and "Curriculum" images, which are slightly different.

 

The script outputs to a log file in the image output directory so you can see what's happening. FWIW the timer was there to ensure it doesn't take ages to run at startup. I'm seeing between 300 and 600ms execution times across devices.

 

$Stopwatch = [system.Diagnostics.Stopwatch]::StartNew()

#================#
# Task Variables #
#================#

$wallpaperImagesSource = "\\domain.name\Path\To\Base\Images"
$wallpaperImageOutput = "C:\Windows\Web\Wallpaper"

Function IsIpAddressInRange {
   param(
       [string] $IPAddress,
       [string] $FromAddress,
       [string] $ToAddress
   )

   $IP = [system.net.ipaddress]::Parse($IPAddress).GetAddressBytes()
   [array]::Reverse($IP)
   $IP = [system.BitConverter]::ToUInt32($IP, 0)

   $From = [system.net.ipaddress]::Parse($FromAddress).GetAddressBytes()
   [array]::Reverse($From)
   $From = [system.BitConverter]::ToUInt32($From, 0)

   $To = [system.net.ipaddress]::Parse($ToAddress).GetAddressBytes()
   [array]::Reverse($To)
   $To = [system.BitConverter]::ToUInt32($To, 0)

   $From -le $IP -and $IP -le $To
}

Function New-ImageInfo {
   param(  
       [Parameter(Mandatory=$True, Position=1)]
       [object] $data,
       [Parameter(Mandatory=$True)]
       [string] $in="",
       [string] $font="Courier New",
       [float] $size=12.0,
       #[float] $lineHeight = 1.4,
       [float] $textPaddingLeft = 0,
       [float] $textPaddingTop = 0,
       [float] $textItemSpace = 0
   )

   $Use = "Logon"
   If (-not (Test-Path "$in\$Usage\$Campus$Use\$Width`x$Height.jpg")) {
       $in = "$in\$Usage\$Campus$Use\1920x1080.jpg"
   }
   Else {
       $in = "$in\$Usage\$Campus$Use\$Width`x$Height.jpg"
   }

   Echo "$In" >> "$wallpaperImageOutput\wallpaper.log"

   [system.reflection.assembly]::loadWithPartialName('system') | out-null
   [system.reflection.assembly]::loadWithPartialName('system.drawing') | out-null
   [system.reflection.assembly]::loadWithPartialName('system.drawing.imaging') | out-null
   [system.reflection.assembly]::loadWithPartialName('system.windows.forms') | out-null

   $foreBrush  = [system.Drawing.Brushes]::White
   $backBrush  = new-object System.Drawing.SolidBrush([system.Drawing.Color]::FromArgb(0, 0, 0, 0))

   # Create font
   $nFont = new-object system.drawing.font($font, $size, [system.Drawing.GraphicsUnit]::Pixel)
   
   # Get primary display resolution
   $SRs = Get-WmiObject -class "Win32_VideoController"
   $I = 0
   If (($SRs | Measure-Object).Count -gt 1) {
       $Cont = $False
       While ($Cont -eq $False) {
           Foreach ($SR in $SRs) {
               If ($SR.CurrentHorizontalResolution -gt 0 -and $SR.CurrentVerticalResolution -gt 0) {
                   $Cont = $True
                   $X = $I
               }
               $I++
           }
       }
       $SR = $SRs[$X]
   }
   ElseIf (($SRs | Measure-Object).Count -eq 1) {
       $SR = $SRs
   }

   [int]$SRWidth = $SR.CurrentHorizontalResolution
   [int]$SRHeight = $SR.CurrentVerticalResolution

   echo "`$SR = $SRWidth x $SRHeight" >> "$wallpaperImageOutput\wallpaper.log"

   # Create Bitmap
   $background = new-object system.drawing.bitmap($SRWidth, $SRHeight)
   $bmp = new-object system.drawing.bitmap -ArgumentList $in

   Echo "Background: $($Background.Size)" >> "$wallpaperImageOutput\wallpaper.log"
   Echo "BMP: $($bmp.Size)" >> "$wallpaperImageOutput\wallpaper.log"

   # Create Graphics
   $image = [system.Drawing.Graphics]::FromImage($background)

   # Paint image's background
   $rect = new-object system.drawing.rectanglef(0, 0, $SRwidth, $SRheight)
   $image.FillRectangle($backBrush, $rect)

   # add in image
   $topLeft = new-object System.Drawing.RectangleF(0, 0, $SRWidth, $SRHeight)
   $image.DrawImage($bmp, $topLeft)

   # Draw string
   $strFrmt = new-object system.drawing.stringformat
   $strFrmt.Alignment = [system.drawing.StringAlignment]::Near
   $strFrmt.LineAlignment = [system.drawing.StringAlignment]::Near

   $taskbar = [system.Windows.Forms.Screen]::PrimaryScreen
   $taskbarOffset = $taskbar.Bounds.Height - $taskbar.WorkingArea.Height

   # first get max key & val widths
   $maxKeyWidth = 0
   $maxValWidth = 0
   $textBgHeight = 0 + $taskbarOffset
   $textBgWidth = 0

   $reversed = @()

   Foreach ($h in $data.GetEnumerator()) {
       $valString = "$($h.Value)"
       $valFont = New-Object System.Drawing.Font($font, $size, [system.Drawing.FontStyle]::Regular)
       $valSize = [system.windows.forms.textrenderer]::MeasureText($valString, $valFont)
       $maxValWidth = ([math]::Max($maxValWidth, $valSize.Width))
       $maxValWidth = $maxValWidth + 20
       
       $keyString = "$($h.Name): "
       $keyFont = New-Object System.Drawing.Font($font, $size, [system.Drawing.FontStyle]::Bold)
       $keySize = [system.windows.forms.textrenderer]::MeasureText($keyString, $keyFont)
       $maxKeyWidth = [math]::Max($maxKeyWidth, $keySize.Width)

       $maxItemHeight = [math]::Max($valSize.Height, $keySize.Height)
       $textBgHeight += ($maxItemHeight + $textItemSpace)

       $Continue = $False
       
       Switch ($keyString) {
           "Host: " {$Continue = $True; Break}
           "Subnet: " {$Continue = $True; Break}
           "Phy: "  {$Continue = $True; Break}
           "OS: " {$Continue = $True; Break}
           "Version: " {$Continue = $True; Break}
           "Boot: " {$Continue = $True; Break}
       }
       
       If ($Continue) {
           $Line = New-Object PSObject
           $Line | Add-Member -Type NoteProperty -Name 'Name' -Value $KeyString
           $Line | Add-Member -Type NoteProperty -Name 'Value' -Value $ValString
           $Reversed += @($Line)
       }
   }

   $textBgWidth = $maxKeyWidth + $maxValWidth
   $textBgX = $SRWidth - ($textBgWidth + $textPaddingLeft)
   $textBgY = $TextPaddingTop

   $textBgRect = New-Object System.Drawing.RectangleF($textBgX, $textBgY, $textBgWidth, $textBgHeight)
   $image.FillRectangle($backBrush, $textBgRect)

   echo "TBRect: $textBgRect" >> "$wallpaperImageOutput\wallpaper.log"

   $i = 0
   $cumulativeHeight = $TextBgY + 10
   $cumulativeHeight = $cumulativeHeight + 190

   foreach ($h in $reversed) {
       $valString = "$($h.Value)"
       $valFont = New-Object System.Drawing.Font($font, $size, [system.Drawing.FontStyle]::Regular)
       $valSize = [system.windows.forms.textrenderer]::MeasureText($valString, $valFont)

       $keyString = "$($h.Name)"
       $keyFont = New-Object System.Drawing.Font($font, $size, [system.Drawing.FontStyle]::Bold)
       $keySize = [system.windows.forms.textrenderer]::MeasureText($keyString, $keyFont)

       echo "Key: $KeyString" >> "$wallpaperImageOutput\wallpaper.log"
       echo "Val: $ValString" >> "$wallpaperImageOutput\wallpaper.log"

       $maxItemHeight = [math]::Max($valSize.Height, $keySize.Height) + $textItemSpace

       $valX = $SRWidth - $maxValWidth
       $valY = $CumulativeHeight + $textItemSpace

       $keyX = $valX - $maxKeyWidth
       $keyY = $valY

       $valRect = New-Object System.Drawing.RectangleF($valX, $valY, $maxValWidth, $valSize.Height)
       $keyRect = New-Object System.Drawing.RectangleF($keyX, $keyY, $maxKeyWidth, $keySize.Height)

       $cumulativeHeight = $valRect.Bottom

       $image.DrawString($keyString, $keyFont, $foreBrush, $keyRect, $strFrmt)
       $image.DrawString($valString, $valFont, $foreBrush, $valRect, $strFrmt)

       $i++
   }
   
   
   echo "$wallpaperImageOutput\$OutFileName" >> "$wallpaperImageOutput\wallpaper.log"

   # Close Graphics
   $image.Dispose();

   # Save and close Bitmap
   $background.Save("$wallpaperImageOutput\$OutFileName", [system.drawing.imaging.imageformat]::Jpeg);
   $background.Dispose();
   $bmp.Dispose();

   # Output file
   Get-Item -Path "$wallpaperImageOutput\$OutFileName"
}

###################
#=================#
# Start Execution #
#=================#
###################

# Font Family name
$font="Input"
# Font size in pixels
$size=20.0
$textPaddingLeft = 5
$textPaddingTop = 5
$textItemSpace = 3

[void] [system.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [system.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

$vc = Get-WmiObject -class "Win32_VideoController" | Select-Object -First 1
$Width = $VC.CurrentHorizontalResolution
$Height = $VC.CurrentVerticalResolution

$NetAddress = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.PrefixOrigin -eq "DHCP"} | Select-Object -First 1)
$IP = $NetAddress.IPAddress
$IntIndex = $NetAddress.ifIndex
$MACAddress = ((Get-NetAdapter -InterfaceIndex $IntIndex).MacAddress -replace '-','.').Substring(9)
$Subnets = $IP.Split('.')

# Get local info to write out to wallpaper
$os = Get-CimInstance Win32_OperatingSystem

$o = ([ordered]@{
   Host = "$($os.CSName)"
   Subnet = "$($Subnets[1])`.$($Subnets[2])"
   Phy = "$MacAddress"
   OS = "$($os.Version)"
   Version = $(Get-Date $os.InstallDate -Format "yyyyMMdd_HHmmss")
   Boot = $(Get-Date $os.LastBootUpTime -Format "yyyy-MM-dd HH:mm:ss")
})

$Group = "C_LogonWallpaper-Seasonal"

Function Get-GroupDN {
   param(
       $Group
   )

   $filter = "(&(objectCategory=Group)(SamAccountname=$Group))"
   $objDomain = New-Object System.DirectoryServices.DirectoryEntry
   $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
   $objSearcher.SearchRoot = $objDomain
   $objSearcher.PageSize = 1000
   $objSearcher.Filter = $filter
   $objSearcher.SearchScope = "Subtree"
   ($objSearcher.FindOne()).Path -replace "LDAP://",""
}

$GroupDN = Get-GroupDN -Group $Group

Function Get-AdComputerData {
   param(
       $Computer = (ls env:\computername).value
   )

   $filter = "(&(objectCategory=Computer)(SamAccountname=$Computer`$))"
   $objDomain = New-Object System.DirectoryServices.DirectoryEntry
   $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
   $objSearcher.SearchRoot = $objDomain
   $objSearcher.PageSize = 1000
   $objSearcher.Filter = $filter
   $objSearcher.SearchScope = "Subtree"
   $objSearcher.FindOne()
}

$Computer = Get-AdComputerData

$Filter = "(&(objectCategory=computer)(objectClass=computer)(cn=$env:COMPUTERNAME))"
$DN = ([adsisearcher]$filter).FindOne().Properties.distinguishedname

If ($Computer.Properties.memberof -contains $GroupDN) {
   $Usage = "Seasonal"
}
ElseIf ($DN -like "*Laptop*") {
   $Usage = "Laptop"
}
ElseIf ((IsIpAddressInRange -IPAddress $IP -FromAddress 10.11.0.0 -ToAddress 10.11.3.255) -or (IsIpAddressInRange -IPAddress $IP -FromAddress 10.21.0.0 -ToAddress 10.21.3.255)) {
   $Usage = "Administration"
}
Else {
   $Usage = "Curriculum"
}


If (IsIpAddressInRange -IPAddress $IP -FromAddress 10.20.0.0 -ToAddress 10.29.255.255) {
   $Campus = "Campus1"
}
Else {
   $Campus = "Campus2"
}

If (!(Test-Path $wallpaperImageOutput)) {
   md $wallpaperImageOutput
}

$OutFileName = "$Campus`Logon.jpg"
If (Test-Path "$wallpaperImageOutput\$OutFileName" -ErrorAction SilentlyContinue) {
   Remove-Item "$wallpaperImageOutput\$OutFileName" -Force -Confirm:$False
}

echo $o > "$wallpaperImageOutput\wallpaper.log"
Echo "Boot: $($Os.LastBootUpTime)" >> "$wallpaperImageOutput\wallpaper.log"
Echo "Campus: $Campus" >> "$wallpaperImageOutput\wallpaper.log"
Echo "Usage: $Usage" >> "$wallpaperImageOutput\wallpaper.log"

$WallPaper = New-ImageInfo -data $o -in "$wallpaperImagesSource" -font $font -size $size -textPaddingLeft $textPaddingLeft -textPaddingTop $textPaddingTop -textItemSpace $textItemSpace

Copy-Item -Path "$wallpaperImageOutput\$OutFileName" -Destination "$WallpaperImageOutput\LogonWallpaper.jpg" -Force

Echo "TimeTaken: $($Stopwatch.Elapsed.Milliseconds)" >> "$wallpaperImageOutput\wallpaper.log"

  • Thanks 3

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...