8

I want to detect if PC is playing any kind of sound.


if it isn't playing any kind of sound I can use else condition in Powershell and do whatever I need to do next.

So is there anyway to detect sound via PowerShell?

Thanks

Mowgli
  • 3,422
  • 21
  • 64
  • 88
  • 1
    Possible duplicate of [Determine if windows is currently playing sound](https://stackoverflow.com/questions/45422255/determine-if-windows-is-currently-playing-sound) – Persistent13 Aug 07 '17 at 19:03

2 Answers2

2

method 1...

Import-Module -Name TroubleShootingPack
Get-TroubleshootingPack C:\Windows\diagnostics\system\Audio | Invoke-TroubleshootingPack

method 2... start to reverse engineer the scripts in C:\Windows\diagnostics\system\Audio :)

P.S: You can also read in shay's blog about how to do your specific task http://scriptolog.blogspot.co.il/2007/09/playing-sounds-in-powershell.html

OhadH
  • 156
  • 1
  • 9
-1

You're going to need to import a .net type or dll. Admittedly, the process is hit or miss and some google searching didn't turn up much, but this is the only way you'll possibly find this sort of functionality. I would suggest search through msdn documentation for .Net for something to do the job.

Once you know what class you need:

Add-Type System.Example

Or

Add-Type -Path "C:\PathtoDll\file.dll"

Then you need to either call a static method

[System.Example]::DoSomething() 

Or create a new instance of the object

$object = New-Object System.Example
Joel Smith
  • 857
  • 9
  • 20
  • 1
    I agree that this will likely be part of the process but it doesn't actually answer the OPs question, it should have been a comment. To explain my downvote further - people use the answer counts to determine whether to read a question at all, so by giving partial answers you make it less likely that someone with the real answer will see this. – George Mauer Jun 28 '13 at 16:45
  • I spent like three hours on it and couldn't find a solution so this is the best I can do – Joel Smith Jun 29 '13 at 00:36
  • 1
    I understand and nothing against your impulse to do research and try to answer the question, that's totally what the community is all about. However, placing this in the answers section decreases the likelihood of the OP (and the rest of us) getting a definitive answer so it's better avoided. As an aside, it's likely if there's no .Net api that the answer lies somewhere within the depths of COM and the winapi. – George Mauer Jun 29 '13 at 18:02
  • 1
    I'm pointing him in the right direction. Much better than anyone else is doing, no one has replied to this for two weeks – Joel Smith Jun 29 '13 at 18:11
  • 1
    Right, and that's awesome and encouraged, I'm saying that it should be done as a comment rather than an answer. – George Mauer Jun 29 '13 at 18:26