Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for defprn2k.pl

(view source code of defprn2k.pl as plain text)

  1. #! perl
  2.  
  3. # Store help text in variable
  4. $syntax = "\nDefPRN2K.pl,  Version 1.00 for Windows 2000\n";
  5. $syntax = $syntax."Display default printer\n\n";
  6. $syntax = $syntax."Usage:  DEFPRN2K.PL\n\n";
  7. $syntax = $syntax."Written by Rob van der Woude\n";
  8. $syntax = $syntax."http://www.robvanderwoude.com\n";
  9.  
  10. # Check Windows version (Windows 2000 = NT 5.0 or later required)
  11. if ( $^O ne "MSWin32" ) {
  12. 	die $syntax;
  13. } else {
  14.         @os_version_info = Win32::GetOSVersion();
  15. 	if ( @os_version_info[1] < 5 ) {
  16. 		die $syntax;
  17. 	}
  18. }
  19.  
  20. # Check number of command line arguments (none required)
  21. if ( @ARGV[0] ) {
  22. 	die $syntax;
  23. }
  24.  
  25. # Initialize the required module
  26. use Win32API::Registry 0.21 qw( :ALL );
  27.  
  28. # Read the value from the registry
  29. RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows", 0, KEY_READ, $handle ) || die "Can't open registry section: ".regLastError()."\n";
  30. RegQueryValueEx( $handle, "Device", [], $type, $regval, [] ) || die "Can't read registry section: ".regLastError()."\n";
  31. RegCloseKey( $handle ) ||  die "Can't close registry section: ".regLastError()."\n";
  32.  
  33. # Parse the string found
  34. $regval =~ m/^([^\,]+),[^\,]+,([^:]+):?$/;
  35. $prn    = $1;
  36. $port   = $2;
  37.  
  38. # Display the result
  39. print "\nDefault printer is $prn on $port\n";
  40.  

page last modified: 2024-02-26; loaded in 0.0165 seconds