http://qs321.pair.com?node_id=96032

physi has asked for the wisdom of the Perl Monks concerning the following question:

Brothers,
I'm trying to get the full name of the current user on NT. Normaly I can use  $<, $> from that kind of stuff. But this does not work on NT. So I can use  $ENV{USERNAME} instead. This gives me the logon name. In the Usermanager there is a field where the whole Username is specified. I need to access this Information. I tried out Win32::NetAdmin but this shows me only the names of my local machine. I'm currently working in a big department, so there are many different Recourcedomains and one Masterdomain. The Accounts are on the masterdomain. So what can I do to get the Information I need? When I use this:
use Win32::NetAdmin qw(GetUser); GetUser('',undef,\%hash);
I get a hash filled with the users of the local machine.

So I thought that:

use Win32::NetAdmin qw(GetUser); GetUser('masterdomainservername',undef,\%hash);
... should give me all the users in the masterdomain. But it doesn't. I get an empty hash. Do I need admin privileges to do that? Or what can I do to get the Infomation I need without having admin-privileges ?

Any help is welcome :-)

Cheers,

----------------------------------- --the good, the bad and the physi-- -----------------------------------

Replies are listed 'Best First'.
Re: userinfo on NT
by the_slycer (Chaplain) on Jul 12, 2001 at 18:26 UTC
    Update Ok, This is better now. Here's how to use Win32::Lanman to do this.
    use Win32::Lanman; my $domain="DOMAINNAME"; my $pdc; my $username; my %info; Win32::Lanman::NetGetDCName('',$my_domain,\$pdc); Win32::Lanman::NetUserGetInfo($pdc, $username, \%info); print "$_ == $info{$_}\n" foreach keys %info;
    This is of couse assuming that you are after what you asked (ie full name of $env{username} ) vs the code you posted (ie enumerating all users in the domain)
      Looks like this will do exactly what I need (I really need only the full name, not all the users from the domain).

      BUT ...

      where can I get Win32::Lanman ??
      I found the pod on the web, but no source :(
      Please gimme a hint :)
      Thanks.
      ----------------------------------- --the good, the bad and the physi-- -----------------------------------
      Update: found it under: http://sunsite.compapp.dcu.ie/pub/perl/modules/by-module/Win32/JHELBERG/
Re: userinfo on NT
by OzzyOsbourne (Chaplain) on Jul 12, 2001 at 18:37 UTC

    You do need admin privleges. You seem to be doing things correctly. GetUserwill return the full names to a hash ref. I posted an similar, extended example of how to get this type information here, but it's no good without the rights.

    -OzzyOsbourne

      Ozzy.... Your scripts rock. I was thinking of doing something like this and thinking of a clean way to do it. I am just a novice monk but i am constantly looking for things that will make me more efficent with perl on my win32 systems. Always willing to listen and learn more perl.. ~Ray~
      Question... I am new to perl(about a month or so) and i have finished the Learning Perl for Win32...where else, in your opinion, should i go to further my learning for perl in retrospect to being able to apply it on my NT/2k machines. I bought "Windows NT - Win32 Perl Programming: The Standard Extensions" and it is a little more advanced in programming. Maybe i guess...i am looking for...something that will keep going in progression...kinda like how the Learning Perl book does...learn a little something new and test my knowledge on it with everything that i previously learned as well. I am able to apply scripts that i find or other people provide for me as examples by tweeking them, but i probably would not be able to get there by myself. Does that make sense? This may be a lot of jarble..but since you do program for NT/2k environment, i figured you would be a good person to ask. Any advice would be much appreciated. As i am always open to listen. thnx ~Ray~
        I'm not a Win32 SysAdmin, but a cow-orker who is bought the following book.   He says it helps a lot in his initial efforts at Perl.
            cheers,
            Don
            striving toward Perl Adept
            (it's pronounced "why-bick")

        Win32 Perl Scripting: The Administrators Handbook
        ISBN: 1578702151
        Author: Dave Roth
        Publisher: New Riders

        I understand exactly what you are saying, You wish to continue from Perl 101 to 102, and 110, and then 210, etc. Unfortunately, there aren't many win32 books out there, and I haven't read one of them (I probably should!). I actually learn by taking on projects that are much bigger than my knowledge base, and asking a lot of questions here at PM

        Honestly, my code consists of 90% plain old Perl, and 10% lines dealing with win32. When I want to expand my Perl horizons, I don't look to win32; I look to Perl. Better looping or learning internal variables (I recently learned about $.) and such have helped much more than knowing exactly when to use GetUser vs. GetUserAttributes. If I know what I'm generally looking for, I can find the specifics in the docs.

        But, I find that books are a hard to recommend, as we all have different styles of learning. I learned Perl from the SAMS Teach Yourself Perl in 21 days, which worked incredibly well for me. If I went by the reviews on this book, I would never have bought it. I would have spit on it and set it on fire. If I went by the reviews, I should've bought the camel book, which was not visually broken down for skimming, and didn't fit my learning style. All I can say is: grab a cup of joe, head to the bookstore, give them all a good read, and then buy them online.

        Although, Merlyn wrote a win32 book that I have been meaning to pick up...

        I wish I could be more helpful...

        -OzzyOsbourne

Re: userinfo on NT
by mikeB (Friar) on Jul 12, 2001 at 18:23 UTC
    It's been a while since I've done NT domain administration, but IIRC, you need domain admin privilages to do this.
Re: userinfo on NT
by joefission (Monk) on Jul 12, 2001 at 23:15 UTC
    One with Win32::AdminMisc...

    use Win32::AdminMisc; use strict; $|=1; my $domain = "MasterDomain"; my $userid = shift; my %attribs = (); chomp $userid; print "$userid\t\t"; if (Win32::AdminMisc::UserGetMiscAttributes($domain, $userid, \%attrib +s)) { print "$attribs{USER_FULL_NAME}\n"; }else{ print "not found\n"; }