Over my head non-programmer

I am in no way a programmer; how many times have you heard that?

I am dabbling only that I need to create a desktop “program” that works with our Autotask PSA application. I have some Autotask API PowerShell code provided by another astute person that I have managed to get the very basics of what I need working.

Now is to encompass that with some other code that will create a desktop user system tray icon that can be used to submit helpdesk requests to our system via API. There are other ones out there included with our RMM for example that send an email, but there are no dynamic system variables.

In using a GUI designer website + some googling, I have been able to get some things working. I will be compiling to EXE, after all, said and done. I am not sure how that will work out on older systems like Windows 7, 8.1 yet - but that’s another day’s issue.

What I am looking for here is:

  • Getting proper closing of the script itself, clearing all variables from memory.
  • Getting the context menu option of the notification error, that when right click and choose exit it does the above.
  • How to get clicking on the icon to bring up the forms dialogue box, closing the form with the X does not exit the program, just closes the form. All tasks are controlled by the notification area icon.

In trying different things, I often get “The script failed due to call depth overflow”

Add-Type -AssemblyName System.Windows.Forms

#region begin GUI{ 

$frm_Main                        = New-Object system.Windows.Forms.Form
$frm_Main.ClientSize             = '400,400'
$frm_Main.text                   = "Helpdesk"
$frm_Main.BackColor              = "#4a90e2"
$frm_Main.TopMost                = $true
$frm_Main.AutoScroll             = $false
$frm_Main.MinimizeBox            = $true
$frm_Main.MaximizeBox            = $false
#$frm_Main.ControlBox             = $false
$frm_Main.WindowState            = 'Normal'
$frm_Main.ShowInTaskbar          = $true
$frm_Main.StartPosition          ='CenterScreen'
$frm_Main.icon                   = "helpdesk.ico"
$frm_Main.Visible                = $false

#region gui notifications {
$notifyicon = New-Object System.Windows.Forms.NotifyIcon
$notifyicon.Text = "Submit a Ticket"
$notifyicon.Icon = "helpdesk.ico"
$notifyicon.Visible = $true

$ContextMenu = New-Object System.Windows.Forms.ContextMenu
$notifyicon.ContextMenu = $ContextMenu

$menuitem1 = New-Object System.Windows.Forms.MenuItem
$menuitem1.Index = 7
$menuitem1.Text = "Exit"

# Add Context MenuItems
[void] $ContextMenu.MenuItems.Add($menuitem1)

# Add Exit MenuItem to notification area
  $notifyicon.Visible = $False


function Closing_Form{
  #Stop-Process $pid  # removed for now

#Register-ObjectEvent -InputObject $notifyicon -EventName Click -SourceIdentifier Clicked_event -Action {$frm_Main.ShowDialog()} | Out-Null ## This was the only way I could get a click on the item to work, just not consistent and caused issues if I stopped in ISE and tried to run again - instance already there. Had to exit 

#endregion notifications }

#region gui events {

$frm_Main.Add_FormClosing({ Closing_Form })

#endregion events }

#endregion GUI }

#Write your logic code here

[void]$frm_Main.ShowDialog()  ## ideally, don't want to run at the start, just when icon tapped

I appreciate any guidance (articles or comments)


Yea, well, we all gotta start somewhere. However, if you’ve never programmed or learned a programming language. You are really jumping into the deep end of the pool here and that is a dangerous precedence, well, in this case a balding precedence, since lots of hair pulling is bound to happen. As you have hit thus far.

This is first and foremost not a PS specific issue, but a Windows Forms / WFP design issue.

If you are trying to do system tray-like or Windows balloon notification stuff, this is not going to do that.
You’d have to do stuff like this.

Balloon notification

Creating a Balloon Tip Notification Using PowerShell -- Microsoft Certified Professional Magazine Online

System Tray app

Creating a system tray application with PowerShell - SAPIEN Blog

So, you are going to take a step back and approach your form build, one segment at a time and see where it breaks as you add each segment. Well, that and going into debug modes to see where it breaks and then correcting it.

Now, the Sapien PS Studio is the premier PS specific editor around, especially for goals like what you are after, IMHO. Yet, it’s not cheap. You can do this without it, in the PowerShell_ISE on in Visual Studio Code, but PSS will make this far easier and as from the link, they provide a forum showing you how.

Thanks for the advice.

I do have some prehistoric experience with Java (1999) and VB.Net (3.0) and some BASIC.

I was able to replicate what I want in VB.NET, thanks to an article

I tried a trial of the Powershell Studio, a little rich for me at the moment. My Visual Studio I got from our work MSDN.
Powershell Equivalent would be wonderful and easy to deploy.

That being said, I have a base of what I want GUI in VB.Net and programically (real word?) in Powershell.

If there is a method of taking variables from VB.NET and run the Powershell command passing those, I might be able to b@sterdize a solution.,

Thanks again for the help!