Advertisement
wetyukmnbxc

Untitled

Mar 6th, 2023
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Can you write a powershell script to make a GUI. Add one button. When this button is clicked, it triggers an event that a sound file is played.
  2.  
  3. Sure, here's a PowerShell script that creates a GUI with a button that plays a sound file when clicked:
  4.  
  5.  
  6. Add-Type -AssemblyName System.Windows.Forms
  7. Add-Type -AssemblyName System.Drawing
  8.  
  9. # Create the form
  10. $form = New-Object System.Windows.Forms.Form
  11. $form.Text = "Play Sound"
  12. $form.Size = New-Object System.Drawing.Size(200, 100)
  13. $form.StartPosition = "CenterScreen"
  14.  
  15. # Create the button
  16. $button = New-Object System.Windows.Forms.Button
  17. $button.Location = New-Object System.Drawing.Point(50, 25)
  18. $button.Size = New-Object System.Drawing.Size(100, 50)
  19. $button.Text = "Play Sound"
  20. $button.Add_Click({
  21.    $sound = New-Object System.Media.SoundPlayer "C:\Windows\Media\chimes.wav"
  22.    $sound.Play()
  23. })
  24.  
  25. # Add the button to the form
  26. $form.Controls.Add($button)
  27.  
  28. # Show the form
  29. $form.ShowDialog() | Out-Null
  30.  
  31.  
  32. This script creates a form with a button labeled "Play Sound". When the button is clicked, it creates a `System.Media.SoundPlayer` object and plays the sound file located at "C:\Windows\Media\chimes.wav". You can replace this file path with the path to your own sound file.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement