Jump to content

running script as service and controling Audio Out.


Tim Net
 Share

Recommended Posts

Hello,

I know how to make a script to play a sound file. I know how to load a script(.exe) as a Windows service. I'd like to have a service which does not require a user to be logged on yet can play music via the audio out jack on a laptop. While this might sound like a streaming app, it needs to run as a service(no user logged in) and is completely local to the single audio out(speakers) jack.

How can I control a sound playing as a service?

Thanks.

Tim

Link to comment
Share on other sites

This is bad for security. When I posted this, I figured that the most direct methods would not work. I figured that there must be some isolation when managing the sound between user mode (me opening Windows Media Player) and SYSTEM services using the _soundplay(). There is not. I added some logging as I expected to try and figure out why the sound file was not playing.

I wrote a very small sound.au3 which just plays a filly pathed .mp3.

#include <Sound.au3>

$sound=_SoundOpen("D:\scripts\AutoIT\Audio\Do you hear what I hear.mp3")

while 1

FileWriteline("D:\scripts\AutoIT\Audio\Activity.log",@hour & ":" & @min & ":" & @SEC & ",Start" )

$play = _SoundPlay($sound,0)

FileWriteline("D:\scripts\AutoIT\Audio\Activity.log",@hour & ":" & @min & ":" & @SEC & "," & $play )

sleep(10000)

$stop = _SoundStop($sound)

FileWriteline("D:\scripts\AutoIT\Audio\Activity.log",@hour & ":" & @min & ":" & @SEC & "," & $stop )

WEnd

_SoundClose($sound)

Compiled it and ran it in my session. No probem, I hear it.

I then added an AT job to run the sound.exe via the scheduler under the SYSTEM account. 45 seconds later when the clock turned, the sound plays!

at 5:49 D:\scripts\AutoIT\Audio\Sound.exe

I then used inetsrv and srvany to load the sound.exe as a service called 'Sound'. Running as SYSTEM again, it played the music.

@echo off

cd /d "%~dp0"

instsrv.exe Sound "%~dp0srvany.exe"

reg add HKLM\SYSTEM\CurrentControlSet\Services\Sound\Parameters

reg add HKLM\SYSTEM\CurrentControlSet\Services\Sound\Parameters /t REG_SZ /v Application /d "%~dp0Sound.exe"

net start Sound

I am perplexed that this is possible. Problem solved.

Tim

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...