启动out-gridview后,Winform调整大小/缩小

时间:2018-12-07 08:19:57

标签: c# powershell

我遇到一个问题,当我启动到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."

}

Shrinking

Script

$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

0 个答案:

没有答案