Thursday, 7 November 2013

BGInfo replacement

BGInfo is good and have been around for a long time but it has some flaws as for example the IP Address that usually is displayed with a couple "none" below or above it. There are some workarounds for this but still..

Another more recent flaw is the roaming of the background by UE-V. When an user logs on to a computer the background gets stamped by BGInfo then the user logs to a different computer and the stamped background which is brought by UE-V gets re-stamped.

A more elegant and flexible solution is to have a little tool available but usually hidden in the notification area.

The following script which has to run during logon creates an informational icon in the notification area and once clicked on will display the computer name, computer model, computer serial number, IP Address, IP Subnet, Subnet Mask, memory, user name and domain.

[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null

[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | out-null

$info = new-object System.Windows.Forms.NotifyIcon

$info.Icon = [System.Drawing.SystemIcons]::Information

$info.Visible = $true

Unregister-Event -SourceIdentifier click_event -ErrorAction SilentlyContinue

Register-ObjectEvent $info MouseClick -sourceIdentifier click_event -Action {




#Finds out IP Address, Subnet and Mask
 
 
$network = Get-WmiObject win32_networkadapterconfiguration -Filter "IPEnabled = $True"

$mask = $network.IPSubnet[0]

$IP = $network.IPAddress[0]

function toBinary ($dottedDecimal){

$dottedDecimal.split(".") | %{$binary=$binary + $([convert]::toString($_,2).padleft(8,"0"))}

return $binary



}
 
function toDottedDecimal ($binary){

do {$dottedDecimal += "." + [string]$([convert]::toInt32($binary.substring($i,8),2)); $i+=8 } while ($i -le 24)

return $dottedDecimal.substring(1)



}
 
$ipBinary = toBinary $IP

$smBinary = toBinary $mask

$netBits=$smBinary.indexOf("0")

$subnet = toDottedDecimal $($ipBinary.substring(0,$netBits).padright(32,"0"))

$model = (Get-WmiObject win32_bios).model

$memory = [MATH]::Round(((Get-WmiObject win32_computersystem).totalphysicalmemory)/1GB)

$serial = (Get-WmiObject win32_bios).serialnumber



 
 
$Form = New-Object System.Windows.Forms.Form

$Form.AutoSize = $true

$Form.startposition = "centerscreen"

$Form.Font = New-Object System.Drawing.Font("Arial",10,[System.Drawing.FontStyle]::Bold)

$Form.Text = "Computer Info"

$Form.BackColor = "#013D6F"

$Form.ForeColor = "White"

$modell = new-object System.Windows.Forms.Label

$modell.Location = new-object System.Drawing.Size(10,5)

$modell.size = new-object System.Drawing.Size(390,20)

$modell.Text = "Model: $($model)"

$modell.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter

$seriall = new-object System.Windows.Forms.Label

$seriall.Location = new-object System.Drawing.Size(10,30)

$seriall.size = new-object System.Drawing.Size(390,20)

$seriall.Text = "Serial: $serial"

$seriall.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter

$memoryl = new-object System.Windows.Forms.Label

$memoryl.Location = new-object System.Drawing.Size(10,55)

$memoryl.size = new-object System.Drawing.Size(390,20)

$memoryl.Text = "Memory: $memory GB"

$memoryl.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter

$computer = new-object System.Windows.Forms.Label

$computer.Location = new-object System.Drawing.Size(10,80)

$computer.size = new-object System.Drawing.Size(390,20)

$computer.Text = "Computer name: $($env:COMPUTERNAME)"

$computer.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter

$IPAddress = new-object System.Windows.Forms.Label

$IPAddress.Location = new-object System.Drawing.Size(10,105)

$IPAddress.size = new-object System.Drawing.Size(390,20)

$IPAddress.Text = "IP Address: $IP"

$IPAddress.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter

$IPSubnet = new-object System.Windows.Forms.Label

$IPSubnet.Location = new-object System.Drawing.Size(10,130)

$IPSubnet.size = new-object System.Drawing.Size(390,20)

$IPSubnet.Text = "IP Subnet: $Subnet"

$IPSubnet.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter

$SubnetMask = new-object System.Windows.Forms.Label

$SubnetMask.Location = new-object System.Drawing.Size(10,155)

$SubnetMask.size = new-object System.Drawing.Size(390,20)

$SubnetMask.Text = "Subnet Mask: $mask"

$SubnetMask.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter

$username = new-object System.Windows.Forms.Label

$username.Location = new-object System.Drawing.Size(10,180)

$username.size = new-object System.Drawing.Size(390,20)

$username.Text = "Username: $($env:USERNAME)"

$username.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter

$domain = new-object System.Windows.Forms.Label

$domain.Location = new-object System.Drawing.Size(10,205)

$domain.size = new-object System.Drawing.Size(390,20)

$domain.Text = "Domain: $($env:USERDOMAIN)"

$domain.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter



 
 
$Form.Controls.Add($modell)

$Form.Controls.Add($seriall)

$Form.Controls.Add($memoryl)

$Form.Controls.Add($computer)

$Form.Controls.Add($IPAddress)

$Form.Controls.Add($IPSubnet)

$Form.Controls.Add($SubnetMask)

$Form.Controls.Add($username)

$Form.Controls.Add($domain)

$Form.Add_Shown({$Form.Activate()})

$Form.ShowDialog()

} | Out-Null



You can automate the execution of the script in a few ways. You can place a shortcut in the StartUp folder, you can place it in the Run registry key or you can use GPP.

Just make sure you run it like this:

C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe -noexit -windowstyle hidden -file C:\WhereEverTheScriptIs.ps1

No comments:

Post a Comment