Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: .VBS file that play sound. I don't know how to stop it  (Read 7859 times)

0 Members and 1 Guest are viewing this topic.

malecos

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Windows 7
    .VBS file that play sound. I don't know how to stop it
    « on: August 12, 2014, 09:09:40 PM »
    Hello, sorry for my poor english.
    Sorry if this is not the right place to post about VBscript.

    I have the following code, that play a sound without openning any player. The code repeats the sound in loop.
    I don't know how to stop the sound. The only way to stop is "kill" the wscript.exe in windows task manager.
    How can I add a messagebox with an "OK" button to stop the sound ?


    Thanks!

    Set Sound = CreateObject("WMPlayer.OCX.7")
    Sound.URL = "c:\windows\media\notify.wav"
    nada = 1
    do while nada = 1
    wscript.sleep 100
    Sound.Controls.play
    loop
    wscript.sleep (int(Sound.currentmedia.duration)+1)*1000

    malecos

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Windows 7
      Re: .VBS file that play sound. I don't know how to stop it
      « Reply #1 on: August 13, 2014, 08:59:13 AM »
      Solved!

      Added commands in the first .vbs file to call another .vbs file. This another .vbs file displays a popup on the screen with an only "OK" button. When "ok" button is pressed, the rest of code kill the wscript.exe application.

      'This was added in first .vbs file to call the second .vbs file:

      Dim objShell
      Set objShell = Wscript.CreateObject("WScript.Shell")
      objShell.Run "inter.vbs"   
      Set objShell = Nothing

      'This is added in second .vbs file to display message and then kill the wscript.exe after "ok" button is pressed:

      x=msgbox ("Message", 0+16+4096, "Tittle")

      strComputer = "."
      strProcess = "'wscript.exe'"
      Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" _
      & strComputer & "\root\cimv2")
      Set colProcess = objWMIService.ExecQuery _
      ("Select * from Win32_Process Where Name = " & strProcess )

      For Each objProcess in colProcess
         objProcess.Terminate()
      Next

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: .VBS file that play sound. I don't know how to stop it
      « Reply #2 on: August 13, 2014, 09:40:16 AM »
      Seems like it would have been easier to break the loop by Opening a message box and then setting the NADA variable to 0 if they click OK.