home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

Learning Perl on Win32 Systems

Learning Perl on Win32 SystemsSearch this book
Previous: 15.6 Exercises Chapter 16 Next: 16.2 Packing and Unpacking Binary Data
 

16. System Information

16.1 Getting User and Machine Information

Perl provides several facilities for finding out information about the user and machine that you are running on. These functions are provided via Win32 extensions (see Appendix B, Libraries and Modules , for more information).

To retrieve the name of the user executing the script, use the Win32::LoginName function:

use Win32;
$name = Win32::LoginName;

To retrieve the name of the machine executing the script, use the Win32::NodeName function:

use Win32;
$machine = Win32::NodeName;

The Win32::NetAdmin module provides extensive functionality for administering users and groups. Here's an simple example of how you might use it to retrieve the current user's home directory:

use Win32::NetAdmin;
$user = Win32::LoginName; # grab the name of the current user
Win32::NetAdmin::UserGetAttributes("",
    $username, $password, $passwordage,
    $privilege, $homedir, $comment,
    $flags, $scriptpath);
print "The homedir for $username is $homedir\n";

For more information on using Win32::NetAdmin , explore the win32mod documentation.

As you explore Perl scripts on the Net, you'll no doubt find scripts that refer to any of a myriad of Perl functions that access UNIX password and group files. At the time of this writing, these functions are not implemented in Perl on Win32 platforms, but you can usually duplicate the functionality (if it's applicable) using one of the Win32 extension modules.











??????????????@Mail.ru