locked
Windows Forms RRS feed

  • Question

  • Hello,

    I have a task to display an image notification at users desktop, and I´m trying to achive that with powershell. When I run the script below locally works well, but if I run remotely I got this error.

    ---------------------------------------Script--------

    Add-Type -AssemblyName System.Windows.Forms;
    [System.Windows.Forms.MessageBoxOptions]::DefaultDesktopOnly


    $img = [System.Drawing.Image]::FromFile('\\SERVER\NetLogon\wallpaper\IMG.jpg');


    $form = New-Object Windows.Forms.Form
    $form.Text =  "Canal Integridade";
    $form.StartPosition = "CenterScreen";
    $form.Width = 1240;
    $form.Height = 720;


    $pictureBox = New-Object Windows.Forms.PictureBox;
    $pictureBox.Image = $img;
    $pictureBox.SizeMode = "StretchImage";
    $pictureBox.Width = $form.Width;
    $pictureBox.Height =$form.Height;


    $form.Controls.add($pictureBox);
    $form.ShowDialog()
    $form.Show();

    Thanks!!!

    Rodrigo Daphanis


    Rodrigo Daphanis

    Tuesday, August 21, 2018 3:09 PM

All replies

  • You cannot remotely display a form.  It is not supported in Windows.


    \_(ツ)_/

    • Proposed as answer by John Seerden Tuesday, August 21, 2018 3:20 PM
    Tuesday, August 21, 2018 3:15 PM
  • You might have some luck with the below code:

    Invoke-WmiMethod -Path win32_process -Name create -ArgumentList "msg * this is the message text" -ComputerName hostname
    Even though its not a "full form", it may still work for your purposes


    Tuesday, August 21, 2018 3:20 PM