Advertisement
Guest User

CD Tray

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