Fellow Monks,

I'm interested in writing a small script that will detect if a CD or CompactFlash card has been inserted into the system and perform some action when that occurs. I've tried a basic poll mechanism and have had some luck dismissing the "There is no disk in drive foo" dialog boxes with Win32::GuiTest, but even this can be annoying if you happen to be trying to type at the same time the dialog boxes are coming up.

Win32::ChangeNotify does not seem to be the answer since it pops up the dialog boxes as well.

I haven't done much on Windows doing Windows-specific tasks, so I was hoping that someone would have some wisdom out there to enlighten me. I just upgraded to ActiveState 5.8.2

Here's my code thus far:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Win32::GuiTest qw(FindWindowLike GetWindowText GetForegroundWindow + SetForegroundWindow SendKeys PushButton); use Thread; my $info; sub waitForSeconds { select (undef, undef, undef, $_[0]); } sub HandleDialog { my $max = shift; my $found = 0; my $tries = 0; while (($found < 2) && ($tries++ < $max)){ waitForSeconds(.2); my ($dialog) = FindWindowLike(0, "^perl.exe", ""); if ($dialog){ print "Found dialog!\n"; SetForegroundWindow($dialog); $found++; PushButton("Continue"); } else { print "Did not find dialog\n"; last; } } } sub checkdir { my $dir = shift; my $t = Thread->new(\&HandleDialog, 10); my @data = stat($dir); $t->join(); if (@data){ print Dumper(\@data); } else { warn "Could not stat $dir"; return; } opendir(DH, $dir) || warn "Could not open $dir"; while ((my $entry = readdir(DH))){ print "Got $entry from $dir\n"; } closedir(DH); } foreach my $arg (@ARGV){ checkdir($arg); }

In reply to Windows drive change notifications by bschmer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.