任务栏上的图标批消息 [英] Batch icon message on task bar
问题描述
是否有可能做一个批处理,或者.VBS如果需要的话,是有可能使一批有一个小图标那里的标志,电池和音量。
Is it possible to make a Batch, or .vbs if needed, is it possible to make batch have a little icon down there with the flag, battery and volume.
我想这是一个为xx分钟关机/小时,并点击mayyybbe在取消'吧。
I want it to be a "Shutting down in xx minutes/hours", and mayyybbe clicking it cancels' it.
在此先感谢:)
推荐答案
嗯,我知道如何完成你想要的东西的一部分 - 从PowerShell的借款制作系统托盘气球提示。但我不知道如何使它监听气球的解雇。也许别人能在矿提供了另一种答案建设呢?
Well, I know how to accomplish part of what you want -- making a systray balloon tip by borrowing from PowerShell. But I don't know how to make it listen for dismissal of the balloon. Maybe someone else can offer another answer building upon mine?
不管怎样,我用这一个转换脚本我做出后手转换成MP3批量。随意破解它为自己的邪恶目的。
Anyway, I use this for a conversion script I made to convert flac to mp3 in batches. Feel free to hack it for your own 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's 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 的在 $ o.ShowBalloonTip值(
的 N 1 的)
和启动睡眠-M
的 N 2 的以毫秒为单位。盐适量。
The n values in $o.ShowBalloonTip(
n1)
and Start-Sleep -M
n2 are in milliseconds. Salt to taste.
更新:我搜了一下关于注册事件的 $ o.BalloonTipClicked
以及一个的在野外可爱的例子。基本上,替换此:
Update: I found a bit about registering an event for $o.BalloonTipClicked
as well as a lovely 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
您还需要在单线程执行的PowerShell
事件工作。
You also need to execute powershell
in a single threaded apartment for the event to work.
start /b "" "powershell" -STA %code%
现在,你需要弄清楚如何使相关的回批生产过程的情况下。对于一件事,你可能不再能够使用启动/ B
来使气球提示无阻塞,你可能会使用一个 FOR / F
循环捕捉的PowerShell的输出
命令。
Now, you need to figure out how to make that relevant back in the context of your batch process. For one thing, you'd probably no longer be able to use start /b
to make the balloon tip non-blocking, and you'd probably use a for /F
loop to capture the output of the powershell
command.
添加到您的后顾之忧,我建议,在XX分钟关闭下来并不完全是用户友好。如果什么?在30分钟内关闭出现了28分钟前,但用户刚才看到了吗? 在上午09时51分关闭可能会更好。
Adding to your worries, I propose that "Shutting down in xx minutes" is not entirely user-friendly. What if "Shutting down in 30 minutes" appeared 29 minutes ago, but the user just now saw it? "Shutting down at 9:51 AM" might be better.
所以,这一切想法,因为你要的是事件驱动的,因为批处理语言不处理日期 - 时间到数学很容易,我建议做了整个该死的东西在PowerShell中。以的.ps1
延长保存此。右键单击并使用PowerShell运行。或者,如果你想从 CMD
控制台执行它,做 PowerShell的。\\ scriptname.ps1
。
So with all this in mind, since what you want is event driven and since the batch language doesn't handle date-time math all that easily, I suggest doing the whole damn thing in PowerShell. Save this with a .ps1
extension. Right-click and run with PowerShell. Or if you want to execute it from a 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,如果你正在读这篇文章,我知道你很高兴。碰巧的是,PowerShell是确实是工作这一次正确的工具。
Bill_Stewart, if you're reading this, I know you're pleased. As it happens, PowerShell is indeed the correct tool for the job this time.
这篇关于任务栏上的图标批消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!