Take screenshot via script?

  • Thread starter Jakob.Mainka@googlemail.com
  • Start date
J

Jakob.Mainka@googlemail.com

Guest
Hi there...
does anyone know if there is a way to take a screenshot with a script?

Thanks,

Jakob
 


On Jan 25, 9:12 am, "Jakob.Mai...@googlemail.com"
<Jakob.Mai...@googlemail.com> wrote:
> Hi there...
> does anyone know if there is a way to take a screenshot with a script?
>
> Thanks,
>
> Jakob


This example will print your screen.

[reflection.assembly]::LoadWithPartialName("System.Drawing") > $null
$Bitmap = new-object System.Drawing.Bitmap 1280,1024
$Size = New-object System.Drawing.Size 1280,1024
$FromImage = [System.Drawing.Graphics]::FromImage($Bitmap)
$FromImage.copyfromscreen(0,0,0,0, $Size,
([System.Drawing.CopyPixelOperation]::SourceCopy))
$Bitmap.Save("c:\PrintScreen.png",
([system.drawing.imaging.imageformat]::png)); # the acceptable
values: png, jpeg, bmp, gif...
invoke-item c:\PrintScreen.png

Regards,
aleksandar
 
FYI, you can get the screen dimentions with WMI or .NET:

$screen = gwmi Win32_DesktopMonitor
$screen[0].screenHeight
$screen[0].screenWidth


[void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
$screen = [System.Windows.Forms.Screen]::GetWorkingArea(0)
$screen.width
$screen.height





-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com

> On Jan 25, 9:12 am, "Jakob.Mai...@googlemail.com"
> <Jakob.Mai...@googlemail.com> wrote:
>> Hi there...
>> does anyone know if there is a way to take a screenshot with a
>> script?
>> Thanks,
>>
>> Jakob
>>

> This example will print your screen.
>
> [reflection.assembly]::LoadWithPartialName("System.Drawing") > $null
> $Bitmap = new-object System.Drawing.Bitmap 1280,1024
> $Size = New-object System.Drawing.Size 1280,1024
> $FromImage = [System.Drawing.Graphics]::FromImage($Bitmap)
> $FromImage.copyfromscreen(0,0,0,0, $Size,
> ([System.Drawing.CopyPixelOperation]::SourceCopy))
> $Bitmap.Save("c:\PrintScreen.png",
> ([system.drawing.imaging.imageformat]::png)); # the acceptable
> values: png, jpeg, bmp, gif...
> invoke-item c:\PrintScreen.png
> Regards,
> aleksandar



 
Correction.. The working area (GetWorkingArea) is the desktop area of the
display, excluding taskbars, docked windows, and docked tool bars.
To get the full dimentions, use:

$screen = [System.Windows.Forms.Screen]::primaryScreen.Bounds
$screen.width
$screen.height


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com

> FYI, you can get the screen dimentions with WMI or .NET:
>
> $screen = gwmi Win32_DesktopMonitor
> $screen[0].screenHeight
> $screen[0].screenWidth
> [void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms
> ")
> $screen = [System.Windows.Forms.Screen]::GetWorkingArea(0)
> $screen.width
> $screen.height
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>> On Jan 25, 9:12 am, "Jakob.Mai...@googlemail.com"
>> <Jakob.Mai...@googlemail.com> wrote:
>>> Hi there...
>>> does anyone know if there is a way to take a screenshot with a
>>> script?
>>> Thanks,
>>> Jakob
>>>

>> This example will print your screen.
>>
>> [reflection.assembly]::LoadWithPartialName("System.Drawing") > $null
>> $Bitmap = new-object System.Drawing.Bitmap 1280,1024
>> $Size = New-object System.Drawing.Size 1280,1024
>> $FromImage = [System.Drawing.Graphics]::FromImage($Bitmap)
>> $FromImage.copyfromscreen(0,0,0,0, $Size,
>> ([System.Drawing.CopyPixelOperation]::SourceCopy))
>> $Bitmap.Save("c:\PrintScreen.png",
>> ([system.drawing.imaging.imageformat]::png)); # the acceptable
>> values: png, jpeg, bmp, gif...
>> invoke-item c:\PrintScreen.png
>> Regards,
>> aleksandar



 
On 25 Jan., 11:10, alexandair <alexand...@gmail.com> wrote:
> On Jan 25, 9:12 am, "Jakob.Mai...@googlemail.com"
>
> <Jakob.Mai...@googlemail.com> wrote:
> > Hi there...
> > does anyone know if there is a way to take a screenshot with a script?

>
> > Thanks,

>
> > Jakob

>
> This example will print your screen.
>
> [reflection.assembly]::LoadWithPartialName("System.Drawing") > $null
> $Bitmap = new-object System.Drawing.Bitmap 1280,1024
> $Size = New-object System.Drawing.Size 1280,1024
> $FromImage = [System.Drawing.Graphics]::FromImage($Bitmap)
> $FromImage.copyfromscreen(0,0,0,0, $Size,
> ([System.Drawing.CopyPixelOperation]::SourceCopy))
> $Bitmap.Save("c:\PrintScreen.png",
> ([system.drawing.imaging.imageformat]::png));  # the acceptable
> values: png, jpeg, bmp, gif...
> invoke-item c:\PrintScreen.png
>
> Regards,
> aleksandar


yeah thanks! exactly what i searched!
works great!
 
"Shay Levi" <no@addre.ss> wrote in message
news:8766a9441b9a18ca2d6ffe6fecc6@news.microsoft.com...
> Correction.. The working area (GetWorkingArea) is the desktop area of the
> display, excluding taskbars, docked windows, and docked tool bars.
> To get the full dimentions, use:
>
> $screen = [System.Windows.Forms.Screen]::primaryScreen.Bounds
> $screen.width
> $screen.height
>


And yet a few more ways:

[System.Windows.Forms.SystemInformation]::WorkingArea

And assuming you have .NET 3.0 or 3.5 (or are on Vista):

[System.Reflection.Assembly]::LoadWithPartialName('PresentationFramework')
[System.Windows.SystemParameters]::FullPrimaryScreenHeight
[System.Windows.SystemParameters]::FullPrimaryScreenWidth

:)

--
Keith

 

Back
Top