Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xp_cmdshell run wave file 5

Status
Not open for further replies.

JeffAlton

Programmer
Apr 19, 2003
42
0
0
US
I am using SQL Express(2005)
I have a visual basic script that plays a wave file when executed. I have tried to call this script using the following:

exec xp_cmdshell 'C:\AIRRAID.VBS'

It seems to execute ok and returns a null in output but the wave file does not play. When the script is executed from the cmd prompt it plays fine.

 
SQL Server is not a toy. Stop trying to treat it as such. If you want bells and whistles, use Access or some other crappy little database. If you want enterprise class performance, stability, and reliability, use SQL Server.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
The wav does play. You can probably even confirm this by watching CPU cycles. But what speakers are you expecting the sound to come out of?

Any command executed for a user will only apply for that user. If you have 29 people connected to a terminal server and one of them generastes a sound, that sound doesn't play for all 29 people. The reason is because the sound only exists in the context of the user.

So when you're connected to a server and you run the xp_cmdshell command, what is the user context of that command? Hint: it isn't your session. It is the user that the database engine is running under. When you disconnect your session, the database is still running, so it can't be your user. Do this:

Code:
exec master.dbo.xp_cmdshell 'set username'
See how it's not the user you connected to the database with? Or if it is, it's not the same session. Connect to the database with a different user and try again. Now you'll see they are different.

A virtual user that has no "front end" has no speakers just like it has no screen. It's not logged in to the console, it is a "virtual session," and it's not going to play the sound for that session in another session, be it the console session or otherwise. Nor is the sound going to play on your local machine over your database connection library somehow.

There are many different users on a windows machine: local system, for example. This user can never display GUI elements because it has no GUI associated with it. Maybe this will illustrate the problem well:

Code:
exec master.dbo.xp_cmdshell 'c:'
exec master.dbo.xp_cmdshell 'cd \'
exec master.dbo.xp_cmdshell 'echo msgbox "test" > m.vbs'
exec master.dbo.xp_cmdshell 'cscript m.vbs'
exec master.dbo.xp_cmdshell 'del m.vbs'
No one will ever see a popup. Where would it display? There is no context for such a thing. The system might be smart enough to not allow GUI elements in a session that has no connected "desktop" so to speak. However, if the msgbox thing DOES work it could hang your SQL server while it waits for someone to click "OK" on a graphical element that no one can access and wasn't rendered on any screen. The problem with where the sound is to play is identical.

[COLOR=black #e0e0e0]For SQL and technical ideas, visit my blog, Squared Thoughts.

[sub]The best part about anything that has cheese is the cheese.[/sub][/color]
 
The place to put flashy things which will make your users clap their hands with glee is in the GUI, not your database.

 
Try running it while you are sitting next to the server. I suspect you might hear it then!
 
Try running it while you are sitting next to the server. I suspect you might hear it then!
I'll eat a napkin if playing that wav makes an audible sound at the server.
 
old man said:
If you want enterprise class performance, stability, and reliability, use SQL Server.

Better yet, Oracle or DB2. SQL-server is for smaller enterprises. ;-)

ANd what's wrong with a bit of music in the serverroom?

Christiaan Baes
Belgium

My Blog
 
ANd what's wrong with a bit of music in the serverroom?
Ah yes, you can't beat that "AIRRAID" music all day [wink]

You also forgot to mention Excel...


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
you forgot another one chrissie. this looks about right:

Code:
[COLOR=blue]select[/color] top 5 dbserver_name 
[COLOR=blue]from[/color] dbservers 
[COLOR=blue]order[/color] [COLOR=blue]by[/color] greatness [COLOR=#FF00FF]desc[/color]

dbserver_name
-------------
Excel
Access
DB2
Oracle
SQL Server

(5 row(s) affected)

That should be about right.

[small]----signature below----[/small]
Majority rule don't work in mental institutions

My Crummy Web Page
 
those might have a shot at making the top 10. Especially notepad.

[small]----signature below----[/small]
Majority rule don't work in mental institutions

My Crummy Web Page
 
Paper. Definitely paper. I did pick an object that I could get down in the event that I proved to be incorrect. :)

run this on your production web site. I dare you.

Code:
print @@spid
GO
exec master.dbo.xp_cmdshell 'echo msgbox "hello" > c:\eraseme.vbs'
exec master.dbo.xp_cmdshell 'cscript.exe c:\eraseme.vbs'
exec master.dbo.xp_cmdshell 'del c:\eraseme.vbs'
Now try to kill that session. Have fun.

DBCC inputbuffer(<the spid that was printed above>)

this proves you have the right spid, or if you need to find it do select * from master.dbo.sysprocesses. Now try to kill it.

kill <the spid>

I wonder why you can't?!?!? How weird.

Just like there is no screen for anyone to click OK on in the example above (and no pointer, and no input device to move the pointer), when playing a wav file through xp_cmdshell, there are no speakers for making sound.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top