I copied this PowerShell code from some site, that show the current position of the mouse:
[Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null
$control = [System.Windows.Forms.Control]
$mouseX = $control::MousePosition.X
$mouseY = $control::MousePosition.Y
Write-Host 'MousePosition:' $mouseX $mouseY
I reviewed the System.Windows.Forms.Control class documentation and discovered several properties that are "sisters" of MousePosition (like Bottom, Bounds, Left, Location, Right or Top), that contain measures about the "control" in pixels, so I tried to also report the Location property values this way:
[Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null
$control = [System.Windows.Forms.Control]
$mouseX = $control::MousePosition.X
$mouseY = $control::MousePosition.Y
Write-Host 'MousePosition:' $mouseX $mouseY
$locationX = $control::Location.X
$locationY = $control::Location.Y
Write-Host 'Location:' $locationX $locationY
However this code don't works: no error is reported, but the Location values don't appear:
MousePosition: 368 431
Location:
Why the MousePosition property can be correctly accessed, but the Location one not?
The purpose of this code is to get the dimensions and position in pixels of the cmd.exe window in which the PowerShell script run. What is the right way to get these values in PowerShell?