Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Script to set the wallpaper on a machine similar to BGInfo but without VBScripts
- $line1 = "ПК: $env:COMPUTERNAME"
- $line2 = "Пользователь: $Env:USERNAME"
- $typeFace = 'Vernada'
- $bgColor = (255, 70, 70, 70) #aRGB
- $txtColor = (255, 255, 255, 255) #aRGB
- $txtShadow = (200, 0, 0, 0) #aRGB
- $src = (Get-ItemProperty -Path 'HKCU:\Control Panel\Desktop' -Name Wallpaper).Wallpaper
- $dst = "$PSScriptRoot\dst.jpg"
- # Based on https://github.com/cwhits/PSBGinfo, written by Chris Helming, Oscar Santiano and Chase Caynoski
- Function AddTextToImage {
- [CmdletBinding()]
- PARAM (
- [Parameter(Mandatory=$false)][String]$sourcePath,
- [Parameter(Mandatory=$true)][String]$destPath,
- [Parameter(Mandatory=$true)][String]$line1,
- [Parameter(Mandatory=$true)][String]$line2,
- [Parameter(Mandatory=$true)][String]$typeFace,
- [Parameter(Mandatory=$true)][Array]$bgColor,
- [Parameter(Mandatory=$true)][Array]$txtColor,
- [Parameter(Mandatory=$true)][Array]$txtShadow
- )
- [Reflection.Assembly]::LoadWithPartialName('System.Drawing') | Out-Null
- $screen = Get-WmiObject -Class win32_videocontroller | where CurrentHorizontalResolution -NE $null
- $screenWidth = $screen[0].CurrentHorizontalResolution
- $screenHeight = $screen[0].CurrentVerticalResolution
- # Move the text in 20 pixels from the right side of the screen
- $textPos = $screenwidth - 20
- $shadowPos = $textPos + 2
- $bmpFile = New-Object System.Drawing.Bitmap([int]($screenWidth)),([int]($screenHeight))
- $Image = [System.Drawing.Graphics]::FromImage($bmpFile)
- $Image.clear([System.Drawing.Color]::FromArgb($bgcolor[0], $bgcolor[1], $bgcolor[2], $bgcolor[3]))
- $Image.SmoothingMode = 'AntiAlias'
- $stringFormat = New-Object System.Drawing.StringFormat
- $stringFormat.Alignment = [System.Drawing.StringAlignment]::Far
- if($sourcePath){
- $srcImg = [System.Drawing.Image]::FromFile($sourcePath)
- $Rectangle = New-Object Drawing.Rectangle ($screenWidth/2 - $srcImg.width/2), ($screenHeight/2 - $srcImg.height/2), $srcImg.Width, $srcImg.Height
- $Image.DrawImage($srcImg, $Rectangle, 0, 0, $srcImg.Width, $srcImg.Height, ([Drawing.GraphicsUnit]::Pixel))
- $srcImg.Dispose()
- }
- # Drop shadow for text
- $Font = New-Object System.Drawing.Font($typeFace, 15)
- $Brush = New-Object Drawing.SolidBrush ([System.Drawing.Color]::FromArgb($txtShadow[0], $txtShadow[1], $txtShadow[2], $txtShadow[3]))
- $Image.DrawString($line1, $Font, $Brush, $shadowPos, 12, $stringFormat)
- $Font = New-object System.Drawing.Font($typeFace, 15)
- $Brush = New-Object Drawing.SolidBrush ([System.Drawing.Color]::FromArgb($txtShadow[0], $txtShadow[1], $txtShadow[2], $txtShadow[3]))
- $Image.DrawString($line2, $Font, $Brush, $shadowPos, 42, $stringFormat)
- # Draw text strings
- $Font = new-object System.Drawing.Font($typeFace, 15)
- $Brush = New-Object Drawing.SolidBrush ([System.Drawing.Color]::FromArgb($txtColor[0], $txtColor[1], $txtColor[2], $txtColor[3]))
- $Image.DrawString($line1, $Font, $Brush, $textpos, 10, $stringFormat)
- $Font = New-object System.Drawing.Font($typeFace, 15)
- $Brush = New-Object Drawing.SolidBrush ([System.Drawing.Color]::FromArgb($txtColor[0], $txtColor[1], $txtColor[2], $txtColor[3]))
- $Image.DrawString($line2, $Font, $Brush, $textpos, 40, $stringFormat)
- # Save image
- $bmpFile.save($destPath, [System.Drawing.Imaging.ImageFormat]::Jpeg)
- $bmpFile.Dispose()
- }
- AddTextToImage -sourcePath $src -destPath $dst -line1 $line1 -line2 $line2 -typeFace $typeFace -bgColor $bgColor -txtColor $txtColor -txtShadow $txtShadow
- # Set wallpaper
- Set-ItemProperty -path 'HKCU:\Control Panel\Desktop' -name wallpaper -value $dst
- Add-Type -TypeDefinition @'
- using System;
- using System.Runtime.InteropServices;
- public class Params
- {
- [DllImport("User32.dll",CharSet=CharSet.Unicode)]
- public static extern int SystemParametersInfo (Int32 uAction, Int32 uParam, String lpvParam, Int32 fuWinIni);
- }
- '@
- $SPI_SETDESKWALLPAPER = 0x0014
- $UpdateIniFile = 0x01
- $SendChangeEvent = 0x02
- $fWinIni = $UpdateIniFile -bor $SendChangeEvent
- [Params]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $dst, $fWinIni) | Out-Null
- # Add new task if necessary
- <#
- if(!(Get-ScheduledTask -TaskName 'BGInfo' -ErrorAction SilentlyContinue)) {
- $TaskAction = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument "-WindowStyle Hidden -NonInteractive -File "$($MyInvocation.InvocationName)"
- $TaskTrigger = New-ScheduledTaskTrigger ...
- Register-ScheduledTask -Action $TaskAction -Trigger $TaskTrigger -TaskName 'BGInfo' -Description 'Set background info with PC and User names'
- }
- #>
Advertisement
Add Comment
Please, Sign In to add comment