Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

The getpwnam function is unimplemented (in Windows)

by Becky (Beadle)
on Jan 19, 2004 at 18:11 UTC ( #322402=perlquestion: print w/replies, xml ) Need Help??
Becky has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I've been given a perl program that a colleague runs perfectly well on unix. It says it's fine to run on windows but I get the following error:

The getpwnam function is unimplemented

I've done a bit of searching and it seems that getpwnam isn't implemented with ActivePerl.

Another website said that the equivalent of getpwnam on windows is NetUserGetInfo(). Is this correct or is there a way I can get getpwnam?


Edit by tye, title, some P tags

  • Comment on The getpwnam function is unimplemented (in Windows)

Replies are listed 'Best First'.
Re: getpwnam
by JamesNC (Chaplain) on Jan 19, 2004 at 18:29 UTC
    use Win32; my $userName = Win32::LoginName(); print "Current User: ", $userName, "\n";
      Good one...I tried this and it worked like a charm !!! Thanks !!!
Re: getpwnam
by derby (Abbot) on Jan 19, 2004 at 18:45 UTC
    It's hard to say what the correct way is. getpwnam returns the password structure (and that's different things on different *Nixes but basically user name, user id, group id, encrypted password, real name, home directory, and shell). Exactly what do you need for your script?


      The only place it's called is in the following subroutine:

      sub map_user_group { if( ! defined( $uid ) ){ if( $user =~ /^\d+$/ ){ # User is just a number - presume it is the uid $uid = $user; } else { $uid = (getpwnam( $user ))[ 2 ]; } } if( ! defined( $gid ) ){ if( $group =~ /\d+$/ ){ # Group is just a number - presume it is the gid $gid = $group; } else { $gid = (getgrnam( $group ))[ 2 ]; } } }

      Any ideas would be much appreciated!

        that snippet of code sets the userid and groupid ... concepts that are foreign to a lot of windows systems. It's not so much that ActivePerl doesn't implement getpwnam (and getgrnam) but that there's no need for it on a windows platform. Exactly what is the script doing with $uid and $gid?


Re: getpwnam
by jweed (Chaplain) on Jan 19, 2004 at 18:20 UTC

      I'm afraid that that isn't going to help being, as it says on the tin, a " by-name interface to Perl's built-in getpw*() functions".

      I think making a wrapper round some Win32::* modules method so it has the same interface as getpwnam() will be the way to go.


Re: The getpwnam function is unimplemented (in Windows)
by ysth (Canon) on Jan 20, 2004 at 00:32 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://322402]
Approved by jweed
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2018-05-24 18:08 GMT
Find Nodes?
    Voting Booth?