[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[原创] VBS 调用API函数Beep唱一曲《周杰伦-回到过去》

半原创,很多代码参考了百度VBS贴吧。
  1. Option Explicit
  2. ' 获取 Excel 对象
  3. Dim oExcel, oBook
  4. Set oExcel = Excel_Init
  5. Set oBook = oExcel.ActiveWorkbook
  6. '提示非台式机用户选择是否继续
  7. If LCase(ChassisType()) <> LCase("Desktop") Then
  8.   If CreateObject("WScript.Shell").Popup(_
  9.     "你的电脑不是台式机(桌面计算机),将会导致扬声器发出较大的噪声,请注意调小音量!" & VbCrLf & VbCrLf & _
  10.     "退出程序,请按“确定”,否则请按“取消”。(7秒后自动取消)", 7, "警告", 48+4096+1) = 1 Then
  11.     WScript.Quit
  12.   End If
  13. End If
  14. '内存报警实例
  15. CreateObject("WScript.Shell").Popup "稍等2秒,即将播放BIOS内存报警声……   " , 2, "提示", 64+4096+0
  16. Beep 880, 600: Sleep 200  '內存
  17. Beep 880, 200: Sleep 200
  18. Beep 880, 200: Sleep 200
  19. '//do~si 节奏数据来自VBS吧
  20. CreateObject("WScript.Shell").Popup "稍等2秒,即将播放so~si音阶……     " , 2, "提示", 64+4096+0
  21. playsnd 440, 100
  22. playsnd 494, 100
  23. playsnd 554, 100
  24. playsnd 622, 100
  25. playsnd 698, 100
  26. playsnd 784, 100
  27. playsnd 880, 100
  28. '//周杰伦的回到过去 节奏数据来自VBS吧
  29. CreateObject("WScript.Shell").Popup "稍等2秒,即将播放《周杰伦-回到过去》……" , 2, "提示", 64+4096+0
  30. playsnd 587, 100: playsnd 784, 100: playsnd 880, 100: playsnd 988, 100:: playsnd 988, 200: playsnd 0, 100
  31. playsnd 988, 100: playsnd 880, 100: playsnd 988, 100: playsnd 1047, 200: playsnd 988, 100: playsnd 988, 100
  32. playsnd 880, 100: playsnd 100, 150: playsnd 880, 100: playsnd 784, 100:: playsnd 988, 100: playsnd 0, (5)
  33. playsnd 988, 100: playsnd 0, (5)::: playsnd 988, 100: playsnd 0, (5):::: playsnd 988, 100: playsnd 880, 100
  34. playsnd 784, 100: playsnd 740, 100: playsnd 784, 200: playsnd 100, 200:: playsnd 784, 100: playsnd 880, 100
  35. playsnd 784, 100: playsnd 988, 100: playsnd 0, (5)::: playsnd 988, 100:: playsnd 0, (5)::: playsnd 988, 100
  36. playsnd 0, (5)::: playsnd 988, 100: playsnd 100, 100: playsnd 587, 100:: playsnd 784, 100: playsnd 1175, 100
  37. playsnd 0, (5)::: playsnd 1175, 99: playsnd 988, 100: playsnd 0, (5):::: playsnd 988, 100: playsnd 0, (5)
  38. playsnd 987, 100: playsnd 100, 100: playsnd 784, 100: playsnd 0, (5):::: playsnd 784, 100: playsnd 880, 200
  39. playsnd 784, 100: playsnd 0, (5)::: playsnd 784, 100: playsnd 0, (5):::: playsnd 784, 50:: playsnd 659, (50)
  40. playsnd 784, 100: playsnd 659, 100: playsnd 784, 100: playsnd 880, 100:: playsnd 100, 100: playsnd 587, 110
  41. playsnd 784, 120: playsnd 880, 130: playsnd 740, 140: playsnd 784, 200:: playsnd 1, 1::::: playsnd 1, 1
  42. ' 关闭 Excel
  43. Excel_Quit
  44. WScript.Quit
  45. Function Excel_Init()
  46.   Dim WshShell
  47.   Dim oExcel, oBook, oModule
  48.   Dim strRegKey, strCode
  49.   Set oExcel = CreateObject("Excel.Application")
  50.   set WshShell = CreateObject("WScript.Shell")
  51.   strRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\$\Excel\Security\AccessVBOM"
  52.   strRegKey = Replace(strRegKey, "$", oExcel.Version)
  53.   WshShell.RegWrite strRegKey, 1, "REG_DWORD"
  54.   Set oBook = oExcel.Workbooks.Add
  55.   Set oModule = obook.VBProject.VBComponents.Add(1)
  56.   strCode = _
  57.   "Declare Sub Beep Lib ""kernel32"" (ByVal fre As Long, ByVal ms As Long)" & vbCr & _
  58.   "Declare Sub Sleep Lib ""kernel32"" (ByVal ms As Long)"
  59.   oModule.CodeModule.AddFromString strCode
  60.   Set Excel_Init = oExcel
  61. End Function
  62. Function playsnd(ByVal x, ByVal y)
  63.   Beep x, y * 3
  64. End Function
  65. Sub Beep(fre,ms)
  66.   oExcel.Run "Beep",fre,ms
  67. End Sub
  68. Sub Sleep(ms)
  69.   oExcel.Run "Sleep",ms
  70. End Sub
  71. Function Excel_Quit()
  72.   oExcel.DisplayAlerts = False
  73.   'oBook.Close
  74.   oExcel.ActiveWorkbook.Close
  75.   oExcel.Quit
  76. End Function
  77. '判断计算机类型,只允许台式机发声(笔记本会使用扬声器发声,声音太刺耳)
  78. Function ChassisType()
  79.   Dim strComputer, objWMIService, colChassis, objChassis, strChassisType
  80.   strComputer = "."
  81.   Set objWMIService = GetObject("winmgmts:" _
  82.               & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  83.   Set colChassis = objWMIService.ExecQuery _
  84.               ("Select * from Win32_SystemEnclosure")
  85.   For Each objChassis in colChassis
  86.     For Each strChassisType in objChassis.ChassisTypes
  87.       Select Case strChassisType
  88.         Case 1
  89.           ChassisType = "Other"
  90.         Case 2
  91.           ChassisType = "Unknown"
  92.         Case 3
  93.           ChassisType = "Desktop"
  94.         Case 4
  95.           ChassisType = "Low Profile Desktop"
  96.         Case 5
  97.           ChassisType = "Pizza Box"
  98.         Case 6
  99.           ChassisType = "Mini Tower"
  100.         Case 7
  101.           ChassisType = "Tower"
  102.         Case 8
  103.           ChassisType = "Portable"
  104.         Case 9
  105.           ChassisType = "Laptop"
  106.         Case 10
  107.           ChassisType = "Notebook"
  108.         Case 11
  109.           ChassisType = "Handheld"
  110.         Case 12
  111.           ChassisType = "Docking Station"
  112.         Case 13
  113.           ChassisType = "All-in-One"
  114.         Case 14
  115.           ChassisType = "Sub-Notebook"
  116.         Case 15
  117.           ChassisType = "Space Saving"
  118.         Case 16
  119.           ChassisType = "Lunch Box"
  120.         Case 17
  121.           ChassisType = "Main System Chassis"
  122.         Case 18
  123.           ChassisType = "Expansion Chassis"
  124.         Case 19
  125.           ChassisType = "Sub-Chassis"
  126.         Case 20
  127.           ChassisType = "Bus Expansion Chassis"
  128.         Case 21
  129.           ChassisType = "Peripheral Chassis"
  130.         Case 22
  131.           ChassisType = "Storage Chassis"
  132.         Case 23
  133.           ChassisType = "Rack Mount Chassis"
  134.         Case 24
  135.           ChassisType = "Sealed-Case PC"
  136.         Case Else
  137.           ChassisType = "Unknown"
  138.       End Select
  139.     Next
  140.   Next
  141. End Function
复制代码
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

回复 3# DAIC
不懂啊,请指教。
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

TOP

来一曲小苹果吧

TOP

  1. Option Explicit
  2. Dim WshShell
  3. Dim oExcel, oBook, oModule
  4. Dim strRegKey, strCode
  5. Set oExcel = CreateObject("Excel.Application")
  6. set WshShell = CreateObject("wscript.Shell")
  7. strRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\$\Excel\Security\AccessVBOM"
  8. strRegKey = Replace(strRegKey, "$", oExcel.Version)
  9. WshShell.RegWrite strRegKey, 1, "REG_DWORD"
  10. Set oBook = oExcel.Workbooks.Add
  11. Set oModule = obook.VBProject.VBComponents.Add(1)
  12. strCode = _
  13. "Declare Sub Beep Lib ""kernel32"" (ByVal fre As Long, ByVal ms As Long)" & vbCr & _
  14. "Declare Sub Sleep Lib ""kernel32"" (ByVal ms As Long)"
  15. oModule.CodeModule.AddFromString strCode
  16. Beep 587, 88: Sleep 20
  17. Beep 494, 88: Sleep 20
  18. Beep 349, 88: Sleep 20
  19. Beep 587, 88: Sleep 20
  20. Beep 494, 88: Sleep 20
  21. Beep 349, 88: Sleep 20
  22. Beep 587, 88: Sleep 20
  23. Beep 494, 88: Sleep 20
  24. Beep 349, 88: Sleep 20
  25. Beep 523, 195: Sleep 20
  26. Beep 523, 195: Sleep 20
  27. Beep 523, 195: Sleep 20
  28. Beep 587, 88: Sleep 20
  29. Beep 494, 88: Sleep 20
  30. Beep 349, 88: Sleep 20
  31. Beep 587, 88: Sleep 20
  32. Beep 494, 88: Sleep 20
  33. Beep 349, 88: Sleep 20
  34. Beep 587, 88: Sleep 20
  35. Beep 494, 88: Sleep 20
  36. Beep 349, 88: Sleep 20
  37. Beep 659, 195: Sleep 20
  38. Beep 659, 195: Sleep 20
  39. Beep 659, 195: Sleep 20
  40. Beep 587, 88: Sleep 20
  41. Beep 494, 88: Sleep 20
  42. Beep 349, 88: Sleep 20
  43. Beep 587, 88: Sleep 20
  44. Beep 494, 88: Sleep 20
  45. Beep 349, 88: Sleep 20
  46. Beep 587, 88: Sleep 20
  47. Beep 494, 88: Sleep 20
  48. Beep 349, 88: Sleep 20
  49. Beep 523, 195: Sleep 20
  50. Beep 523, 195: Sleep 20
  51. Beep 523, 195: Sleep 20
  52. Beep 587, 88: Sleep 20
  53. Beep 494, 88: Sleep 20
  54. Beep 349, 88: Sleep 20
  55. Beep 587, 88: Sleep 20
  56. Beep 494, 88: Sleep 20
  57. Beep 349, 88: Sleep 20
  58. Beep 587, 88: Sleep 20
  59. Beep 494, 88: Sleep 20
  60. Beep 349, 88: Sleep 20
  61. Beep 659, 195: Sleep 20
  62. Beep 659, 195: Sleep 20
  63. Beep 659, 195: Sleep 20
  64. Beep 587, 410: Sleep 20
  65. Beep 494, 410: Sleep 20
  66. Beep 523, 410: Sleep 20
  67. Beep 440, 410: Sleep 20
  68. Beep 659, 410: Sleep 20
  69. Beep 523, 410: Sleep 20
  70. Beep 494, 410: Sleep 20
  71. Beep 587, 410: Sleep 20
  72. Beep 587, 410: Sleep 20
  73. Beep 494, 410: Sleep 20
  74. Beep 523, 410: Sleep 20
  75. Beep 440, 410: Sleep 20
  76. Beep 659, 410: Sleep 20
  77. Beep 523, 410: Sleep 20
  78. Beep 494, 820: Sleep 20
  79. Beep 587, 410: Sleep 20
  80. Beep 494, 410: Sleep 20
  81. Beep 523, 410: Sleep 20
  82. Beep 440, 410: Sleep 20
  83. Beep 659, 410: Sleep 20
  84. Beep 523, 410: Sleep 20
  85. Beep 494, 410: Sleep 20
  86. Beep 587, 410: Sleep 20
  87. Beep 587, 410: Sleep 20
  88. Beep 494, 410: Sleep 20
  89. Beep 523, 410: Sleep 20
  90. Beep 440, 410: Sleep 20
  91. Beep 659, 410: Sleep 20
  92. Beep 523, 410: Sleep 20
  93. Beep 494, 820: Sleep 20
  94. Beep 440, 410: Sleep 20
  95. Beep 659, 410: Sleep 20
  96. Beep 494, 410: Sleep 20
  97. Beep 659, 410: Sleep 20
  98. Beep 523, 410: Sleep 20
  99. Beep 587, 195: Sleep 20
  100. Beep 659, 195: Sleep 20
  101. Beep 587, 410: Sleep 20
  102. Beep 784, 410: Sleep 20
  103. Beep 880, 195: Sleep 20
  104. Beep 659, 195: Sleep 20
  105. Beep 988, 195: Sleep 20
  106. Beep 1047, 195: Sleep 20
  107. Beep 988, 195: Sleep 20
  108. Beep 1047, 88: Sleep 20
  109. Beep 988, 88: Sleep 20
  110. Beep 880, 195: Sleep 20
  111. Beep 784, 195: Sleep 20
  112. Beep 659, 195: Sleep 20
  113. Beep 784, 195: Sleep 20
  114. Beep 587, 195: Sleep 20
  115. Beep 659, 195: Sleep 20
  116. Beep 523, 410: Sleep 450
  117. Beep 440, 410: Sleep 20
  118. Beep 659, 410: Sleep 20
  119. Beep 494, 410: Sleep 20
  120. Beep 659, 410: Sleep 20
  121. Beep 523, 410: Sleep 20
  122. Beep 587, 195: Sleep 20
  123. Beep 659, 195: Sleep 20
  124. Beep 587, 410: Sleep 20
  125. Beep 784, 410: Sleep 20
  126. Beep 880, 195: Sleep 20
  127. Beep 659, 195: Sleep 20
  128. Beep 988, 195: Sleep 20
  129. Beep 1047, 195: Sleep 20
  130. Beep 988, 195: Sleep 20
  131. Beep 1047, 88: Sleep 20
  132. Beep 988, 88: Sleep 20
  133. Beep 880, 195: Sleep 20
  134. Beep 784, 195: Sleep 20
  135. Beep 880, 840: Sleep 20
  136. Beep 440, 410: Sleep 20
  137. Beep 659, 410: Sleep 20
  138. Beep 494, 410: Sleep 20
  139. Beep 659, 410: Sleep 20
  140. Beep 523, 410: Sleep 20
  141. Beep 587, 195: Sleep 20
  142. Beep 659, 195: Sleep 20
  143. Beep 587, 410: Sleep 20
  144. Beep 784, 410: Sleep 20
  145. Beep 880, 195: Sleep 20
  146. Beep 659, 195: Sleep 20
  147. Beep 988, 195: Sleep 20
  148. Beep 1047, 195: Sleep 20
  149. Beep 988, 195: Sleep 20
  150. Beep 1047, 88: Sleep 20
  151. Beep 988, 88: Sleep 20
  152. Beep 880, 195: Sleep 20
  153. Beep 784, 195: Sleep 20
  154. Beep 659, 195: Sleep 20
  155. Beep 784, 195: Sleep 20
  156. Beep 587, 195: Sleep 20
  157. Beep 659, 195: Sleep 20
  158. Beep 523, 410: Sleep 450
  159. Beep 440, 410: Sleep 20
  160. Beep 659, 410: Sleep 20
  161. Beep 494, 410: Sleep 20
  162. Beep 659, 410: Sleep 20
  163. Beep 523, 410: Sleep 20
  164. Beep 587, 195: Sleep 20
  165. Beep 659, 195: Sleep 20
  166. Beep 587, 410: Sleep 20
  167. Beep 784, 410: Sleep 20
  168. Beep 880, 195: Sleep 20
  169. Beep 659, 195: Sleep 20
  170. Beep 988, 195: Sleep 20
  171. Beep 1047, 195: Sleep 20
  172. Beep 988, 195: Sleep 20
  173. Beep 1047, 88: Sleep 20
  174. Beep 988, 88: Sleep 20
  175. Beep 880, 195: Sleep 20
  176. Beep 784, 195: Sleep 20
  177. Beep 880, 840: Sleep 20
  178. Sub Beep(fre,ms)
  179. oExcel.Run "Beep",fre,ms
  180. End Sub
  181. Sub Sleep(ms)
  182. oExcel.Run "Sleep",ms
  183. End Sub
  184. oExcel.DisplayAlerts = False
  185. oBook.Close
  186. oExcel.Quit
复制代码
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

TOP

返回列表