Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # From http://www.reddit.com/r/PowerShell/comments/2inuxb/prank_script_that_randomly_openscloses_the_cd_tray/
- $wait = 60
- $status = "closed"
- function CDTray ($mode) {
- $MemDef = @"
- [DllImport("winmm.dll", CharSet = CharSet.Ansi)]
- public static extern int mciSendStringA(
- string lpstrCommand,
- string lpstrReturnString,
- int uReturnLength,
- IntPtr hwndCallback
- );
- "@
- $winnm = Add-Type -memberDefinition $MemDef -ErrorAction 'SilentlyContinue' -passthru -name mciSendString
- $winnm::mciSendStringA("set cdaudio door $mode", $null, 0,0)
- }
- while ($true) {
- $num = Get-Random -Max 10
- if ($num -lt 2) {
- if ($status -eq "closed") {
- $status = "open"
- } else {
- $status = "closed"
- }
- CDTray $status
- }
- sleep $wait
- }
Add Comment
Please, Sign In to add comment