Win32 - Interfaces to some Win32 API Functions
Perl on Win32 contains several functions to access Win32 APIs. Some are included in Perl itself (on Win32) and some are only available after explicitly requesting the Win32 module with:
use Win32;
The builtin functions are marked as [CORE] and the other ones
as [EXT] in the following alphabetical listing. The Win32
module
is not part of the Perl source distribution; it is distributed in
the libwin32 bundle of Win32::* modules on CPAN. The module is
already preinstalled in binary distributions like ActivePerl.
[EXT] Takes STRING and replaces all referenced environment variable
names with their defined values. References to environment variables
take the form %VariableName%
. Case is ignored when looking up the
VariableName in the environment. If the variable is not found then the
original %VariableName%
text is retained. Has the same effect
as the following:
$string =~ s/%([^%]*)%/$ENV{$1} || "%$1%"/eg
[CORE] Converts the supplied Win32 error number (e.g. returned by
Win32::GetLastError()) to a descriptive string. Analogous to the
perror() standard-C library function. Note that $^E
used
in a string context has much the same effect.
C:\> perl -e "$^E = 26; print $^E;" The specified disk or diskette cannot be accessed
[CORE] Returns the name of the filesystem of the currently active drive (like 'FAT' or 'NTFS'). In list context it returns three values: (FSTYPE, FLAGS, MAXCOMPLEN). FSTYPE is the filesystem type as before. FLAGS is a combination of values of the following table:
0x00000001 supports case-sensitive filenames 0x00000002 preserves the case of filenames 0x00000004 supports Unicode in filenames 0x00000008 preserves and enforces ACLs 0x00000010 supports file-based compression 0x00000020 supports disk quotas 0x00000040 supports sparse files 0x00000080 supports reparse points 0x00000100 supports remote storage 0x00008000 is a compressed volume (e.g. DoubleSpace) 0x00010000 supports object identifiers 0x00020000 supports the Encrypted File System (EFS)
MAXCOMPLEN is the maximum length of a filename component (the part between two backslashes) on this file system.
[CORE] GetFullPathName combines the FILENAME with the current drive and directory name and returns a fully qualified (aka, absolute) path name. In list context it returns two elements: (PATH, FILE) where PATH is the complete pathname component (including trailing backslash) and FILE is just the filename part. Note that no attempt is made to convert 8.3 components in the supplied FILENAME to longnames or vice-versa. Compare with Win32::GetShortPathName and Win32::GetLongPathName.
This function has been added for Perl 5.6.
$^E
used in a numeric context amounts to the
same value.
[CORE] Returns a representation of PATHNAME composed of longname components (if any). The result may not necessarily be longer than PATHNAME. No attempt is made to convert PATHNAME to the absolute path. Compare with Win32::GetShortPathName and Win32::GetFullPathName.
This function has been added for Perl 5.6.
[CORE] Returns the array (STRING, MAJOR, MINOR, BUILD, ID), where the elements are, respectively: An arbitrary descriptive string, the major version number of the operating system, the minor version number, the build number, and a digit indicating the actual operating system. For the ID, the values are 0 for Win32s, 1 for Windows 9X and 2 for Windows NT/2000/XP. In scalar context it returns just the ID.
Currently known values for ID MAJOR and MINOR are as follows:
OS ID MAJOR MINOR Win32s 0 - - Windows 95 1 4 0 Windows 98 1 4 10 Windows Me 1 4 90 Windows NT 3.51 2 3 51 Windows NT 4 2 4 0 Windows 2000 2 5 0 Windows XP 2 5 1 Windows .NET Server 2 5 1
Unfortunately as of June 2002 there is no way to distinguish between .NET servers and XP servers without using additional modules.
[EXT] In scalar context returns the name of the Win32 operating system being used. In list context returns a two element list of the OS name and whatever edition information is known about the particular build (for Win9x boxes) and whatever service packs have been installed. The latter is roughly equivalent to the first item returned by GetOSVersion() in list context.
Currently the possible values for the OS name are
Win32s Win95 Win98 WinMe Win2000 WinXP/.Net WinNT3.51 WinNT4
This routine is just a simple interface into GetOSVersion(). More specific or demanding situations should use that instead. Another option would be to use POSIX::uname(), however the latter appears to report only the OS family name and not the specific OS. In scalar context it returns just the ID.
(MACHINE, MESSAGE, TIMEOUT, FORCECLOSE, REBOOT)
[EXT] Shutsdown the specified MACHINE, notifying users with the supplied MESSAGE, within the specified TIMEOUT interval. Forces closing of all documents without prompting the user if FORCECLOSE is true, and reboots the machine if REBOOT is true. This function works only on WinNT.
[EXT] Create a dialogbox containing MESSAGE. FLAGS specifies the required icon and buttons according to the following table:
0 = OK 1 = OK and Cancel 2 = Abort, Retry, and Ignore 3 = Yes, No and Cancel 4 = Yes and No 5 = Retry and Cancel
MB_ICONSTOP "X" in a red circle MB_ICONQUESTION question mark in a bubble MB_ICONEXCLAMATION exclamation mark in a yellow triangle MB_ICONINFORMATION "i" in a bubble
TITLE specifies an optional window title. The default is "Perl".
The function returns the menu id of the selected push button:
0 Error
1 OK 2 Cancel 3 Abort 4 Retry 5 Ignore 6 Yes 7 No
[CORE] Sets the ShowMode of child processes started by system().
By default system() will create a new console window for child
processes if Perl itself is not running from a console. Calling
SetChildShowWindow(0) will make these new console windows invisible.
Calling SetChildShowWindow() without arguments reverts system() to the
default behavior. The return value of SetChildShowWindow() is the
previous setting or undef
.
[EXT] The following symbolic constants for SHOWWINDOW are available (but not exported) from the Win32 module: SW_HIDE, SW_SHOWNORMAL, SW_SHOWMINIMIZED, SW_SHOWMAXIMIZED and SW_SHOWNOACTIVATE.