Win32::GuiTest::Cmd - Perl Batch File Enhancer. Part of Win32::GuiTest.
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?");
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:
use Win32::NetAdmin;
use Win32::NetResource;
use Win32::ODBC;
use Socket;
use Sys::Hostname;
use File::Path 'mkpath';
use Getopt::Std 'getopts';
Console interaction functions heavily based on the command-line installer for the libwin32 distribution written by Gurusamy Sarathy.
Shows a message and waits until the user presses ENTER.
Asks for a [y/n] response using the message you specify. The program dies if you answer 'n'.
Asks for a [y/n] response using the message you specify. Returns 1 if you type 'y' or 0 otherwise.
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.
Checks if a file is executable.
Just like AskForIt, but returns false if the value is not an executable file.
Just like AskForIt, but returns false if the value is not a directory.
Asks for an exe file an runs it using system.
system
Mostly allow opening Win32 Control Panel Applets programatically.
Opens a Control Panel Applet (.cpl) by name.
RunCpl("modem.cpl");
Each of them opens the corresponding Control Panel Applet.
Installs or configures the RAS (Remote Access Service) component.
Runs the User/Group Manager application.
Manipulate the registry.
Uses regsvr32.exe to register a COM server.
RegisterCom("c:\\myfiles\\mycontrol.ocx");
Uses regsvr32.exe to unregister a COM server.
UnregisterCom("c:\\myfiles\\mycontrol.ocx");
Uses regedit.exe to merge a .reg file into the system registry.
AddToRegistry("c:\\myfiles\\test.reg");
Sorry about that...
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
Returns the full path for a temporary file that will not collide with an existing file.
Ernesto Guisado <erngui@acm.org>, <http://triumvir.org>
To install Win32::GuiTest, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Win32::GuiTest
CPAN shell
perl -MCPAN -e shell install Win32::GuiTest
For more information on module installation, please visit the detailed CPAN module installation guide.