NAME

Win32::GuiTest::Cmd - Perl Batch File Enhancer. Part of Win32::GuiTest.

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?");

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:

use Win32::NetAdmin;

use Win32::NetResource;

use Win32::ODBC;

use Socket;

use Sys::Hostname;

use File::Path 'mkpath';

use Getopt::Std 'getopts';

FUNCTIONS

Console

Console interaction functions heavily based on the command-line installer for the libwin32 distribution written by Gurusamy Sarathy.

Pause([$message])

Shows a message and waits until the user presses ENTER.

YesOrDie([$message])

Asks for a [y/n] response using the message you specify. The program dies if you answer 'n'.

YesOrNo([$msg])

Asks for a [y/n] response using the message you specify. Returns 1 if you type 'y' or 0 otherwise.

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.

IsExe($filename)

Checks if a file is executable.

AskForExe([$question],[$def_exe])

Just like AskForIt, but returns false if the value is not an executable file.

AskForDir([$question],[$def_dir])

Just like AskForIt, but returns false if the value is not a directory.

AskAndRun([$question],[$def_exe])

Asks for an exe file an runs it using system.

System Configuration

Mostly allow opening Win32 Control Panel Applets programatically.

RunCpl($applet)

Opens a Control Panel Applet (.cpl) by name.

RunCpl("modem.cpl");
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.

Ras

Installs or configures the RAS (Remote Access Service) component.

Users

Runs the User/Group Manager application.

Registry

Manipulate the registry.

RegisterCom($path)

Uses regsvr32.exe to register a COM server.

RegisterCom("c:\\myfiles\\mycontrol.ocx");
UnregisterCom($path)

Uses regsvr32.exe to unregister a COM server.

UnregisterCom("c:\\myfiles\\mycontrol.ocx");
AddToRegistry($regfile)

Uses regedit.exe to merge a .reg file into the system registry.

AddToRegistry("c:\\myfiles\\test.reg");

Misc

Sorry about that...

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
TempFileName

Returns the full path for a temporary file that will not collide with an existing file.

AUTHOR

Ernesto Guisado <erngui@acm.org>, <http://triumvir.org>