How to get user and group information in Perl on Windows?

Perl has several built-in functions for accessing / etc / passwd on Unix systems (and elsewhere, when supported) for user and group information. For instance,

my $name = getpwuid($uid); 

will return the username based on the user ID or undef if there is no such user.

If a Perl script needs to be portable and run on Unices and Windows, how do I access user and group information? ActivePerl seems to support the User :: grent and User :: pwent modules, which provide access to / etc / passwd by field, even on Windows. Curiously, they do not support the getpw * and getgr * built-in functions. What other alternatives are there?

+4
source share
2 answers

You can use the Win32::NetAdmin module .

UserGetAttributes and GroupIsMember look as if they are doing what you need.

+5
source

Oddly enough, the Interix Perl build that ships with Microsoft Services for Unix supports getpw * and friends.

0
source

Source: https://habr.com/ru/post/1277520/


All Articles