At 10:45 AM 6/18/2001, Christian Jung wrote:
>but i want scheduling shutdowns, and before the computer dies, i want to 
>save screen into picture file.

The following code uses SnagIt and captures the screen in a file.
You have to modify paths though.
This code has been working in our environment for years, but outside of it 
this code is a fragment, so you must modify paths before trying it.

If you have specific questions, email me.

#
# Use SnagIt/32 to capture the screen
#
sub SnagNSave {
     my ($dir) = @_;
     my ($base) = "OkeyDokey.Snag";
     my ($file);
     my ($snagItExe, $snagShort, $title, $findIt);
     my ($rc) = 0;
     my %info = ();

     $findIt = "$ENV{'HUB'}/bat/sysadmin/findLocalCmd";
     if (-f $findIt) {
         chomp($snagItExe = `perl $findIt snagit`);
     }
     $snagItExe = 'C:\Program Files\TechSmith\SnagIt32\snagit32.exe'
             unless ( $snagItExe && -f $snagItExe );
     if ( -f $snagItExe ) {
         # quote the executable if it contains a space -- patch for
         # BatExecBG deficiency
         $snagShort = Win32::GetShortPathName($snagItExe);
         unless (BatExecBG($snagShort)) {
             $@ = "Problems starting $snagItExe";
             return 0;
         }
     } else {
         $@ = "Cannot find $snagItExe\n";
         return 0;
     }

     if (&Win32::IsWinNT) {
         Win32::AdminMisc::GetFileInfo($snagShort, \%info);
         $title = ($info{'FileVersion'} eq '4.3.1')
                 ? 'SnagIt/32'
                 : 'SnagIt';
     }
     elsif (1777580 == (stat $snagShort)[7]) {
         $title = "SnagIt/32";
     }
     else {
         $title = 'SnagIt';
     }

     my $n = 0;
     my $limit = 10000;
     while ( $n < $limit ) {
         $n++;
         $file = ($title eq 'SnagIt')
                 ##  Snag jpeg files they are a lot smaller
                 ? sprintf("%s%04d.jpg", "$dir/$base", $n)   # jpeg by default
                 : sprintf("%s%04d.gif", "$dir/$base", $n);
         print "Checking out $file...\n";
         last unless -e $file;
     }
     print "Will create $file\n";
     my $fileKeystrokes;
     ($fileKeystrokes = $file) =~ s%/%\\\\%g;
     if ( $n >= $limit ) {
         $@ = "OkeyDokey limit exceeded:\n" .
             "\tToo many snagged screen shots are in $dir";
     }     # Find SnagIt/32
     else {
         WaitNSend(${title}, 10000,
              "\\CTRL+\\\\SHIFT+\\P\\CTRL-\\\\SHIFT-\\") &&
         sleep 2 &&
         WaitNSend("${title} Capture Preview", 10000,
                 "\\ALT+\\FS\\ALT-\\\r") &&
         sleep 1;

         ##  Default file type is already set for 5.0
         if ($title != 'SnagIt') {
            WaitNSend("Save As", 10000,
                      "\\ALT+\\T\\ALT-\\" .
                      "\\UP\\\\UP\\\\UP\\\\UP\\\\UP\\" .
                      "\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\r")        # GIF
            &&
            sleep 1;
         }

         WaitNSend("Save As", 10000, "\\ALT+\\N\\ALT-\\$fileKeystrokes")
         &&
         sleep 1 &&
         WaitNSend("Save As", 5000, "\\ALT+\\S\\ALT-\\\\ESC\\")
         &&
         sleep 2;

         WaitNSend(${title}, 5000, "\\ALT+\\ \\ALT-\\n", "Minimize SnagIt") &&
         sleep 2;

         if ( -f $file ) {
             print "Snagged successfully into $file\n";
             $rc = $file;
         } else {
             print "Error creating $file??\n";
             # Ask SnagNSave to exit, so next time we'll start from scratch
             if ( WaitNSend("${title}", 3000,
                            "\\ALT+\\\\F4\\\\ALT-\\", 'Quit from SnagIt') ) {
                 print "Sent Alt-F4 to SnagIt\n";
             } else {
                 print "Cannot send Alt-F4 to SnagIt:\n\t$@\n";
             }
         }
     }
     $rc;
} # SnagNSave

sub WaitNSend {
     my ($title, $timeout, $keystrokes, $comments) = @_;
     my ($rc) = 0;
     my ($hWnd);

     ($_ = $keystrokes) =~ s/\r/\\r/gs;
     print "Sending <$_> to <$title> ", ($comments ? "($comments)" : ""), "\n";
     if (!Win32::Setupsup::WaitForWindow($title, \$hWnd, $timeout, 100)) {
         $@ = "Could not find $title window: ";
     } elsif (! &Win32::Setupsup::SendKeys($hWnd, $keystrokes, 0, 50) ) {
         $@ = "Could not send <$keystrokes> to <$title>: ";
     } else {
         $rc = 1;
     }
     $rc;
} # WaitNSend

--
Mike Mirman                             Tel: (508) 647-7555
The Mathworks, Inc.                     FAX: (508) 647-7013
3 Apple Hill Drive, Natick, MA 01760-2098
mailto:[EMAIL PROTECTED]            Web: http://www.mathworks.com

_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin

Reply via email to