显示批处理文件中的气球通知 [英] Show balloon notifications from batch file

查看:111
本文介绍了显示批处理文件中的气球通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示长时间运行的批次中的气球通知.

I would like to show balloon notifications from batches that run during long time.

我知道您可以显示弹出窗口(某些解决方案非常富于想象力),但是拥有此功能将很有趣选项.

I know you can show popups (and some solutions are very imaginative), but it would be interesting to have this option too.

有没有一种方法可以显示批处理文件中的气球通知?至少请从Windows 7开始,但也欢迎XP.

Is there a way you can show a balloon notification from a batch file? Starting from Windows 7 at least please but XP welcome too.

我想至少需要一个托盘图标,但是坦率地说,我不能走得更远.也许使用 rundll32.exe ?我知道这不是从命令行执行任何操作的推荐方法.

I suppose it would necessary at least a tray icon but frankly I cannot go much farther. Maybe with rundll32.exe? I know this is not a recommended way to do anything from command line.

rundll32.exe调用的函数所需的函数签名在此知识库中记录文章.这并没有阻止人们使用rundll32来调用随机不是由rundll32调用的函数,类似于user32LockWorkStation user32退出WindowsEx .

The function signature required for functions called by rundll32.exe is documented in this Knowledge Base article. That hasn't stopped people from using rundll32 to call random functions that weren't designed to be called by rundll32, like user32 LockWorkStation or user32 ExitWindowsEx.

但是我发现了这个 RunAnyDll实用程序通过 Yaniv Pessach 似乎可以正确调用.dll.不幸的是,我发现没有可测试的链接(不,它不在Internet存档中).我已经写了作者要他请一位.让我们看看.

But I found this RunAnyDll utility by Yaniv Pessach that appears to make the .dll calls right. Unfortunately, I found not a working link to test it (no, it isn't in the Internet archive). I've written the author to ask him for one. Let's see.

(我什至不知道它是否有用,但这是一个有趣的实用程序.也许它可以使此答案 Run 框和命令行执行之间的区别与Raymond Chen帖子中的调用约定有关.)

(I don't even know if it will be useful but it's an interesting utility. Maybe it could make work this answer to the popup question. I think the difference between the Run box and the command line execution has something to do with the calling convention thing in Raymond Chen post.)

另一个无法测试的实用程序是已弃用的 eventtriggers,但是我不确定是否有帮助.

Another unfindable utility to test is the deprecated eventtriggers but again I'm not sure if it would be of help.

npocmaka greg zakharov 的答案都非常有趣. npocmaka 的那个离我要问的更近了,因为它会产生气球通知. greg zakharov 使用了不同的技术,但其结果非常相似(在这种情况下,文本出现在鼠标指针的位置).我已经在XP中测试了它们,并且两者都可以工作(安装了.NET).两者都有超时,我不知道如何保留通知,直到用户单击为止(以防万一用户不在,但您想看到它).

Both npocmaka and greg zakharov answers are very interesting. npocmaka's one is nearer to what I was asking because it produces a balloon notification. greg zakharov's uses a diferent technique but its outcome is very similar (in this case a text appearing at mouse pointer location). I've tested them in XP and both work (with .NET installed). Both have a timeout and I don't know how to keep the notification until the user clicks (just in case the user is out but you want to see it).

理想情况下,我的问题是要得到这样的东西.

Ideally, my question was about getting something like this.

@echo off

echo Some long part job that goes well.

call :balloon "Report about above tasks" [optional parameters about icon, title, timeout, etc.]

echo More tasks but one fails
if errorlevel 1 call :balloon "Error this and that" [optional parameters]

echo This is the end of the tasks
goto :eof

:balloon

    echo If you don't want to make a temporary file
    echo then you must make one-liner calls to PowerShell, wscript or whatever.

exit /b

因此,作为混合脚本,我看到的缺点是,很难将其插入任何批处理中.如果您要在批处理中重复使用多次,则为每个气球生成一个 .exe 似乎是不切实际的,因此最终,如 greg zakharov 所述,它更加健壮和灵活生成仅接受参数并重复使用的.exe(就像 notifu ).最后,我想使用一个进行单行Powershell调用的:balloon 子例程是您可以获得的最佳选择(几乎在XP中是本机的,因为您需要下载但还需要.net)

So being hybrid scripts the drawback I see is that it must be very difficult to insert this inside any batch. Generating an .exe for every balloon seems impracticable if you are going to reuse several times in your batch so, in the end, as greg zakharov states, it's more robust and flexible to generate just an .exe that accept parameters and reuse it (just as notifu). In the end, I suppose that using a :balloon subroutine that makes a one-liner powershell call is the best you can get (almost natively in XP because you need a download but you also need .net).

推荐答案

使用PowerShell一线式

无需创建文件,无论执行策略是什么,它都可以工作.感谢 Mark Dodsons 向我们展示了使用PS进行操作并npocmaka (图标列表).

另存为例如 balloon.bat (当然,您可以将其作为子例程插入到任何批处理中).

Save as, for example, balloon.bat (of course, you can insert this as subroutine in any batch).

@echo off

if "%~1"=="" call :printhelp  & exit /b 1
setlocal

if "%~2"=="" (set Icon=Information) else (set Icon=%2)
powershell -Command "[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); $objNotifyIcon=New-Object System.Windows.Forms.NotifyIcon; $objNotifyIcon.BalloonTipText='%~1'; $objNotifyIcon.Icon=[system.drawing.systemicons]::%Icon%; $objNotifyIcon.BalloonTipTitle='%~3'; $objNotifyIcon.BalloonTipIcon='None'; $objNotifyIcon.Visible=$True; $objNotifyIcon.ShowBalloonTip(5000);"

endlocal
goto :eof

:printhelp
echo USAGE: %~n0 Text [Icon [Title]]
echo Icon can be: Application, Asterisk, Error, Exclamation, Hand, Information, Question, Shield, Warning or WinLogo
exit /b

如果没有第二个参数,则默认为 Information .

If there's no second parameter it defaults to Information.

我想您可以使用 mshta 和vbscript或javascript,但是到目前为止我还没有成功.

I suppose you can use mshta and vbscript or javascript, but I had no success until now.

这篇关于显示批处理文件中的气球通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