automators & workspacers unite!
RSS icon Email icon Home icon
  • Creating a custom Windows Logon screen with version numbers

    Posted on June 4th, 2012 Marcel Venema No comments

    Most companies work with custom logon screens with build or version numbers for their workstation infrastructure. Instead of using paint or any other graphic application I created a RES Automation Manager RunBook to automatically set a logon screen and place the version number in the left-down corner.

    The building block contains two modules: one module for drawing the version number on the bitmap and another module for setting the logon screen. If you don’t have Automation Manager you can use the code below, but I can strongly suggest to try the RES Automation Manager software, it is awesome!

    Drawing the version number

    For the version number I use a small PowerShell script, so PowerShell is required. If you don’t want to install PowerShell on your workstations, change the RunBook  and run the script on another computer and copy the bitmap file afterwards.

    [sourcecode language="powershell"]
    # Watermark logonscreen with build version
    # 20120411 Marcel Venema, ConoScenza v1.0

    #Load System.Drawing assembly
    [Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null

    $filename = "%TMP%\LOGONSCREEN.JPG"
    $filenameNew = "%TMP%\CSAFLOGONSCREEN.JPG"
    $text = "$[CSAF_VERSION]" # RES-AM parameter
    $fontname = "Impact"
    $fontsize = 16

    #Select a font and instantiate
    #fontstyle: regular, bold, italic, underline
    $font = new-object System.Drawing.Font($fontname,$fontsize,[Drawing.FontStyle]‘Regular’ )

    #Get image
    $img = [System.Drawing.Image]::FromFile($filename)

    #Create a bitmap
    $bmp = new-object System.Drawing.Bitmap([int]($img.width)),([int]($img.height))

    #Intialize Graphics
    $gImg = [System.Drawing.Graphics]::FromImage($bmp)

    #Set the color required for the watermark.
    $color = [System.Drawing.Color]::FromArgb(255, 255, 255)

    #Set up the brush for drawing image/watermark string
    $myBrush = new-object Drawing.SolidBrush $color
    $rect = New-Object Drawing.Rectangle 0,0,$img.Width,$img.Height
    $gUnit = [Drawing.GraphicsUnit]::Pixel

    #Draw the water mark
    $gImg.DrawImage($img,$rect,0,0,$img.Width,$img.Height,$gUnit)
    $gImg.DrawString($text,$font,$myBrush,12,$img.Height – 40 – $fontsize)
    $newImagePath = $filenameNew
    #Save image
    $bmp.save($newImagePath,[System.Drawing.Imaging.ImageFormat]::Jpeg)
    $bmp.Dispose()
    $img.Dispose()
    [/sourcecode]

    Setting the logon screen

    Setting the logon screen is a small tweak within the Microsoft Windows 7 operating system. See http://blogs.technet.com/b/deploymentguys/archive/2011/08/22/windows-7-background-customization.aspx for more information. You need to copy a backgroundDefault.jpg file to the %WINDIR%\System32\oobe\info\Backgrounds folder and add a registry key.

    Download the RES Automation Manager building block here : [download id="12"]