简体   繁体   English

Powershell:如何获取登录用户的主屏幕分辨率?

[英]Powershell: How can i get the primary screen resolution of a logged in user?

Our current scenario is this:我们目前的情况是这样的:

We have more than 80 tablet computers (running Windows 10) in our network that run under the same user ( DefaultUser ).我们的网络中有 80 多台平板电脑(运行 Windows 10)在同一用户( DefaultUser )下运行。 In order to verify that the display settings are correctly set, we would like to use a powershell script to automatically check the used resolution remotely with a support user account.为了验证显示设置是否正确设置,我们想使用 powershell 脚本通过支持用户帐户远程自动检查使用的分辨率。

So far, we know how to get the primary screen resolution for the user under which the script gets executed (which is rather easy):到目前为止,我们知道如何为执行脚本的用户获取主屏幕分辨率(这很容易):

  // get primary screen width
  Add-Type -AssemblyName System.Windows.Forms
  [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Width   // height accordingly

In case we execute this script on one of the tablets using the support account, we get the primary screen resolution for the support account user - but not for the desired user DefaultUser .如果我们使用支持帐户在其中一台平板电脑上执行此脚本,我们将获得支持帐户用户的主屏幕分辨率 - 但不是所需用户DefaultUser

How can we get the resolution for the DefaultUser ?我们如何获得DefaultUser的分辨率?

The only solution that easily comes to my mind is a rather ugly thing: Using the windows task scheduler i could create a task that executes the script (under the defaultUser) to get the screen resolution and write the result(s) into a file that can be accessed by the support user account.唯一容易想到的解决方案是一件相当丑陋的事情:使用 windows 任务调度程序,我可以创建一个执行脚本的任务(在 defaultUser 下)以获取屏幕分辨率并将结果写入一个文件可以通过支持用户帐户访问。 But i am looking for something more elegant.但我正在寻找更优雅的东西。

You may be able to use CIM or WMI to get from point a to b.您也许可以使用 CIM 或 WMI 从点 a 到 b。

CIM_VideoController is the class that would contain the resolution. CIM_VideoController 是包含分辨率的 class。

Using PowerShell Core:使用 PowerShell 内核:

Get-CimInstance CIM_VideoController | Select SystemName, CurrentHorizontalResolution, CurrentVerticalResolution

Using Windows PowerShell:使用 Windows PowerShell:

Get-WmiObject Win32_VideoController | Select SystemName, CurrentHorizontalResolution, CurrentVerticalResolution

You should be able to open the proper ports to use either of these options remotely (though you could also probably get away with using Invoke-Command to run them, as long as you use CredSSP or Kerberos Delegation to take the 2nd hop problem into account).您应该能够打开正确的端口以远程使用这些选项中的任何一个(尽管您也可以使用 Invoke-Command 来运行它们,只要您使用 CredSSP 或 Kerberos 委派来考虑第二跳问题)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM