Greetings,
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
[System.Windows.Forms.Application]::EnableVisualStyles()
#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
$menuitem1.add_Click({
$notifyicon.Visible = $False
Closing_Form
})
function Closing_Form{
$frm_Main.Close()
$notifyicon.Dispose()
$frm_Main.Dispose()
#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)