Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

View File

@@ -0,0 +1,453 @@
# $Id: Cmd.pm,v 1.1 2007/10/23 12:18:37 pkaluski Exp $
=head1 NAME
Win32::GuiTest::Cmd - Perl Batch File Enhancer. Part of Win32::GuiTest.
=head1 SYNOPSIS
use Win32::GuiTest::Cmd ':ASK';
Pause("Press ENTER to start the setup...");
setup_network()
if YesOrNo("Setup networking component?");
$address = AskForIt("What's your new ip address?",
"122.122.122.122");
$dir = AskForDir("Where should I put the new files?",
"c:\\temp");
copy_files($dir) if $dir;
$exe = AskForExe("Where is your net setup program?",
"/foo/bar.exe");
system($exe) if YesOrNo("Want me to run the net setup?");
=head1 DESCRIPTION
Instead of writing batch files (although on NT they are almost
usable), I've resorted more and more to writing Perl scripts for
common sysadmin/build/test chores. This module makes that kind of
thing easier.
Other modules I've found useful for that kind of work:
C<use Win32::NetAdmin;>
C<use Win32::NetResource;>
C<use Win32::ODBC;>
C<use Socket;>
C<use Sys::Hostname;>
C<use File::Path 'mkpath';>
C<use Getopt::Std 'getopts';>
=cut
package Win32::GuiTest::Cmd;
require Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
use ExtUtils::MakeMaker;
use Cwd;
use File::Basename;
use strict;
use warnings;
@ISA = qw(Exporter);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
@EXPORT = ();
%EXPORT_TAGS=(
CPL => [ qw(
Accessibility AppWizard Console DateTime Display Exchange FindFast
Internet Joystick Modem Mouse Multimedia Network Odbc Pcmcia Ports Ras
Regional Server System Telephony Ups Users
)],
ASK => [ qw(
Pause YesOrDie YesOrNo AskForIt IsExe AskForExe AskForDir AskAndRun
)],
REG => [ qw(
RegisterCom UnregisterCom AddToRegistry
)],
MISC => [ qw(
WhichExe TempFileName
)],
);
@EXPORT_OK= ();
{ my $ref;
foreach $ref ( values(%EXPORT_TAGS) ) {
push( @EXPORT_OK, @$ref );
}
}
$EXPORT_TAGS{ALL}= \@EXPORT_OK;
# Preloaded methods go here.
=head1 FUNCTIONS
=head2 Console
Console interaction functions heavily based on the command-line installer for
the libwin32 distribution written by Gurusamy Sarathy.
=over 4
=item Pause([$message])
Shows a message and waits until the user presses ENTER.
=cut
sub Pause {
my $msj = shift;
print "$msj" if $msj;
scalar(<STDIN>); # hang around in case they ran it from Explorer
}
=item YesOrDie([$message])
Asks for a [y/n] response using the message you specify. The program
dies if you answer 'n'.
=cut
sub YesOrDie {
my $m = shift || "Proceed?";
print "$m [y] ";
die "Bailing out\n" if scalar(<STDIN>) !~ /^\s*(y|$)/i;
}
=item YesOrNo([$msg])
Asks for a [y/n] response using the message you specify. Returns 1 if
you type 'y' or 0 otherwise.
=cut
sub YesOrNo {
my $m = shift || "Which?";
print "$m [y] ";
return 1 if scalar(<STDIN>) =~ /^\s*(y|$)/i;
}
=item AskForIt([$question],[$def_value])
Asks the user to input a value and returns it. If you omit $question
a default question will be used. If you omit $def_value, false will be used
as default return value.
=cut
sub AskForIt {
my $m = shift || "Enter value";
my $def = shift;
$def = "" unless defined $def;
print "$m \[$def\] ";
my $v = <STDIN>;
chomp $v;
return ($v =~ /^\s*$/ ? $def : $v);
}
=item IsExe($filename)
Checks if a file is executable.
=cut
sub IsExe {
my $exe = shift;
return $exe if -x $exe && ! -d _;
}
=item AskForExe([$question],[$def_exe])
Just like AskForIt, but returns false if the value
is not an executable file.
=cut
sub AskForExe {
my $exe = AskForIt(@_);
return $exe if -x $exe && ! -d _;
warn "$exe is not executable\n";
return "";
}
=item AskForDir([$question],[$def_dir])
Just like AskForIt, but returns false if the value
is not a directory.
=cut
sub AskForDir {
my $dir = AskForIt(@_);
return $dir if -d $dir;
warn "$dir is not a directory\n";
return "";
}
=item AskAndRun([$question],[$def_exe])
Asks for an exe file an runs it using C<system>.
=cut
sub AskAndRun {
my $exe = AskForExe(@_);
system($exe) if $exe;
}
sub try_again {
print "Let's try this again.\n";
goto shift;
}
=back
=head2 System Configuration
Mostly allow opening Win32 Control Panel Applets programatically.
=over 4
=item RunCpl($applet)
Opens a Control Panel Applet (.cpl) by name.
RunCpl("modem.cpl");
=cut
sub RunCpl {
my $cpl = shift;
system("start rundll32.exe shell32.dll,Control_RunDLL $cpl");
}
=item Modem, Network, Console, Accessibility, AppWizard, Pcmcia,
Regional, Joystick, Mouse, Multimedia, Odbc, Ports, Server,
System, Telephony, DateTime, Ups, Internet, Display, FindFast,
Exchange, 3ComPace
Each of them opens the corresponding Control Panel Applet.
=cut
sub Modem { RunCpl "modem.cpl"; }
sub Network { RunCpl "ncpa.cpl"; }
sub Console { RunCpl "console.cpl"; }
sub Accessibility { RunCpl "access.cpl"; }
sub AppWizard { RunCpl "appwiz.cpl"; }
sub Pcmcia { RunCpl "DEVAPPS.cpl"; }
sub Regional { RunCpl "intl.cpl"; }
sub Joystick { RunCpl "joy.cpl"; }
sub Mouse { RunCpl "main.cpl"; }
sub Multimedia { RunCpl "mmsys.cpl"; }
sub Odbc { RunCpl "ODBCCP32.cpl"; }
sub Ports { RunCpl "PORTS.cpl"; }
sub Server { RunCpl "srvmgr.cpl"; }
sub System { RunCpl "sysdm.cpl"; }
sub Telephony { RunCpl "telephon.cpl"; }
sub DateTime { RunCpl "timedate.cpl"; }
sub Ups { RunCpl "ups.cpl"; }
sub Internet { RunCpl "INETCPL.cpl"; }
sub Display { RunCpl "DESK.cpl"; }
# Propietary CPL applets
sub FindFast { RunCpl "FINDFAST.cpl"; }
sub Exchange { RunCpl "MLCFG32.cpl"; }
#sub 3ComPace { RunCpl "pacecfg.cpl"; }
# Some useful system utilities
=item Ras
Installs or configures the RAS (Remote Access Service) component.
=cut
sub Ras { system("start rasphone.exe"); }
=item Users
Runs the User/Group Manager application.
=cut
sub Users { system("start musrmgr.exe"); }
=back
=head2 Registry
Manipulate the registry.
=over 4
=item RegisterCom($path)
Uses regsvr32.exe to register a COM server.
RegisterCom("c:\\myfiles\\mycontrol.ocx");
=cut
sub RegisterCom {
my $server = shift;
system("regsvr32 $server") &&
warn "Could not register server $server\n";
}
=item UnregisterCom($path)
Uses regsvr32.exe to unregister a COM server.
UnregisterCom("c:\\myfiles\\mycontrol.ocx");
=cut
sub UnregisterCom {
my $server = shift;
system("regsvr32 /u $server");
}
=item AddToRegistry($regfile)
Uses regedit.exe to merge a .reg file into the system registry.
AddToRegistry("c:\\myfiles\\test.reg");
=cut
sub AddToRegistry {
my $reg = shift;
system("regedit $reg");
}
=back
=head2 Misc
Sorry about that...
=over 4
=item WhichExe($file)
Takes a command name guesses which
executable file gets executed if you invoke the command.
WhichExe("regedit") -> C:\WINNT\regedit.exe
WhichExe("regsvr32") -> D:\bin\regsvr32.exe
WhichExe("ls") -> D:\Usr\Cygnus\B19\H-i386-cygwin32\bin\ls.exe
Based on original code grabbed from CPAN::FirstTime.
Added support for NT file extension associations:
WhichExe("test.pl") -> perl D:\SCRIPTS\test.pl %*
WhichExe("report.ps") -> D:\gstools\gsview\gsview32.exe D:\TMP\report.ps
=cut
#
# Uses extensions in PATHEXT or default extensions to look for
# posible filenames.
#
sub MaybeCommand {
my $file = shift;
for (split(/;/, $ENV{'PATHEXT'} || '.COM;.EXE;.BAT;.CMD')) {
return "${file}$_" if -e "${file}$_";
}
return;
}
sub MaybeAssoc {
my $abs = shift;
my($name,$path,$suffix) = fileparse($abs, '\..*');
return unless $suffix;
for (`assoc`) {
chomp;
if (/$suffix=(.*)/) {
my $type = $1;
for (`ftype`) {
chomp;
if (/$type=(.*)/) {
my $cmdline = $1;
my $count = ($cmdline =~ s/%1/${abs}/);
$cmdline =~ s/%\*/${abs}/ if !$count;
return $cmdline;
}
}
#warn "No ftype for $type\n";
}
}
return;
}
sub WhichExe {
my(@path) = split /$Config::Config{'path_sep'}/, $ENV{'PATH'};
my $exe = shift;
my $path = shift || [ @path ];
unshift @$path, getcwd; # Don't forget to check the cwd first
#warn "in WhichExe exe[$exe] path[@$path]";
for (@$path) {
my $abs = MM->catfile($_, $exe);
my $ret;
# Try with file associations
if (($ret = MaybeAssoc($abs))) {
return $ret;
}
# Try with command extensions
if (($ret = MaybeCommand($abs))) {
return $ret;
}
}
}
=item TempFileName
Returns the full path for a temporary file that will not collide with an
existing file.
=cut
sub TempFileName {
my $pre = "aaaaaaaa";
for (0..10000000) {
my $name = MM->catfile("$ENV{TMP}", "$pre.reg");
return $name unless -e $name;
$pre++;
}
return;
}
# Autoload methods go after =cut, and are processed by the autosplit program.
1;
__END__
=back
=head1 AUTHOR
Ernesto Guisado E<lt>erngui@acm.orgE<gt>, E<lt>http://triumvir.orgE<gt>
=cut

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,186 @@
#
# Not automatically generated (for now...)
#
sub BM_SETCHECK { 0x00F1; }
sub BST_CHECKED { 0x0001; }
sub BST_INDETERMINATE { 0x0002; }
sub BST_UNCHECKED { 0x0000; }
sub ES_MULTILINE { 0x0004; }
sub ES_NUMBER { 0x2000; }
sub ES_PASSWORD { 0x0020; }
sub ES_READONLY { 0x0800; }
sub GWL_EXSTYLE { -20; }
sub GWL_ID { -12; }
sub GWL_STYLE { -16; }
sub GW_CHILD { 5; }
sub GW_HWNDNEXT { 2; }
sub SW_FORCEMINIMIZE { 11; }
sub SW_HIDE { 0; }
sub SW_MAX { 11; }
sub SW_MAXIMIZE { 3; }
sub SW_MINIMIZE { 6; }
sub SW_NORMAL { 1; }
sub SW_RESTORE { 9; }
sub SW_SHOW { 5; }
sub SW_SHOWDEFAULT { 10; }
sub SW_SHOWMAXIMIZED { 3; }
sub SW_SHOWMINIMIZED { 2; }
sub SW_SHOWMINNOACTIVE { 7; }
sub SW_SHOWNA { 8; }
sub SW_SHOWNOACTIVATE { 4; }
sub SW_SHOWNORMAL { 1; }
sub TCM_SETCURFOCUS { 0x1300 + 48; }
sub WM_COMMAND { 0x0111; }
sub WM_SYSCOMMAND { 0x0112; }
sub WM_LBUTTONDOWN { 0x0201; }
sub WM_LBUTTONUP { 0x0202; }
### From WinUser.h
# Common extended styles
sub WS_EX_ACCEPTFILES { 0x00000010; }
sub WS_EX_TOOLWINDOW { 0x00000080; }
sub WS_EX_TOPMOST { 0x00000008; }
### From CommCtrl.h
sub LVS_AUTOARRANGE { 0x0100; }
sub LVS_ICON { 0x0000; }
sub LVS_LIST { 0x0003; }
sub LVS_SMALLICON { 0x0002; }
sub TVM_EXPAND { 0x1100 + 2; }
sub TVM_GETNEXTITEM { 0x1100 + 10; }
sub TVM_SELECTITEM { 0x1100 + 11; }
sub TVM_GETITEM { 0x1100 + 12; }
sub TVM_ENSUREVISIBLE { 0x1100 + 20; }
sub TVGN_ROOT { 0; }
sub TVGN_NEXT { 1; }
sub TVGN_CHILD { 4; }
sub TVGN_CARET { 9; }
sub TVE_EXPAND { 2; }
### From winuser.h
sub KEYEVENTF_EXTENDEDKEY { 0x0001; }
sub KEYEVENTF_KEYUP { 0x0002; }
sub VK_LBUTTON { 0x01; }
sub VK_RBUTTON { 0x02; }
sub VK_CANCEL { 0x03; }
sub VK_MBUTTON { 0x04; }
sub VK_BACK { '0' . 0x08; } # for IsKeyPressed, because it treats
sub VK_TAB { '0' . 0x09; } # single digits as characters
sub VK_CLEAR { 0x0C; }
sub VK_RETURN { 0x0D; }
sub VK_SHIFT { 0x10; }
sub VK_CONTROL { 0x11; }
sub VK_MENU { 0x12; }
sub VK_PAUSE { 0x13; }
sub VK_CAPITAL { 0x14; }
sub VK_KANA { 0x15; }
sub VK_HANGEUL { 0x15; }
sub VK_HANGUL { 0x15; }
sub VK_JUNJA { 0x17; }
sub VK_FINAL { 0x18; }
sub VK_HANJA { 0x19; }
sub VK_KANJI { 0x19; }
sub VK_ESCAPE { 0x1B; }
sub VK_CONVERT { 0x1C; }
sub VK_NONCONVERT { 0x1D; }
sub VK_ACCEPT { 0x1E; }
sub VK_MODECHANGE { 0x1F; }
sub VK_SPACE { 0x20; }
sub VK_PRIOR { 0x21; }
sub VK_NEXT { 0x22; }
sub VK_END { 0x23; }
sub VK_HOME { 0x24; }
sub VK_LEFT { 0x25; }
sub VK_UP { 0x26; }
sub VK_RIGHT { 0x27; }
sub VK_DOWN { 0x28; }
sub VK_SELECT { 0x29; }
sub VK_PRINT { 0x2A; }
sub VK_EXECUTE { 0x2B; }
sub VK_SNAPSHOT { 0x2C; }
sub VK_INSERT { 0x2D; }
sub VK_DELETE { 0x2E; }
sub VK_HELP { 0x2F; }
sub VK_LWIN { 0x5B; }
sub VK_RWIN { 0x5C; }
sub VK_APPS { 0x5D; }
sub VK_NUMPAD0 { 0x60; }
sub VK_NUMPAD1 { 0x61; }
sub VK_NUMPAD2 { 0x62; }
sub VK_NUMPAD3 { 0x63; }
sub VK_NUMPAD4 { 0x64; }
sub VK_NUMPAD5 { 0x65; }
sub VK_NUMPAD6 { 0x66; }
sub VK_NUMPAD7 { 0x67; }
sub VK_NUMPAD8 { 0x68; }
sub VK_NUMPAD9 { 0x69; }
sub VK_MULTIPLY { 0x6A; }
sub VK_ADD { 0x6B; }
sub VK_SEPARATOR { 0x6C; }
sub VK_SUBTRACT { 0x6D; }
sub VK_DECIMAL { 0x6E; }
sub VK_DIVIDE { 0x6F; }
sub VK_F1 { 0x70; }
sub VK_F2 { 0x71; }
sub VK_F3 { 0x72; }
sub VK_F4 { 0x73; }
sub VK_F5 { 0x74; }
sub VK_F6 { 0x75; }
sub VK_F7 { 0x76; }
sub VK_F8 { 0x77; }
sub VK_F9 { 0x78; }
sub VK_F10 { 0x79; }
sub VK_F11 { 0x7A; }
sub VK_F12 { 0x7B; }
sub VK_F13 { 0x7C; }
sub VK_F14 { 0x7D; }
sub VK_F15 { 0x7E; }
sub VK_F16 { 0x7F; }
sub VK_F17 { 0x80; }
sub VK_F18 { 0x81; }
sub VK_F19 { 0x82; }
sub VK_F20 { 0x83; }
sub VK_F21 { 0x84; }
sub VK_F22 { 0x85; }
sub VK_F23 { 0x86; }
sub VK_F24 { 0x87; }
sub VK_NUMLOCK { 0x90; }
sub VK_SCROLL { 0x91; }
sub VK_LSHIFT { 0xA0; }
sub VK_RSHIFT { 0xA1; }
sub VK_LCONTROL { 0xA2; }
sub VK_RCONTROL { 0xA3; }
sub VK_LMENU { 0xA4; }
sub VK_RMENU { 0xA5; }
sub VK_PROCESSKEY { 0xE5; }
sub VK_ATTN { 0xF6; }
sub VK_CRSEL { 0xF7; }
sub VK_EXSEL { 0xF8; }
sub VK_EREOF { 0xF9; }
sub VK_PLAY { 0xFA; }
sub VK_ZOOM { 0xFB; }
sub VK_NONAME { 0xFC; }
sub VK_PA1 { 0xFD; }
sub VK_OEM_CLEAR { 0xFE; }
1;