Advertisement
UlrichC

System Information on Desktop Wallpaper

Jul 10th, 2019
2,487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ########################Add Types###################################################
  2. Add-Type -AssemblyName PresentationFramework
  3. Add-Type -AssemblyName System.Windows.Forms
  4. Add-Type -Name Window -Namespace Console -MemberDefinition '
  5. [DllImport("Kernel32.dll")]
  6. public static extern IntPtr GetConsoleWindow();
  7.  
  8. [DllImport("user32.dll")]
  9. public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
  10. '
  11. $ErrorActionPreference = "SilentlyContinue"
  12.  
  13. $Runspace = [runspacefactory]::CreateRunspace()
  14. $Runspace.ApartmentState = "STA"
  15. $Runspace.ThreadOptions = "ReuseThread"
  16. $Runspace.Open()
  17.  
  18. $code = {
  19.  
  20.  
  21. #Find the primary monitor
  22. $Monitor = [System.Windows.Forms.Screen]::AllScreens | Where-Object {$_.Primary -Like "True"}
  23.  
  24. #Set Window position based on the primary monitor's resolution.
  25. $Global:Left = $Monitor.bounds.Width - 345
  26. $Global:Top = $Monitor.bounds.Height #Curretnly not using this because it's just easier to set the absolute value in the XAML below.
  27.  
  28. [xml]$xaml = @"
  29. <Window
  30. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  31. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="Window_Main"
  32.  
  33. Title="BGInfo" ShowInTaskbar="False" Focusable="False" ResizeMode="NoResize" WindowStyle="None" Left="$Left" Top="20" RenderTransformOrigin="0.5,0.5" Height="45" Width="250">
  34. <Grid Background="#FF070707" AllowDrop="True">
  35.  <TextBlock x:Name="TextBlock_ComputerName" Height="40" Grid.Column="0" Grid.Row="0" VerticalAlignment="Bottom" Margin="9.5,0,9.5,6" Foreground="White" HorizontalAlignment="Left" FontSize="14">
  36.      <Run Text="Computer Name: LAAA0000AAA0000" />
  37.      <LineBreak />
  38.      <Run Text="IP Address(es):     10.120.120.120. 10.120.120.120." />
  39.      <LineBreak />
  40.      <LineBreak />
  41.  </TextBlock>
  42.  <Button Content="Button" IsTabStop="False" x:Name="Button_1" Height="11" Width="24" Opacity="0" RenderTransformOrigin="0.5417,0.5" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,218,29.5" />
  43.  <Button Content="Button" IsTabStop="False" Width="25" Height="15" x:Name="Button_2" Opacity="0" RenderTransformOrigin="0.5,0.5" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="2,0,0,-1.5" />
  44. </Grid>
  45. </Window>
  46. "@
  47.  
  48. $syncHash = [hashtable]::Synchronized(@{})
  49. $reader=(New-Object System.Xml.XmlNodeReader $xaml)
  50. $syncHash.Window=[Windows.Markup.XamlReader]::Load( $reader )
  51.  
  52. $SyncHash.TextBlock_ComputerName = $SyncHash.Window.FindName("TextBlock_ComputerName")
  53. #These buttons are only here as a hidden method to conveniently close this window
  54. $SyncHash.Button_1 = $SyncHash.Window.FindName("Button_1")
  55. $SyncHash.Button_2 = $SyncHash.Window.FindName("Button_2")
  56.  
  57.  
  58. #These buttons will close the window if clicked within the right order within a certain time.
  59. $SyncHash.Button_1.Add_Click({
  60.    $Global:FirstClickTime = (Get-Date) + (New-TimeSpan -Seconds 3)
  61. })
  62.  
  63. $SyncHash.Button_2.Add_Click({
  64.    IF ((Get-Date) -Lt $Global:FirstClickTime) {$SyncHash.Window.Close()}
  65.    
  66. })
  67.  
  68. $syncHash.Host = $host
  69. $Runspace = [runspacefactory]::CreateRunspace()
  70. $Runspace.ApartmentState = "STA"
  71. $Runspace.ThreadOptions = "ReuseThread"
  72. $Runspace.Open()
  73. $Runspace.SessionStateProxy.SetVariable("syncHash",$syncHash)
  74.  
  75.  
  76. $code = {
  77.    Do {
  78.    $IPAddresses = (Get-NetIPAddress | Where-Object {$_.AddressFamily -Eq "IPv4"} | Where-Object {$_.InterFaceAlias -Eq "Wi-Fi" -Or $_.InterFaceAlias -Eq "Ethernet"} | Where-Object {$_.AddressState -Eq "Preferred"}).IPAddress
  79.    #Set the contents of the Text Block
  80.    $SyncHash.TextBlock_ComputerName.Dispatcher.invoke([action]{
  81.    $SyncHash.TextBlock_ComputerName.Text = "Computer Name: $Env:COMPUTERNAME
  82. Active IP Address: $IPAddresses"
  83.    })
  84.    Start-Sleep 10
  85.    } Until (1 -eq 2)
  86. }#End of Code Block
  87.  
  88. $PSinstance = [powershell]::Create().AddScript($Code)
  89. $PSinstance.Runspace = $Runspace
  90. $job = $PSinstance.BeginInvoke()#
  91.  
  92.  
  93. $SyncHash.Window.ShowDialog()
  94.  
  95.  
  96.    }#End of Code Block
  97.  
  98.    $PSinstance = [powershell]::Create().AddScript($Code)
  99.    $PSinstance.Runspace = $Runspace
  100.    $job = $PSinstance.BeginInvoke()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement