Использовать PowerShell Добавить элемент управления веб-браузера, Ошибка сценария подсказки - PullRequest
0 голосов
/ 06 июня 2019

Я пытаюсь добавить элемент управления веб-браузера с помощью powershell, но у меня возникла следующая проблема, любые предложения приветствуются, заранее спасибо

1. Некоторые простые веб-страницы могут отображаться нормально

2.Но для веб-страниц html5 или веб-страниц с элементами управления Flash они не могут загружаться должным образом, показывая ошибки скрипта.

3.Если я использую браузер IE, чтобы открыть три вышеуказанные страницы напрямую, я могу открыть их успешно.

На следующем GIF-изображении показана загрузка трех веб-страниц

enter image description here

function Show-web_psf {

    [void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
    [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    #endregion Import Assemblies

    [System.Windows.Forms.Application]::EnableVisualStyles()
    $form1 = New-Object 'System.Windows.Forms.Form'
    $webbrowser1 = New-Object 'System.Windows.Forms.WebBrowser'
    $buttonFlashWebUnableToOpen = New-Object 'System.Windows.Forms.Button'
    $buttonH5WebUnableToOpenPro = New-Object 'System.Windows.Forms.Button'
    $buttonSimpleWebCanOpenNorm = New-Object 'System.Windows.Forms.Button'
    $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'

    $form1_Load = {
        #TODO: Initialize Form Controls here

    }

    function Set-WebBrowserEmulation
    {
        param
        (
            [ValidateNotNullOrEmpty()]
            [string]$ExecutableName = [System.IO.Path]::GetFileName([System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName)
        )

        #region Get IE Version
        $valueNames = 'svcVersion', 'svcUpdateVersion', 'Version', 'W2kVersion'

        $version = 0;
        for ($i = 0; $i -lt $valueNames.Length; $i++)
        {
            $objVal = [Microsoft.Win32.Registry]::GetValue('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer', $valueNames[$i], '0')
            $strVal = [System.Convert]::ToString($objVal)
            if ($strVal)
            {
                $iPos = $strVal.IndexOf('.')
                if ($iPos -gt 0)
                {
                    $strVal = $strVal.Substring(0, $iPos)
                }

                $res = 0;
                if ([int]::TryParse($strVal, [ref]$res))
                {
                    $version = [Math]::Max($version, $res)
                }
            }
        }

        if ($version -lt 7)
        {
            $version = 7000
        }
        else
        {
            $version = $version * 1000
        }
        #endregion

        [Microsoft.Win32.Registry]::SetValue('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', $ExecutableName, $version)
    }

    #endregion

    $buttonSimpleWebCanOpenNorm_Click = {
        #TODO: Place custom script here
        $webbrowser1.Url = "http://www.bing.com"
    }

    $buttonH5WebUnableToOpenPro_Click = {
        #TODO: Place custom script here
        $webbrowser1.Url = "http://online.focusky.com/fazc/plom/"
    }

    $buttonFlashWebUnableToOpen_Click = {
        #TODO: Place custom script here
        $webbrowser1.Url = "http://fs.focusky.com.cn/gtsdr/nelz/index.html?flash"
    }

    #region Generated Events
    #----------------------------------------------

    $Form_StateCorrection_Load=
    {
        #Correct the initial state of the form to prevent the .Net maximized form issue
        $form1.WindowState = $InitialFormWindowState
    }

    $Form_Cleanup_FormClosed=
    {
        #Remove all event handlers from the controls
        try
        {
            $buttonFlashWebUnableToOpen.remove_Click($buttonFlashWebUnableToOpen_Click)
            $buttonH5WebUnableToOpenPro.remove_Click($buttonH5WebUnableToOpenPro_Click)
            $buttonSimpleWebCanOpenNorm.remove_Click($buttonSimpleWebCanOpenNorm_Click)
            $form1.remove_Load($form1_Load)
            $form1.remove_Load($Form_StateCorrection_Load)
            $form1.remove_FormClosed($Form_Cleanup_FormClosed)
        }
        catch { Out-Null <# Prevent PSScriptAnalyzer warning #> }
    }
    #endregion Generated Events

    #----------------------------------------------
    #region Generated Form Code
    #----------------------------------------------
    $form1.SuspendLayout()
    #
    # form1
    #
    $form1.Controls.Add($webbrowser1)
    $form1.Controls.Add($buttonFlashWebUnableToOpen)
    $form1.Controls.Add($buttonH5WebUnableToOpenPro)
    $form1.Controls.Add($buttonSimpleWebCanOpenNorm)
    $form1.AutoScaleDimensions = '6, 13'
    $form1.AutoScaleMode = 'Font'
    $form1.ClientSize = '944, 502'
    $form1.Name = 'form1'
    $form1.StartPosition = 'CenterScreen'
    $form1.Text = 'Form'
    $form1.add_Load($form1_Load)
    #
    # webbrowser1
    #
    $webbrowser1.Anchor = 'Top, Bottom, Left, Right'
    $webbrowser1.Location = '-3, 42'
    $webbrowser1.MinimumSize = '20, 20'
    $webbrowser1.Name = 'webbrowser1'
    $webbrowser1.Size = '945, 460'
    $webbrowser1.TabIndex = 3
    #
    # buttonFlashWebUnableToOpen
    #
    $buttonFlashWebUnableToOpen.Location = '613, 13'
    $buttonFlashWebUnableToOpen.Name = 'buttonFlashWebUnableToOpen'
    $buttonFlashWebUnableToOpen.Size = '298, 23'
    $buttonFlashWebUnableToOpen.TabIndex = 2
    $buttonFlashWebUnableToOpen.Text = 'Flash Web: Unable to open, prompt script error'
    $buttonFlashWebUnableToOpen.UseCompatibleTextRendering = $True
    $buttonFlashWebUnableToOpen.UseVisualStyleBackColor = $True
    $buttonFlashWebUnableToOpen.add_Click($buttonFlashWebUnableToOpen_Click)
    #
    # buttonH5WebUnableToOpenPro
    #
    $buttonH5WebUnableToOpenPro.Location = '292, 13'
    $buttonH5WebUnableToOpenPro.Name = 'buttonH5WebUnableToOpenPro'
    $buttonH5WebUnableToOpenPro.Size = '297, 23'
    $buttonH5WebUnableToOpenPro.TabIndex = 1
    $buttonH5WebUnableToOpenPro.Text = 'H5 Web: Unable to open, prompt script error'
    $buttonH5WebUnableToOpenPro.UseCompatibleTextRendering = $True
    $buttonH5WebUnableToOpenPro.UseVisualStyleBackColor = $True
    $buttonH5WebUnableToOpenPro.add_Click($buttonH5WebUnableToOpenPro_Click)
    #
    # buttonSimpleWebCanOpenNorm
    #
    $buttonSimpleWebCanOpenNorm.Location = '33, 13'
    $buttonSimpleWebCanOpenNorm.Name = 'buttonSimpleWebCanOpenNorm'
    $buttonSimpleWebCanOpenNorm.Size = '235, 23'
    $buttonSimpleWebCanOpenNorm.TabIndex = 0
    $buttonSimpleWebCanOpenNorm.Text = 'Simple web: Can open normally'
    $buttonSimpleWebCanOpenNorm.UseCompatibleTextRendering = $True
    $buttonSimpleWebCanOpenNorm.UseVisualStyleBackColor = $True
    $buttonSimpleWebCanOpenNorm.add_Click($buttonSimpleWebCanOpenNorm_Click)
    $form1.ResumeLayout()
    #endregion Generated Form Code

    #----------------------------------------------

    #Save the initial state of the form
    $InitialFormWindowState = $form1.WindowState
    #Init the OnLoad event to correct the initial state of the form
    $form1.add_Load($Form_StateCorrection_Load)
    #Clean up the control events
    $form1.add_FormClosed($Form_Cleanup_FormClosed)
    #Show the Form
    return $form1.ShowDialog()

} #End Function

#Call the form
Show-web_psf | Out-Null
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...