Hi,
So I did some playing around, and there are a couple of things I thought would be useful to add to the code above.
params
numeric p_delay : IN
string p_heading : IN
string p_message : IN
string p_icon : IN
endparams
variables
string v_sql, v_line
numeric v_status
handle v_shell
endvariables
if(p_delay = "" | p_delay = 0)
p_delay = 5000
else
p_delay = p_delay*1000
endif
v_sql = "powershell -windowstyle hidden -Command %%"Add-Type -AssemblyName System.Windows.Forms ;"
v_sql = $concat(v_sql," $global:balloon = New-Object System.Windows.Forms.NotifyIcon ;")
v_sql = $concat(v_sql," $path = (Get-Process -id $pid).Path;")
v_sql = $concat(v_sql," $balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;")
v_sql = $concat(v_sql," $balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::None ;")
v_sql = $concat(v_sql," $balloon.BalloonTipText = '",$replace(p_message,1,"'","\'",-1),"';")
v_sql = $concat(v_sql," $balloon.BalloonTipTitle = '",p_heading,"' ;")
v_sql = $concat(v_sql," $balloon.Visible = $true ;")
v_sql = $concat(v_sql," $balloon.ShowBalloonTip(",p_delay,");")
v_sql = $concat(v_sql," Start-Sleep -Milliseconds ",p_delay,";")
v_sql = $concat(v_sql," $global:balloon.Dispose();%%"")
newinstance "WSH_WSHSHELL",v_shell
v_shell->run(v_status,v_sql,0,0)
deleteinstance v_shell
Notes:-
- It seems the variable delay for notifications is deprecated, and now based on system accessibility settings. So all the p_delay in here is (basically) pointless.
- The code above left an icon in the system tray, which vanished on mouse over, but it was stacking icons up if left to run several times. So I instituted the $global:balloon.Dispose() to clear it. However, this seems to get rid of the resources before it can display the icon for the application, so I put in the Sleep command to keep the NotifyIcon around long enough to display the tooltip properly.
- Finally, I remembered we'd implemented the shell dll as a signature I could use the Wshell.run command rather than using files.
- This was to cope with the fact that I wanted to remove the files after use, and couldn't get it to delete itself, and/or get the timing right on deleting them from the app.
This is now working, as required, thank you.
Iain
------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------
Original Message:
Sent: 03-30-2022 09:03
From: Hortion Gilles
Subject: Accessing the windows notifications.
well,
create a notification.bat :
powershell -windowstyle hidden -Command "Add-Type -AssemblyName System.Windows.Forms ; $global:balloon = New-Object System.Windows.Forms.NotifyIcon ;$path = (Get-Process -id $pid).Path;$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning ;$balloon.BalloonTipText = 'What do you think of this balloon tip?';$balloon.BalloonTipTitle = \"Attention $Env:USERNAME\" ;$balloon.Visible = $true ;$balloon.ShowBalloonTip(5000)"
create a notification.vbs file that calls the notification.bat file:
Set WinScriptHost = CreateObject("WScript.Shell")WinScriptHost.Run Chr(34) & "notification.bat" & Chr(34), 0Set WinScriptHost = Nothing
then call notification.vbs:
spawn "notification.vbs"
------------------------------
Hortion Gilles
Agfa-Gevaert NV
Original Message:
Sent: 03-30-2022 07:53
From: Iain Sharp
Subject: Accessing the windows notifications.
Yup, they are working, but they both show big black windows due to the cmd. I've tried /q but I can't see a cmd switch which prevents the window.
Haven't tried the javascript above yet though (more complex setup).
------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
Original Message:
Sent: 03-30-2022 07:40
From: Hortion Gilles
Subject: Accessing the windows notifications.
Hi,
spawn "powershell -Command %%"Add-Type -AssemblyName System.Windows.Forms ; $global:balloon = New-Object System.Windows.Forms.NotifyIcon ;$path = (Get-Process -id $pid).Path;$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning ;$balloon.BalloonTipText = 'What do you think of this balloon tip?';$balloon.BalloonTipTitle = \%%"Attention $Env:USERNAME\%%" ;$balloon.Visible = $true ;$balloon.ShowBalloonTip(5000)%%""
Work also with oscommand by adding cmd /c :
activate "OSCOMMAND".command("cmd /c powershell -Command %%"Add-Type -AssemblyName System.Windows.Forms ; $global:balloon = New-Object System.Windows.Forms.NotifyIcon ;$path = (Get-Process -id $pid).Path;$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning ;$balloon.BalloonTipText = 'What do you think of this balloon tip?';$balloon.BalloonTipTitle = \%%"Attention $Env:USERNAME\%%" ;$balloon.Visible = $true ;$balloon.ShowBalloonTip(5000)%%"")
------------------------------
Hortion Gilles
Agfa-Gevaert NV
Original Message:
Sent: 03-30-2022 07:19
From: Iain Sharp
Subject: Accessing the windows notifications.
Hmm, I put this in the following code into my test form (single command button).
trigger detailvariables string v_sql, v_lineendvariablesdebugv_sql = "powershell -Command %%"Add-Type -AssemblyName System.Windows.Forms ;"v_sql = $concat(v_sql," $global:balloon = New-Object System.Windows.Forms.NotifyIcon ;")v_sql = $concat(v_sql," $path = (Get-Process -id $pid).Path;")v_sql = $concat(v_sql,"$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;")v_sql = $concat(v_sql,"$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning ;")v_sql = $concat(v_sql,"$balloon.BalloonTipText = 'What do you think of this balloon tip?';")v_sql = $concat(v_sql,"$balloon.BalloonTipTitle = 'Attention $Env:USERNAME' ;")v_sql = $concat(v_sql,"$balloon.Visible = $true ;")v_sql = $concat(v_sql,"$balloon.ShowBalloonTip(5000)%%"")activate "SYS_OSCOMMAND".COMMANDOUT(v_sql, v_line)
Which sets v_sql =
powershell -Command "Add-Type -AssemblyName System.Windows.Forms ; $global:balloon = New-Object System.Windows.Forms.NotifyIcon ; $path = (Get-Process -id $pid).Path;$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning ;$balloon.BalloonTipText = 'What do you think of this balloon tip?';$balloon.BalloonTipTitle = 'Attention $Env:USERNAME' ;$balloon.Visible = $true ;$balloon.ShowBalloonTip(5000)"
Running this from the command prompt does the popup. Running it from the OSCOMMAND signature, does nothing, and returns $status=0 and nothing in v_line)
------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
Original Message:
Sent: 03-30-2022 05:57
From: Hortion Gilles
Subject: Accessing the windows notifications.
Hi,
VB script can be replaced by powershell command, and you can find on google many examples like :
powershell -Command "Add-Type -AssemblyName System.Windows.Forms ; $global:balloon = New-Object System.Windows.Forms.NotifyIcon ;$path = (Get-Process -id $pid).Path;$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning ;$balloon.BalloonTipText = 'What do you think of this balloon tip?';$balloon.BalloonTipTitle = \"Attention $Env:USERNAME\" ;$balloon.Visible = $true ;$balloon.ShowBalloonTip(5000)"
You can run this by spawn or oscommand ... it's a bit longer but it works...
ATTENTION : Do not use powershell script, it's block by Windows security...
Gilles .
------------------------------
Hortion Gilles
Agfa-Gevaert NV
Original Message:
Sent: 03-25-2022 08:47
From: Iain Sharp
Subject: Accessing the windows notifications.
Is there a hidden method and/or something on the shared GIT stuff which would allow a uniface component to send a message to the windows notification tray.
We did write a VB dll to access the NotifyIcon class, but access to this has stopped working and my VB expert is on maternity leave.
If there were a standard method, that would be lovely.
Regards,
Iain
------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------