Ei kuvausta

SystemSoundsList.ps1 1019B

123456789101112131415161718192021222324252627282930313233
  1. # Import the necessary assemblies
  2. Add-Type -AssemblyName System.Windows.Forms
  3. # Create the form
  4. $form = New-Object System.Windows.Forms.Form
  5. $form.Text = "System Sounds"
  6. $form.Size = New-Object System.Drawing.Size(400,300)
  7. # Create the list box
  8. $listBox = New-Object System.Windows.Forms.ListBox
  9. $listBox.Location = New-Object System.Drawing.Size(10,10)
  10. $listBox.Size = New-Object System.Drawing.Size(375,250)
  11. $form.Controls.Add($listBox)
  12. # Get the system sounds directory
  13. $systemSoundsDir = [System.Environment]::GetFolderPath("Windows") + "\Media"
  14. # Populate the list box with the system sounds
  15. Get-ChildItem -Path $systemSoundsDir | ForEach-Object {
  16. $listBox.Items.Add($_.Name)
  17. }
  18. # Define the list box's selected index changed event
  19. $listBox.Add_SelectedIndexChanged({
  20. # Get the selected sound file
  21. $selectedSound = $listBox.SelectedItem
  22. # Play the sound
  23. (New-Object System.Media.SoundPlayer -ArgumentList "$systemSoundsDir\$selectedSound").Play()
  24. })
  25. # Show the form
  26. $form.ShowDialog()

Powered by TurnKey Linux.