A Modern bginfo solution – just a simple powershell script

Hey, I’ve been looking around for a bginfo solution. I tried the original one from sysinternal tools
https://docs.microsoft.com/en-us/sysinternals/downloads/bginfo
but it always changes the background to “tile”, I don’t know why..
There are hotfixes out there but I don’t want a hotfix. I want a “real solution”

So I found this page.
https://p0w3rsh3ll.wordpress.com/2014/08/29/poc-tatoo-the-background-of-your-virtual-machines/

So started with that, then I’ve worked further with it and now
it’s finally working as I want and the result is this:

So first, Download this script.
Link bginfo

Then just run the script either as a scheduled task or login script in GPO. No bginfo.exe is needed or anything extra.

If you want to change the information on the background, open the bginfo.ps1
then go to the
“#Writing info to the background” part, and then change what information that you want to use 🙂

And if you want to change the Background to be stretch instead of fit, you change this part, change the -style to stretch.

Another thing that is great is, if you want to force a background also, you change this part active, just take away the #

So that’s it

Good luck while using it
Pontus

Thanks for all the good respons guys!

I saw in comments that you getting this error

I get this
WARNING: Failed to Exception calling “Save” with “2” argument(s): “A generic error occurred in GDI+.”

“Per Nell Grant’s Comment above, try changing the [string] $OutFile Parameter on Line 29, as follows.
Before:
[string] $OutFile= “$($env:temp)\BGInfo.bmp”,
After:
[string] $OutFile=“$($env:temp)\” + ( ( get-date ).TimeOfDay.TotalSeconds ) + “BGInfo.bmp”,”

So its changed on the updated version in the script now.

Thanks for helping out!

Have a great day!

Pontus

