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-ID: 358689

Url: https://administrator.de/forum/powershell-formular-mit-webbrowser-object-schreiben-nicht-moeglich-358689.html

Ausgedruckt am: 31.03.2025 um 15:03 Uhr

emeriks
emeriks 19.12.2017 um 21:30:35 Uhr
Goto Top
Hab's selbst gefunden.
Bei "$Form.Show()" friert das Formular ein. Warum auch immer. Mit "$Form.ShowDialog()" funktioniert es.
134998
134998 20.12.2017 aktualisiert um 11:40:42 Uhr
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