Yunga

CDTrayPrank.ps1

Oct 8th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # From http://www.reddit.com/r/PowerShell/comments/2inuxb/prank_script_that_randomly_openscloses_the_cd_tray/
  2.  
  3. $wait = 60
  4. $status = "closed"
  5.  
  6. function CDTray ($mode) {
  7.   $MemDef = @"
  8. [DllImport("winmm.dll", CharSet = CharSet.Ansi)]
  9.  public static extern int mciSendStringA(
  10.    string lpstrCommand,
  11.    string lpstrReturnString,
  12.    int uReturnLength,
  13.    IntPtr hwndCallback
  14.  );
  15. "@
  16.  
  17.   $winnm = Add-Type -memberDefinition $MemDef -ErrorAction 'SilentlyContinue' -passthru -name mciSendString
  18.   $winnm::mciSendStringA("set cdaudio door $mode", $null, 0,0)
  19. }
  20.  
  21. while ($true) {
  22.   $num = Get-Random -Max 10
  23.   if ($num -lt 2) {
  24.     if ($status -eq "closed") {
  25.       $status = "open"
  26.     } else {
  27.       $status = "closed"
  28.     }
  29.     CDTray $status
  30.   }
  31.   sleep $wait
  32. }
Add Comment
Please, Sign In to add comment