43 Replies to “A Modern bginfo solution – just a simple powershell script”

  1. Fantastic alternative and works very well on Windows 10. Does not work on Windows 7 though. Any ideas on how to modify to work on both versions?

    Like

  2. Thanks for your efforts Pontus and for sharing!

    I’d like the option to locate the info to the lower-left of the desktop instead of top-right. Is that possible?

    Liked by 2 people

  3. There’s a few things that can go wrong here. 1) Your BMP save will try to save to the same file name every time the script runs. If the file already exists and it’s already set as the background, your save will fail with a generic GDI+ error. To fix that, you will need to make the $Outfile name unique every time it runs. 2) This does not work with multiple monitors where there is a combination of both landscape and portrait mode. This is because the script takes the entire resolution of the desktop and the ‘tallest’ y axis measurement brings the information off the screen. Perhaps messing with alignment could fix this. But generally this is not dynamic enough for crazy monitor setups, which seems to be more common these days.

    Still though, very cool script. I appreciate this at least being an option since BGinfo from SysInternals has its own silly limitations with resolution and scaling.

    Like

    1. aha that’s why,I always got that error, was trying to figure that, but didn´t solved it.

      Aha, think it will be hard to solve that issue, will think about it.

      Yes, got tired of bginfo in Sysinternals, register fixes need to get it to work properly.

      Thanks for everyone that uses this, feel free to improve it!

      Cheers.

      Like

      1. for the $outfile, i used:
        [string] $OutFile= “$($env:temp)\” + ( ( get-date ).TimeOfDay.TotalSeconds ) + “BGInfo.bmp”, to randomize it, and allow for multiple logins.

        What you may also want to introduce is a way to choose the “input background” as well, to start fresh if possible. I know you can set the background as it is, but if there is a default install, you should be using that background instead of re-writing the same

        Like

  4. Additionally, changed the info gathering to something I was able to use better:

    $systemInfo = ( .\systeminfo.exe )
    $memory = ( $systemInfo | Select-String ‘Total Physical Memory:’).ToString().Split(‘:’)[1].Trim()
    $osType = ( $systemInfo | Select-String ‘OS Name:’).ToString().Split(‘:’)[1].Trim()
    $osVersion = ( $systemInfo | Select-String ‘OS Version:’ )[0].ToString().Split(‘:’).Trim()[1]
    $BootTime = ( $systemInfo | Select-String ‘System Boot Time’ ).ToString().Substring(27)
    $domaincontroller = $env:LOGONSERVER.split(“\”)[2]

    $t = @”
    Server Computer Name : $env:COMPUTERNAME
    Currently logged on User : $env:USERNAME
    Logon Domain Controller : $domaincontroller
    Last System Start Time : $BootTime
    Total Memory count : $memory
    Total CPU core count : $env:NUMBER_OF_PROCESSORS
    Operating System Type: $osType
    Operating System Version : $osVersion
    Server Logon Domain : $env:USERDNSDOMAIN
    “@

    The extra spaces cleaned up the view when it is placed on the desktop.

    Like

  5. The script is great.

    I found these useful additions:

    $BuildInfo =(Get-ItemProperty -Path “HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion” -Name ReleaseId).ReleaseId
    $IPAddress =(Get-NetIPAddress -AddressFamily ipV4 | Where-Object {$_.IPAddress -notlike ‘127.0.*’} | Select -expandproperty IPAddress)
    $ServiceTag =(Get-WmiObject Win32_BIOS | Select -expandproperty SerialNumber)

    $t = @”

    Host Name: $env:COMPUTERNAME
    Service Tag: $ServiceTag
    IP Adress: $IPAddress
    User Name: $env:USERNAME
    Logon Domain: $env:USERDNSDOMAIN
    Logon Server: $env:LOGONSERVER
    OS Version: $OSVersion
    Build Info: $BuildInfo
    “@

    Like

    1. Thank you for posting, Eric.

      Unfortunately, I ran into an unforeseen problem w/ your Script.
      In most circumstances, your script updates should work, as intended.

      However, I have several NordVPN Adapters, which contain an APIPA Address (169.254.X.X), when the VPN is Deactivated.

      As a result, Four IP Addresses were Listed (169.254.43.40, 169.254.30.3, 192.168.1.127, 169.254.57.70).

      I ended up making a small update to the IP Address portion of your Script, to display only the working IP Address (192.168.1.127).

      Before:
      $IPAddress = (Get-NetIPAddress -AddressFamily ipV4 | Where-Object {$_.IPAddress -notlike ‘127.0.*’} | Select -expandproperty IPAddress)

      After:
      $IPAddress = (Get-NetIPAddress -AddressFamily ipV4 | Where-Object {$_.IPAddress -notlike ‘127.0.*’ -and $_.IPAddress -notlike ‘169.254.*’} | Select -expandproperty IPAddress)

      $t = @”
      IP Address: $IPAddress
      “@

      On a related note, there may be instances where you want to display an APIPA Address, since they are a good indicator of DHCP related Issues, etc.

      Therefore, I thought I’d share an alternative method of acquiring the IP Address.

      $IPAddress = ( Get-NetIPConfiguration | Where-Object { $_.IPv4DefaultGateway -ne $null -and $_.NetAdapter.Status -ne “Disconnected” } ).IPv4Address.IPAddress

      $t = @”
      IP Address: $IPAddress
      “@

      Thanks again!

      Like

  6. I have the script working how I want it. But every time I run it, the text is cut off by the edge of the screen. The script never changes the background settings from fill to stretch. Any ideas on how to get the text info to align correctly at the top right of the screen?

    Like

    1. Depends which background you are using, if you have windows original it should work, if you have a corporate background try to make it as windows background in size
      Pontus

      Like

  7. AVERTISSEMENT : Failed to Exception lors de l’appel de « Save » avec « 2 » argument(s) : « Une erreur générique s’est produite dans GDI+. »

    Any way to fix this ?

    Like

    1. Per Nell Grant’s Comment above, try changing the [string] $OutFile Parameter on Line 29, as follows.

      Before:
      [string] $OutFile= “$($env:temp)\BGInfo.bmp”,

      After:
      [string] $OutFile=“$($env:temp)\” + ( ( get-date ).TimeOfDay.TotalSeconds ) + “BGInfo.bmp”,

      Hope that helps.

      Like

    1. Hello Gearlos,

      As “Nell Grant” pointed out above, the [string]$OutFile Parameter (on Line 29) needs to be Updated, to Randomize the File Name, thereby allowing Multiple Logins, etc.

      Before:
      [string] $OutFile= “$($env:temp)\BGInfo.bmp”,

      After:
      [string] $OutFile=“$($env:temp)\” + ( ( get-date ).TimeOfDay.TotalSeconds ) + “BGInfo.bmp”,

      Give that a try and see if it resolves your issue.

      Like

  8. Hello,

    I am using this opportunity to write that this is very simple and good alternative to bginfo. I was using it for couple of months without issues but after september/october update 2020, script can not be run (Powershell has stopped working error).

    Detailed error: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

    Have anyone experienced the same type of error?

    Like

      1. Hello,

        Just for your info and for all others that could potentially experience this issue (Unhandled Exception: System.AccessViolationException). The problem was with Carbon Black Sensor application that was installed on workstations at that time period. That Cyber Security agent was blocking execution of the powershell script under regular user account. Since we are not using Carbon Black sensor, we have uninstalled it from workstations. This can be also resolved by granting execution of the powershell scripts in Carbon Black policies to group of users all whitelisting the scripts for all users.

        Like

      2. Hello,

        Just for your info and for all others that could potentially experience this issue (Unhandled Exception: System.AccessViolationException). The problem was with Carbon Black Sensor application that was installed on workstations at that time period. That Cyber Security agent was blocking execution of the powershell script under regular user account. Since we are not using Carbon Black sensor anymore, we have uninstalled it from workstations. This can be also resolved by granting execution of the powershell scripts in Carbon Black policies to group of users or whitelisting the scripts for all users.

        Like

  9. Getting this message when running

    WARNING: Failed cannot find the current wallpaper C:\Users\UserAccount\AppData\Local\Temp\BGInfo.bmp

    Like

  10. Maybe not enough coffee this morning but testing this out and one issue I have is running this at login with scheduled task and the first time it sets the info, I have the wallpaper #out since I don’t want to change it on the user. Works great, but the 2nd time they restart and login the info is over writing the old start time, so you end up with text on top of text but just for system boot time, what am I doing wrong?

    #Gather information

    $systemInfo = ( systeminfo )

    $BootTime = ( $systemInfo | Select-String ‘System Boot Time’ ).ToString().Substring(27)

    $BuildInfo =(Get-ItemProperty -Path “HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion” -Name ReleaseId).ReleaseId
    $IPAddress = (Get-NetIPAddress -AddressFamily ipV4 | Where-Object {$_.IPAddress -notlike ‘127.0.*’ -and $_.IPAddress -notlike ‘169.254.*’} | Select -expandproperty IPAddress)

    #Writing info to the background
    $t = @”
    Computername: $env:COMPUTERNAME
    Username: $env:USERNAME
    Build Info: $BuildInfo
    System Start Time : $Boottime
    IP Address: $IPAddress
    “@

    #Format etc
    $BGHT = @{
    Text = $t;
    Theme = “Current” ;
    FontName = “Segoe UI” ;
    UseCurrentWallpaperAsSource = $true ;
    }

    $WallPaper = New-BGinfo @BGHT

    #Runing the function
    Set-Wallpaper -Path $WallPaper.FullName -Style stretch

    Like

  11. i’m struggling to get this running on my domain.
    added it to startup at user and computer and added the powershell script at domaincontrollers netlogon folder. the script got domain users and domain computer with read and run enabled.. but i still cant get the info on my test laptop.. what am i forgetting here?
    when i run the script it works perfect except if you change wallpeper, then it disappear.

    Like

    1. i use the powershell script from cdirrigle https://pastebin.com/J2V5V9P4 posted earlier

      i like how it runs in the system tray as a question mark

      if i need the user or myself get any info, click on question mark and there it is
      i like how it doesn’t change the wallpaper

      i don’t believe the info needs to be there all the time, only when we need it

      Like

      1. One trick was getting this to run as a scheduled task for each user who logins into the device. I ended up pushing out a batch the puts the power shell I need on every device that runs the power shell to create the task in scheduling due gpo not liking a task for every user.

        Like

    1. #What triggers the task
      $STTrigger = New-ScheduledTaskTrigger -AtLogon
      $STName = “Pc Info Task”
      #Action to run as
      $STAction = New-ScheduledTaskAction -Execute “powershell.exe” -Argument ‘-NoProfile -windowstyle Hidden -NoLogo -NonInteractive -ExecutionPolicy Bypass -File c:\script\pcinfobox.ps1’
      #Configure when to stop the task
      $STSettings = New-ScheduledTaskSettingsSet -DontStopOnIdleEnd -ExecutionTimeLimit ([TimeSpan]::Zero)
      #Configure the principal to use for the scheduled task and the level to run as
      $STPrincipal = New-ScheduledTaskPrincipal -GroupId “BUILTIN\Users” -RunLevel “Highest”
      #Register the new scheduled task
      Register-ScheduledTask $STName -Action $STAction -Trigger $STTrigger

      This was what I created to add the task btw

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s