Guest User

AlarmClock

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