Servidor
##Server
$port=2051
$IPEndPoint=New-Object System.Net.IPEndPoint([IPAddress]::Any,$port)
$TcpListener=New-Object System.Net.Sockets.TcpListener $IPEndPoint
$TcpListener.Start()
$AcceptTcpClient=$TcpListener.AcceptTcpClient()
$GetStream=$AcceptTcpClient.GetStream()
$StreamReader=New-Object System.IO.StreamReader $GetStream
$ReadAllLines = $StreamReader.ReadToEnd()
$Bytes = ([system.Text.Encoding]::Default).GetBytes($ReadAllLines)
rm screenshotcopy.bmp
[System.IO.File]::WriteAllBytes('screenshotcopy.bmp',$Bytes)
#Creación del formulario
$Image=[system.drawing.image]::FromFile(".\screenshotcopy.bmp")
$form2 = [Windows.Forms.Form] @{
Text = 'Mi formulario'
BackgroundImage = $Image
Width = $Image.Width
Height = $Image.Height
BackgroundImageLayout = "None"
WindowState = "maximized"
FormBorderStyle = "None"
}
$form2.ShowDialog()
$StreamReader.Dispose()
$GetStream.Dispose()
$AcceptTcpClient.Dispose()
Cliente
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
##Client $port=2051 $TcpClient=New-Object System.Net.Sockets.TcpClient([IPAddress]::Loopback, $port) $GetStream = $TcpClient.GetStream() $StreamWriter = New-Object System.IO.StreamWriter $GetStream $path='screenshot.bmp' $Bitmap=New-Object System.Drawing.Bitmap([System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Width, [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Height) $Graphics=[System.Drawing.Graphics]::FromImage($Bitmap) $Graphics.CopyFromScreen((New-Object System.Drawing.Point(0,0)), (New-Object System.Drawing.Point(0,0)), $Bitmap.Size) $Graphics.Dispose() $Bitmap.Save($path,'Bmp') $Bytes = [System.IO.File]::ReadAllBytes($path) $StreamWriter.Write($Bytes,0,$Bytes.length) $StreamWriter.Dispose() $GetStream.Dispose() $TcpClient.Dispose() |

