Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Win32 local users and groups modules

by waswas-fng (Curate)
on Nov 21, 2003 at 17:36 UTC ( [id://308976]=perlquestion: print w/replies, xml ) Need Help??

waswas-fng has asked for the wisdom of the Perl Monks concerning the following question:

Hey, I have a project coming up soon that will require me to do a lot of work with local users/groups on Windows 2k. I will need to recreate a very complex structure of users and groups that currently exists on one of our external web sites on a new server. I have looked at my options and think that using perl to suck down group members and relationships for munging and recreation on the other server is the best way. I have a utility that will allow me to dump the users and passwords (nix the group info) from the box. My questions are (coming from a unix background here) I know there are quite a lot of modules for accessing and creating local users and groups -- what would someone that has done a lot of work in this area use for doing this? I just need something that is stable and tested. On a non perl note, I am also interested in anyones ideas for other ways to migrate local users/groups between two 2k boxes without losing passwords. I can't use local -> ad to migrate because of the way the proprietary software uses these users and groups.

Thanks in advance!


-Waswas

Replies are listed 'Best First'.
Re: Win32 local users and groups modules
by AcidHawk (Vicar) on Nov 22, 2003 at 12:32 UTC

    Win32::AdminMisc and heres some code to get you started..

    #! perl.exe use strict; use warnings; use Win32::AdminMisc; my (@users, @groups); print "List of USERS\n"; Win32::AdminMisc::GetUsers("","",\@users); foreach my $usr(@users) { print "$usr\n"; } print "\nList of GLOBAL Groups\n"; Win32::AdminMisc::GetGroups("",GROUP_TYPE_GLOBAL,\@groups); foreach my $grp(@groups) { print "$grp\n"; }

    Update: I have also had some good success with Win32::NetAdmin although can't remember if I got the password stuff working..

    -----
    Of all the things I've lost in my life, its my mind I miss the most.
      Thanks AcidHawk, the only thing is I don't think that module has any ability to actually create groups and modify the userlist associated to the groups. My deal is that I am tasked with migrating a old web app from a old server to a new one. I do not have access to the source code for the application and it relies heavily on local groups and users to provide access restrictions. To gauge the scope of the application it has close to 3500 groups and 900 users. the users may belong to multiple groups and depending on the groups they have access to different parts of the site. My plan was to use a program I have that dumps user/passhash to a file and then reload it to the new machine. then run a perl script that takes username/group relationships and creates an interim file that I can then transfer to the new box and use to recreate the groups. I also have to do the same thing at the filesystem level to set permissions / groups on a ton of files. This is turning out to be a mess -- it would have taken me like 5 minutes on a unix box. Do you have any ideas on modules that can be used to not only get group names but also membership on 2k boxes?


      Thanks!
      -Waswas

        Hi, I looked in my Roths Win32 Perl Scripting book and found several references to backing up and restoring machine and user accounts (pg 129). Also chapter 2 talks about Account Maintenance. I could only find a small reference on pg 200 that talks about group membership. I'll type it up if you like.

        Most of the scripts relating to user and group stuff is Lanman though, maybe worth a look..? (Btw I think Jenda is responsible for this..)

        This may also be worth a look..

        I then looked at my Roths Win32 Perl Programming bookand think I found what you are looking for. On page 126 there is a section about Group Account Management which talks about Adding groups and adding users to groups. So here is a quick snippet. it uses win32::netadmin.

        #! /usr/bin/perl use Win32::NetAdmin; my $machine = "\\\\server1"; my $group = "TestGroup"; my @users = qw(AcidHawk Fred Sally Bill); my $server = ""; Win32::NetAdmin::GroupCreate( $machine, $group, "This is a test group" +) or die "Cannot create group\n"; my $result = Win32::NetAdmin::LocalGroupAddUsers( $server, $group, \@u +sers); if ($result) { print "Successfully added users to $group\n"; } else { print "Failed to add users to $group\n"; }

        Update: cpan:Win32::NetAdmin does have the following which may help

        GroupGetMembers(server, groupName, userArrayRef) Fills userArrayRef with the members of groupName.
        and
        LocalGroupGetMembers(server, groupName, userArrayRef) Fills userArrayRef with the members of groupName.
        as well as
        GroupAddUsers(server, groupName, users) Adds a user to a group.
        and
        LocalGroupAddUsers(server, groupName, users) Adds a user to a group.
        HTH..

        -----
        Of all the things I've lost in my life, its my mind I miss the most.
Re: Win32 local users and groups modules
by Anonymous Monk on Nov 21, 2003 at 18:26 UTC
    what would someone that has done a lot of work in this area use for do +ing this?
    One of the Win32:: Modules specifically designed for doing this or Win32::OLE Win32::WSH ... whatever works.
      Ok, maybe I asked the wrong way, I understand there are many Win32:: tree modules that handle this, I am asking for recomendations for the "best" or "most production ready" module out of that list list for this type of work. Also any problems people have run into managing local users and groups vs ad users and groups with these mods...
      Win32::API,Win32::NetAdmin,Win32API::Net,Win32::AD::User


      -Waswas

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://308976]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-20 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found