Taskbar Batch Message

Is it possible to make a package, or .vbs, if necessary, it is possible for the package to have a small icon there with a flag, battery and volume.

I want it to be "Completion in xx minutes / hours", and mayyybbe clicked it to cancel it.

Thank you in advance:)

+1
source share
1 answer

Well, I know how to accomplish some of what you want - creating the tip of a balloon using borrowing from PowerShell. But I don’t know how to make him listen to the balloon being fired. Maybe someone else can offer another answer building to mine?

Anyway, I use this to convert the script that I did to convert flac to mp3 in batches. Feel free to hack it for your evil purposes.

@echo off setlocal for %%I in (*.flac) do ( rem // This initiates the systray balloon. call :systray converting from "%%~nxI" to "%%~nI.mp3" ) goto :EOF rem // Here the :systray function :systray <message> setlocal enabledelayedexpansion set "args=%*" set "args=!args:'=''!" set "code="[void] [Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');^ $o=New-Object Windows.Forms.NotifyIcon;$o.Icon='%systemroot%\System32\PerfCenterCpl.ico';^ $o.BalloonTipIcon='Info';$o.BalloonTipText='!args!';$o.BalloonTipTitle='%~nx0';$o.Visible=1;^ $o.ShowBalloonTip(10000);Start-Sleep -M 12000;$o.Dispose();Exit"" start /b "" "powershell" %code% endlocal & goto :EOF 

n values ​​in $o.ShowBalloonTip( n 1 ) and Start-Sleep -M n 2 are in milliseconds. Salt to taste.


Update: I learned a little about event registration for $o.BalloonTipClicked , as well as a great example in the wild . Basically replace this:

 $o.ShowBalloonTip(10000);Start-Sleep -M 12000;$o.Dispose();Exit 

... with this:

 $o.ShowBalloonTip(10000);register-objectevent $o BalloonTipClicked clicked;^ if (wait-event clicked -t 12) {$true} else {$false}; $o.Dispose(); Exit 

You also need to execute powershell in one multi-threaded apartment for the event to work.

 start /b "" "powershell" -STA %code% 

Now you need to figure out how to make this relevant in the context of your batch process. First, you probably can no longer use start /b to make the spherical tip non-blocking, and you probably use the for /F loop to capture the output of the powershell command.

Adding to your concerns, I suggest that "Shutting down in xx minutes" is not entirely user friendly. What if Shutdown After 30 Minutes appeared 29 minutes ago, but the user just saw it? "Shutdown at 9:51 a.m." could be better.

So, with all of this in mind, since what you want is event driven, and since the batch language doesn’t cope with math with date, all this is easy, I suggest doing the whole damn thing in PowerShell. Save this with the .ps1 extension. Right-click and launch using PowerShell. Or, if you want to execute it from the cmd console, do powershell ".\scriptname.ps1" .

 set-executionpolicy remotesigned if ([threading.thread]::CurrentThread.GetApartmentState() -eq "MTA") { & powershell.exe -window minimized -sta $MyInvocation.MyCommand.Definition exit } [void] [Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') $minutes = 30 $launch_time = (Get-Date).AddMinutes($minutes).ToShortTimeString() $o = New-Object Windows.Forms.NotifyIcon $o.Icon = "$env:SystemRoot\System32\PerfCenterCpl.ico" $o.BalloonTipIcon = "Info" $o.BalloonTipText = "Shutting down at $launch_time" $o.BalloonTipTitle = "Shutdown pending..." $o.Visible = 1 function show-balloon { $o.ShowBalloonTip($minutes * 60 * 1000) } show-balloon $o_hover = [Windows.Forms.MouseEventHandler]{ show-balloon } $o.add_MouseMove($o_hover) register-objectevent $o BalloonTipClicked clicked if (wait-event clicked -t ($minutes * 60)) { remove-event clicked $o.BalloonTipText = "Have a nice day!" $o.BalloonTipTitle = "Shutdown aborted" $o.ShowBalloonTip(10000) if (wait-event clicked -t 10) { remove-event clicked } } else { # Initiate shutdown sequence on my mark. Authorization rojo alpha 3. Mark. stop-computer } unregister-event clicked $o.Dispose() 

Bill_Stewart, if you read this, I know that you are satisfied. As it happens, PowerShell is currently the right tool for the job.

+4
source

Source: https://habr.com/ru/post/1247661/


All Articles