How to show properly a balloontip ?

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
hackoo
Posts: 103
Joined: Sat Jan 22, 2011 12:27 am

How to show properly a balloontip ?

Post by hackoo » Thu Apr 21, 2016 4:01 pm

I'm writing a cleaner for some known virus key like ( "vbs" ,"vbe" ,"wsf", "a3x", "VBScript.Encode" ) from the registry.

I want to add a BalloonTip in powershell with this script but, there is something wrong !

I don't know how to remove the icon from the taskbar to show the progress scan ?

This is a draft. It is not yet optimized !
  1. @echo off
  2.  
  3. Title Hackoo Virus Cleaner to delete virus key from registry by Hackoo 2016
  4.  
  5. Color 1A & Mode con cols=80 lines=8
  6.  
  7. Set Pattern="\.vbs"^
  8.  
  9. ^ "\.vbe"^
  10.  
  11. ^ "\.wsf"^
  12.  
  13. ^ "\.a3x"^
  14.  
  15. ^ "VBScript.Encode"^
  16.  
  17. ^ "\winlogon\.bat"
  18.  
  19.  
  20.  
  21. Set Key="HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"^
  22.  
  23. ^ "HKCU\Software\Microsoft\Windows\CurrentVersion\Run"^
  24.  
  25. ^ "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"^
  26.  
  27. ^ "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"
  28.  
  29.  
  30.  
  31. For %%P in (%Pattern%) Do (
  32.  
  33.         For %%K in (%Key%) Do (    
  34.  
  35.             Cls
  36.  
  37.             echo(
  38.  
  39.             echo(
  40.  
  41.             Echo         ***************************** Scan *****************************
  42.  
  43.             echo             %%K
  44.  
  45.             Echo         ****************************************************************
  46.  
  47.             Call :PS_Sub 'Warning' 10 '" Please wait... "' "' Scan is in progress.... %%K'" 'Warning'
  48.  
  49.             Call :Delete_Virus_Key %%K %%P "%TmpLogFile%"
  50.  
  51.         )
  52.  
  53. )
  54.  
  55. exit /b
  56.  
  57. ::*************************************************************************
  58.  
  59. :Delete_Virus_Key <Key> <Pattern> <LogFile>
  60.  
  61. Setlocal enabledelayedexpansion
  62.  
  63. for /f "delims=REG_SZ" %%I in (
  64.  
  65.     'reg query "%~1" /s^|findstr /ic:"%~2"'
  66.  
  67.     )   Do  (
  68.  
  69.                 If %ErrorLevel% NEQ 1 (
  70.  
  71.                     Set KeyName="%%~I"
  72.  
  73.                     (
  74.  
  75.                         Call:Trim !keyName!
  76.  
  77.                         Title Deleting Run key: !keyName!
  78.  
  79.                         echo Deleting Run key: !keyName!
  80.  
  81.                         echo reg delete "%~1" /v !keyName! /f
  82.  
  83.                         echo(
  84.  
  85.                         echo *****************************
  86.  
  87.                         echo reg delete "%~1" /v "!keyName!" /f
  88.  
  89.                         echo *****************************
  90.  
  91.                         echo(
  92.  
  93.                     )>>"%~3"
  94.  
  95.                     rem Call :PS_Sub 'Warning' 100 '"!KeyName!"' "'Delete !KeyName!'" 'Warning'
  96.  
  97.                 ) else (
  98.  
  99.                     Set KeyName="%%~I"
  100.  
  101.                     Call:Trim !keyName!
  102.  
  103.                     Title Deleting Run key: !keyName!
  104.  
  105.                     echo Deleting Run key: !keyName!
  106.  
  107.                     echo reg delete "%~1" /v !keyName! /f
  108.  
  109.                     echo(
  110.  
  111.                     echo *****************************
  112.  
  113.                     echo reg delete "%~1" /v "!keyName!" /f
  114.  
  115.                     echo *****************************
  116.  
  117.                     echo(
  118.  
  119.                 )>>"%~3"
  120.  
  121.             )      
  122.  
  123. )
  124.  
  125. EndLocal
  126.  
  127. Exit /b
  128.  
  129. ::*************************************************************************
  130.  
  131. :Trim <String>
  132.  
  133. (
  134.  
  135.     echo Wscript.echo Trim("%~1"^)
  136.  
  137. )>"%tmp%\%~n0.vbs"
  138.  
  139. for /f "delims=" %%a in ('Cscript /nologo "%tmp%\%~n0.vbs"') do (
  140.  
  141.     set "KeyName=%%a"
  142.  
  143. )
  144.  
  145. exit /b
  146.  
  147. ::**************************************************************************
  148.  
  149. :PS_Sub $notifyicon $time $title $text $icon
  150.  
  151. PowerShell  ^
  152.  
  153.   [reflection.assembly]::loadwithpartialname('System.Windows.Forms') ^| Out-Null; ^
  154.  
  155.   [reflection.assembly]::loadwithpartialname('System.Drawing') ^| Out-Null; ^
  156.  
  157.   $notify = new-object system.windows.forms.notifyicon; ^
  158.  
  159.   $notify.icon = [System.Drawing.SystemIcons]::%1; ^
  160.  
  161.   $notify.visible = $true; ^
  162.  
  163.   $notify.showballoontip(%2,%3,%4,%5)
  164.  
  165. %End PowerShell%
  166.  
  167. exit /B
  168.  
  169. ::*************************************************************************
So to simplify my issue, we focus just on this function :

What should i add here to get rid the notifyicon from the taskbar ?
  1. ::**************************************************************************
  2.  
  3. :PS_Sub $notifyicon $time $title $text $icon
  4.  
  5. PowerShell  ^
  6.  
  7.   [reflection.assembly]::loadwithpartialname('System.Windows.Forms') ^| Out-Null; ^
  8.  
  9.   [reflection.assembly]::loadwithpartialname('System.Drawing') ^| Out-Null; ^
  10.  
  11.   $notify = new-object system.windows.forms.notifyicon; ^
  12.  
  13.   $notify.icon = [System.Drawing.SystemIcons]::%1; ^
  14.  
  15.   $notify.visible = $true; ^
  16.  
  17.   $notify.showballoontip(%2,%3,%4,%5)
  18.  
  19. %End PowerShell%
  20.  
  21. exit /B
  22.  
  23. ::*************************************************************************

User avatar
jvierra
Posts: 11839
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: How to show properly a balloontip ?

Post by jvierra » Thu Apr 21, 2016 4:11 pm

When PowerShell exits the icon will be removed.

User avatar
hackoo
Posts: 103
Joined: Sat Jan 22, 2011 12:27 am

Re: How to show properly a balloontip ?

Post by hackoo » Thu Apr 21, 2016 4:22 pm

jvierra wrote:When PowerShell exits the icon will be removed.
I saw this http://stackoverflow.com/questions/2179 ... powershell
so how to add this method .Dispose() in my code ?

User avatar
jvierra
Posts: 11839
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: How to show properly a balloontip ?

Post by jvierra » Thu Apr 21, 2016 4:53 pm

When PowerShell exits the balloon tip will be disposed.

User avatar
jvierra
Posts: 11839
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: How to show properly a balloontip ?

Post by jvierra » Thu Apr 21, 2016 5:04 pm

If you are just looking to turn it on and off then just set the "Visible" property to false.

User avatar
jvierra
Posts: 11839
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: How to show properly a balloontip ?

Post by jvierra » Thu Apr 21, 2016 5:09 pm

Do the following at a prompt to see how it works:

.
  1. Add-Type -Assembly System.Windows.Forms
  2.  
  3. $notify = new-object system.windows.forms.notifyicon
  4.  
  5. $notify.icon = [System.Drawing.SystemIcons]::Exclamation
  6.  
  7. $notify.visible = $true
  8.  
  9.  
  10.  
  11. # now just type the following
  12.  
  13. #  $notify.visible = $false

User avatar
hackoo
Posts: 103
Joined: Sat Jan 22, 2011 12:27 am

Re: How to show properly a balloontip ?

Post by hackoo » Thu Apr 21, 2016 5:18 pm

I think i need to pause for a while and use the method .Dispose like that :
  1. ::**************************************************************************
  2.  
  3. :PS_Sub $notifyicon $time $title $text $icon
  4.  
  5. PowerShell  ^
  6.  
  7.   [reflection.assembly]::loadwithpartialname('System.Windows.Forms') ^| Out-Null; ^
  8.  
  9.   [reflection.assembly]::loadwithpartialname('System.Drawing') ^| Out-Null; ^
  10.  
  11.   $notify = new-object system.windows.forms.notifyicon; ^
  12.  
  13.   $notify.icon = [System.Drawing.SystemIcons]::%1; ^
  14.  
  15.   $notify.visible = $true; ^
  16.  
  17.   $notify.showballoontip(%2,%3,%4,%5); ^
  18.  
  19.   Start-Sleep -s 5; ^
  20.  
  21.   $notify.Dispose()
  22.  
  23. %End PowerShell%
  24.  
  25. exit /B
  26.  
  27. ::*************************************************************************
So what do you think ?

Locked