PowerShell V2停止屏幕分辨率干扰

时间:2015-10-20 14:40:22

标签: powershell-v2.0

我有一个加载.ps1表单的脚本。 目前的问题是我的显示器是100%,但对于一些人来说是125%,150%。

对于意味着屏幕文本将处于缩放状态的用户。 有没有办法阻止这个搞乱形式。 或者有没有办法检测显示是否已更改并重新应用字体大小?



Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object system.Windows.Forms.Form
$Form.Text = "Sample Form"
$Label = New-Object System.Windows.Forms.Label
$Label.Text = "This form is very simple."
$Label.AutoSize = $True
$Form.Controls.Add($Label)
$Form.ShowDialog()




2 个答案:

答案 0 :(得分:0)

这可能会有所帮助:

    #  If a user is logged on, then get display scale factor for logged on user (even if running in session 0)
[boolean]$UserDisplayScaleFactor = $false
If ($RunAsActiveUser) {
    [int32]$dpiPixels = Get-RegistryKey -Key 'HKCU\Control Panel\Desktop\WindowMetrics' -Value 'AppliedDPI' -SID $RunAsActiveUser.SID
    If (-not ([string]$dpiPixels)) {
        [int32]$dpiPixels = Get-RegistryKey -Key 'HKCU\Control Panel\Desktop' -Value 'LogPixels' -SID $RunAsActiveUser.SID
    }
    [boolean]$UserDisplayScaleFactor = $true
}
If (-not ([string]$dpiPixels)) {
    #  This registry setting only exists if system scale factor has been changed at least once
    [int32]$dpiPixels = Get-RegistryKey -Key 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI' -Value 'LogPixels'
    [boolean]$UserDisplayScaleFactor = $false
}
Switch ($dpiPixels) {
    96 { [int32]$dpiScale = 100 }
    120 { [int32]$dpiScale = 125 }
    144 { [int32]$dpiScale = 150 }
    192 { [int32]$dpiScale = 200 }
    Default { [int32]$dpiScale = 100 }
}

来源: AppDeployToolkitMain.ps1 文件中的http://psappdeploytoolkit.com/

答案 1 :(得分:0)

当我跑出Annoyed先生时,它给了我一个错误,它没有认出get-regkey术语。

然而,我确实提出了一种不同的方法来保持字体相同......



cd 'HKCU:\Control Panel\Desktop'
$val = Get-ItemProperty -Path . -Name "LogPixels"

if($val.LogPixels -eq 120)
{
    $Font = New-Object System.Drawing.Font("Microsoft Sans Serif",(8.25/1.25))
    $objForm.Font = $Font
}if($val.LogPixels -eq 150){
    $Font = New-Object System.Drawing.Font("Microsoft Sans Serif",(8.25/1.50))
    $objForm.Font = $Font
}




希望这可以帮助别人,只有这就是我在表单中有一个网页浏览器,无法设置缩放功能,放大/缩小......