在Windows服务中播放默认Windows声音 [英] play default Windows sounds in Windows Service

查看:393
本文介绍了在Windows服务中播放默认Windows声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS2010的VB.net中开发Windows服务



在某些情况下,我想播放用户通知的系统默认声音。



我曾尝试使用代码播放声音,但它没有播放任何声音。



I am developing windows service in VB.net in VS2010

In some case I want to play system default sound for user notification.

I had tried following code to play sound but it''s not playing any sound.

System.Media.SystemSounds.Question.Play()







 'I checked by attaching debug that the path is correct
My.Computer.Audio.Play(Path.Combine(My.Application.Info.DirectoryPath, "Blip.wav"), AudioPlayMode.Background)







My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Question)







即使我使用InstallUtil安装服务后检查服务属性中的允许与桌面交互复选框



我检查了与我的电脑连接的扬声器。



我在win xp中测试了它并赢了7



请帮我解决这个问题并让我知道我哪里错了。



谢谢




Even I checked the check box of "Allow to interact with desktop" in service properties after installing service using "InstallUtil"

I checked the speaker connected with my pc.

I have tested it in win xp and win 7

Please help me to resolved this issue and let me know where I am going wrong.

Thanks

推荐答案

我认为你不能从服务中播放声音。至少,我从来没有听说过有声播放过的单一服务。这总是留给用户模式的应用程序,该应用程序与服务对话并通过命名管道或其他一些通信方法接收来自它的通知。
I don''t think you can play sounds from a service. At least, I''ve never heard of a single service ever playing a sound. That was always left up to a user-mode application that talks to the service and receives notifications from it, via named pipes or some other communication method.


我成功使用此链接 http://bresleveloper.blogspot.co.il/2012/06/c -service-play-sound-with-naudio.html [ ^ ]即使用户尚未登录该服务也会播放声音。
I succeed with this link http://bresleveloper.blogspot.co.il/2012/06/c-service-play-sound-with-naudio.html[^] even if user has not logged in the service will play sound.


这篇关于在Windows服务中播放默认Windows声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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