how to modify the VBScript so that it plays sound via Shell command default available player.

I had this question after viewing modifying VBScript to VBA.

i have this great master piece created by Bill and it works with windows 10 that has media player available in it.  however, my machine is domain envi Enterprise Win10 and it does not have windows media player installed the default player is VLC for all type of sound players and it also have grove music player.

is there a possibility to modify the code so that it plays it with default player?

thank you.
LVL 6
FloraAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
Traveling this week but will poke at it a bit next week if you don't get a solution.

~bp
0
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
'
' from Chip Pearson
' http://www.cpearson.com/excel/PlaySound.aspx
'
Public Declare Function sndPlaySound32 _
    Lib "winmm.dll" _
    Alias "sndPlaySoundA" ( _
        ByVal lpszSoundName As String, _
        ByVal uFlags As Long) As Long

'SND_SYNC = &H0
'SND_ASYNC = &H1
'SND_NODEFAULT = &H2
'SND_MEMORY = &H4
'SND_LOOP = &H8
'SND_NOSTOP = &H10

Public Sub API_PlaySound(psFilename As String)
   Call sndPlaySound32(psFilename, &H2 + &H1) 'SND_NODEFAULT + SND_ASYNC
End Sub

Public Sub PlayMySoundFile()  'change name to whatever you want
   Dim sFile As String _
      , sPathFile As String
      
   sPathFile = "c:\path\myFile.wav"                '------- change to name of your file
   If Len(Dir(sPathFile)) > 0 Then
      Call sndPlaySound32(sPathFile, &H2 + &H1) 'SND_NODEFAULT + SND_ASYNC
   End If
   
End Sub

Open in new window

0
FloraAuthor Commented:
Thank you Bill
0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

FloraAuthor Commented:
Crystal

i do not have the slightest idea how to incorporate the code you posted into the code given by Bill. the code below is VBScript encapsulated in hta form.


<html>

<head>

<title>USB Drive Alert</title>

<hta:application
  applicationname="USB Drive Alert"
  id="usbalert"
  border="dialog"
  innerborder="no"
  maximizebutton="no"
  scroll="no"
  version="1.0"/>

<!--Create handler for async event monitoring-->
<object ID="objSink" CLASSID="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223"></object>

<!--Create handler for event handler-->
<script language="vbscript" for="objSink" event="OnObjectReady(objEvent, objContext)">
    Call objSinkOnObjectReady(objEvent, objContext)
</script>

<script language="vbscript">

Sub Window_OnLoad
    ' Size Window, position it
    self.ResizeTo 600, 300
    self.MoveTo 10, 10

    ' Create WMI object to monitor LogicalDisk events
    Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
    strSql = "Select * From __InstanceOperationEvent Within 1 Where TargetInstance isa 'Win32_LogicalDisk'"
    objWMI.ExecNotificationQueryAsync objSink, strSQL
End Sub

Sub ExitButton()
    ' Close window
    window.Close
End Sub

Sub objSinkOnObjectReady(objEvent, objContext)
    Const RemovableDisk = 2

    ' Only interested in removable disk events
    If objEvent.TargetInstance.DriveType = RemovableDisk Then

        ' See what even this is and process if desired
        Select Case objEvent.Path_.Class

            ' Drive added event
            Case "__InstanceCreationEvent"

                ' Display message indicating drive added
                StatusLine "Removable drive " & objEvent.TargetInstance.DeviceId & " has been added."

            ' Drive removed event
            Case "__InstanceDeletionEvent"

                ' Display message indicating drive removed and play alarm sound
                StatusLine "Removable drive " & objEvent.TargetInstance.DeviceId & " has been removed."
                Alarm.play()

        End Select

    End If

End Sub

Sub StatusLine(strText)
    ' Add a line to the text message box
    txtMessages.Value = txtMessages.Value & Now() & " - " & strText & vbCrLf
End Sub

</script>

</head>

<body>

<textarea id="txtMessages" readonly rows="10" cols="60"></textarea>
<p>
<input id="btnExit" style="width: 80px" type="button" value="Exit" name="exit_button" onClick="ExitButton">
<embed id="Alarm" name="Alarm" src=".\siren.wav" loop="false" hidden="true" autostart="false">

</body>

</html>

Open in new window

0
Bill PrewCommented:
Give this change a try, it's not quite as "pretty" as the Media Player approach, but the VLC plugin doesn't play well with IE / HTA usage.  But this should play the WAV file with your default app for it, the only shortcoming is the VLC player will load and be visible when it plays, and remain active after it plays.  But given your use case I'm not sure that is a big problem.

<html>

<head>

<title>USB Drive Alert</title>

<hta:application
  applicationname="USB Drive Alert"
  id="usbalert"
  border="dialog"
  innerborder="no"
  maximizebutton="no"
  scroll="no"
  version="1.0"/>

<!--Create handler for async event monitoring-->
<object ID="objSink" CLASSID="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223"></object>

<!--Create handler for event handler-->
<script language="vbscript" for="objSink" event="OnObjectReady(objEvent, objContext)">
    Call objSinkOnObjectReady(objEvent, objContext)
</script>

<script language="vbscript">

Sub Window_OnLoad
    ' Size Window, position it
    self.ResizeTo 600, 300
    self.MoveTo 10, 10

    ' Create WMI object to monitor LogicalDisk events
    Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
    strSql = "Select * From __InstanceOperationEvent Within 1 Where TargetInstance isa 'Win32_LogicalDisk'"
    objWMI.ExecNotificationQueryAsync objSink, strSQL
End Sub

Sub ExitButton()
    ' Close window
    window.Close
End Sub

Sub objSinkOnObjectReady(objEvent, objContext)
    Const RemovableDisk = 2

    ' Only interested in removable disk events
    If objEvent.TargetInstance.DriveType = RemovableDisk Then

        ' See what even this is and process if desired
        Select Case objEvent.Path_.Class

            ' Drive added event
            Case "__InstanceCreationEvent"

                ' Display message indicating drive added
                StatusLine "Removable drive " & objEvent.TargetInstance.DeviceId & " has been added."

            ' Drive removed event
            Case "__InstanceDeletionEvent"

                ' Display message indicating drive removed and play alarm sound
                StatusLine "Removable drive " & objEvent.TargetInstance.DeviceId & " has been removed."
                CreateObject("WScript.Shell").Run ".\siren.wav", 7

        End Select

    End If

End Sub

Sub StatusLine(strText)
    ' Add a line to the text message box
    txtMessages.Value = txtMessages.Value & Now() & " - " & strText & vbCrLf
End Sub

</script>

</head>

<body>

<textarea id="txtMessages" readonly rows="10" cols="60"></textarea>
<br>
<input id="btnExit" style="width: 80px" type="button" value="Exit" name="exit_button" onClick="ExitButton">

</body>

</html>

Open in new window

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FloraAuthor Commented:
Thank you very much Bill.

it worked like a magic.  very much appreciated.
0
Bill PrewCommented:
Welcome.

~bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 10

From novice to tech pro — start learning today.