Harrod200

Alarm Clock

Aug 18th, 2015
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'URL of internet radio source
  2. strURL = "http://www.bbc.co.uk/radio/player/bbc_radio_two"
  3. 'URL of offline audio file
  4. strMP3 = "C:\Windows\Media\Alarm02.wav"
  5. 'Time in Mins
  6. intWait = 59
  7. 'WLAN Profile Name
  8. strWLANProf = "Bob"
  9. 'Volume to run at (%)
  10. intVolMax = 65
  11.  
  12. set objShell = createobject("wscript.shell")
  13.  
  14. 'Set system volume to 0, but unmuted
  15. objshell.run "nircmd setsysvolume 0"
  16. objshell.run "nircmd mutesysvolume 0"
  17.  
  18. intStopMinute = minute(now) + intWait
  19. if intStopMinute >= 60 then intStopMinute = intStopMinute - 60
  20.  
  21. 'Reset WLAN (try to fix that annoying issue)
  22. objshell.run "cmd.exe /C " & chr(34) & "netsh wlan disconnect" & chr(34),0,true
  23. wscript.sleep 2000
  24. objshell.run "cmd.exe /C " & chr(34) & "netsh wlan connect " & strWLANProf & chr(34),0,true
  25. wscript.sleep 10000
  26.  
  27. 'Find out if we're online
  28. boolOnline = Ping("8.8.8.8")
  29. 'boolonline = false
  30.  
  31. 'Online = internet radio, offline = mp3
  32. if boolOnline = true then
  33.    
  34.     'Create an instance of IE (because it's VB-able), open the internet radio URL
  35.     Set objIE = CreateObject("InternetExplorer.Application")
  36.     objIE.navigate strURL
  37.     objIE.visible = 1
  38.  
  39.     'Wait a while to give it time to load the stream
  40.     wscript.sleep 30000
  41.  
  42.     'Gradually increase volume to the limit
  43.     intPercent = 0
  44.     do while not intPercent = intVolMax
  45.         intPercent = intPercent + 1
  46.         intVol = (65535 / 100) * intPercent
  47.         objshell.run "nircmd setsysvolume " & intVol
  48.         wscript.sleep 150
  49.     loop
  50.  
  51.     'Wait for the length of the alarm
  52.     do while not minute(now) = intStopMinute
  53.         wscript.sleep 60000
  54.     loop
  55.  
  56.    
  57.     'Close IE
  58.     objIE.quit
  59. else
  60.     'Set volume to the maximum set
  61.     intVol = (65535 / 100) * intVolMax
  62.     objshell.run "nircmd setsysvolume " & intVol
  63.  
  64.     'Wait a minute
  65.     wscript.sleep 60000
  66.    
  67.     'Load media player
  68.     Set objWMP = createobject("wmplayer.ocx.7")
  69.     intStop = 0
  70.    
  71.     'Keep playing the mp3, over and over again
  72.     objWMP.url = strMP3
  73.     do while intStop <> 1
  74.         if objwmp.playstate = 1 then
  75.             objWMP.url = strMP3
  76.         elseif objwmp.playstate = 9 then
  77.             intStop = objshell.popup("Stop?",1,"Alarm Clock",&H20 + &H2000)
  78.         end if
  79.  
  80.         if minute(now) = intStopMinute then intStop = 1
  81.     loop
  82. end if
  83.  
  84. 'Googled ping function
  85. Function Ping(strHost)
  86.     Dim objSh, strCommand, intWindowStyle, blnWaitOnReturn
  87.  
  88.     blnWaitOnReturn = True
  89.     intWindowStyle = 0
  90.     strCommand = "%ComSpec% /C %SystemRoot%\system32\ping.exe -n 1 " _
  91.     & strHost & " | " & "%SystemRoot%\system32\find.exe /i " _
  92.     & Chr(34) & "TTL=" & Chr(34)
  93.  
  94.     Set objSh = WScript.CreateObject("WScript.Shell")
  95.     Ping = Not CBool(objSh.Run(strCommand, intWindowStyle, blnWaitOnReturn))
  96.     Set objSh = Nothing
  97. End Function
Advertisement
Add Comment
Please, Sign In to add comment