emeriks
Goto Top

PowerShell - Formular mit Webbrowser-Object - Schreiben nicht möglich

Hi,
ich will mit PowerShell ein Formular öffnen, welches nur ein Webbrowser enthält. In diesen Webbrowser will ich dann direkt den HTML-Code reinschreiben. Ich will nicht ein Dokument laden.
Allerding pasiert da nichts. Wenn ich den selben Code - natürlich in VB.Net übersetzt - im Visual Studio VB.Net verwende, dann schreibt er "Hallo Welt!" in den Browser. Unter PowerShell schreibt er nicht in Browser. Keine Fehlermeldung, nichts.

Was mache ich falsch?

Noch ein Hinweis:
Ich möchte nicht den Internet Explorer starten.

Add-Type -AssemblyName System.Windows.Forms
$IE = New-Object System.Windows.Forms.WebBrowser
$IE.AllowNavigation = $True
$IE.Dock = [System.Windows.Forms.DockStyle]::Fill
$IE.IsWebBrowserContextMenuEnabled = $False
$IE.Name = "WebBrowser1"  
$IE.ScriptErrorsSuppressed = $True
$IE.ScrollBarsEnabled = $False
$IE.TabIndex = 0
$IE.Url = New-Object System.Uri -ArgumentList "about:blank", [System.UriKind]::Absolute  
$IE.WebBrowserShortcutsEnabled = $False

$Form = New-Object System.Windows.Forms.Form
$Form.AutoScaleDimensions = New-Object System.Drawing.SizeF -ArgumentList 6, 13
$Form.AutoScaleMode = [System.Windows.Forms.AutoScaleMode]::Font
$Form.ClientSize = New-Object System.Drawing.Size -ArgumentList 378, 254
$Form.ControlBox = $True
$Form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::None
$Form.MaximizeBox = $False
$Form.MinimizeBox = $False
$Form.ShowIcon = $False
$Form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
$Form.Text = ""  
$Form.TopMost = $True
$Form.WindowState = [System.Windows.Forms.FormWindowState]::Normal

$Form.Controls.Add($IE)

$Form.Show()

$IE.Document.Write("Hallo Welt!")  

Content-Key: 358689

Url: https://administrator.de/contentid/358689

Printed on: April 20, 2024 at 04:04 o'clock

Member: emeriks
emeriks Dec 19, 2017 at 20:30:35 (UTC)
Goto Top
Hab's selbst gefunden.
Bei "$Form.Show()" friert das Formular ein. Warum auch immer. Mit "$Form.ShowDialog()" funktioniert es.
Mitglied: 134998
134998 Dec 20, 2017 updated at 10:40:42 (UTC)
Goto Top
$Form.Show()
Show() is non blocking in contrast to ShowDialog() but powershell has no application loop, so the form crashes because it's resources are removed by the shell in the background cause it wants to close itself.

Best regards
Tom