首页 > 解决方案 > 启动 out-gridview 后 Winform 调整大小/缩小

问题描述

我有一个问题,当我启动到 out-gridview 时,我的 winform 正在缩小/调整大小,不知道为什么会这样。

谁能帮忙,我附上了代码。这与上次我认为我似乎无法理解为什么会这样略有不同。

可能只是我的环境导致了问题,但它不再发生在我的其他工具上,这让我建议它是代码。

最近几天我一直在尝试解决它,但我就是无法破解它。

任何人有任何建议....真的卡住了。

#This function creates a list of all of the SCCM delivered and installed MSI's
$ComputerName = $env:COMPUTERNAME

#reg path for 32 bit installs
$uninstallkey32 = "software\\microsoft\\windows\\currentversion\\uninstall"
#reg path for 64 bit installs
$uninstallkey64 = "software\\wow6432Node\\microsoft\\windows\\currentversion\\uninstall"
#registry hive to open
$reg = [microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$ComputerName)
$regkey = $reg.OpenSubKey($uninstallkey32)
$regkey64 = $reg.OpenSubKey($uninstallkey64)
#get all subkeys
$subkeys = $regkey.GetSubKeyNames()
$subkeys64 = $regkey64.GetSubKeyNames()
#clear displayname array
$DisplayName = @()
#loop through 32 bit installs
foreach ($key in $subkeys)
{
    $thiskey = $uninstallkey32+"\\"+$key
    $thissubkey = $reg.OpenSubKey($thiskey)
    if ($thissubkey.GetValue("InstallSource") -like "C:\Windows\ccmcache*")
    {
        #add msi data to array
        $DisplayName += ,@($thissubkey.GetValue("DisplayName"),$thissubkey.GetValue("DisplayVersion"),$key)
    }
}
#loop through 64 bit installs
foreach ($key in $subkeys64)
{
    $thiskey = $uninstallkey64+"\\"+$key
    $thissubkey = $reg.OpenSubKey($thiskey)
    if ($thissubkey.GetValue("InstallSource") -like "C:\Windows\ccmcache*")
    {
        #add msi data to array
        $DisplayName += ,@($thissubkey.GetValue("DisplayName"),$thissubkey.GetValue("DisplayVersion"),$key)
    }
}
#remove duplicates from arry and sort
$sorted_name = $DisplayName |Sort |Get-Unique 
$sorted_name = $sorted_name| ? {$_}

$Application = Foreach ($Name in $sorted_Name)
{
    $Name | Select @{Name = 'Name';Expression = {$Name[0]}}, @{Name = 'GUID';Expression = {$Name[2]}} | Select #-Unique

}

$SelectedApplication = $Application | Out-GridView -PassThru -Title "Please select MSI to Uninstall" | Select-Object -ExpandProperty "GUID" | Out-String 
$SelectMSIName = $Application | Select-Object "Name"


try {

    #Invoke-Expression "PsExec.exe \\" + $ComputerName + " cmd /c msiexec /uninstall '" + $SelectedApplication + "' /qn /norestart"

    .\PsExec.exe \\$ComputerName cmd /c msiexec /uninstall $SelectedApplication /qn /norestart

    LogWrite "Application removed succesfully. Reboot may be required"


} catch {

    LogWrite "Failed to uninstall application."

}

收缩

脚本

$AdminTool                       = New-Object system.Windows.Forms.Form

$AdminTool.MinimumSize           = New-Object System.Drawing.Size(770, 380)

$AdminTool.Width                 = 770

$AdminTool.Height                = 380

$AdminTool.AutoSize              = $false

$AdminTool.AutoScaleMode         = "None"

$AdminTool.text                  = "MOD"

$AdminTool.BackColor             = $Form_BG

$AdminTool.TopMost               = $false

$AdminTool.StartPosition         = "CenterScreen"

$AdminTool.FormBorderStyle       = "FixedDialog"

$AdminTool.MaximizeBox           = $false

$AdminTool.ControlBox            = $falses

$AdminTool.MinimizeBox           = $false

$AdminTool.MainMenuStrip         = $MainMenu

$AdminTool.KeyPreview = $True

$AdminTool.Add_KeyDown({if ($_.KeyCode -eq "Return"){ConnectPC}})

这是表格代码

Powershell 主要次要构建修订版本


5 1 15063 1446

标签: c#powershell

解决方案


推荐阅读