Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Win32 local users and groups modules

by AcidHawk (Vicar)
on Nov 22, 2003 at 12:32 UTC ( #309152=note: print w/replies, xml ) Need Help??


in reply to Win32 local users and groups modules

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.

Replies are listed 'Best First'.
Re: Re: Win32 local users and groups modules
by waswas-fng (Curate) on Nov 24, 2003 at 16:57 UTC
    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.
        Wow, great post, thanks for your help. I will have to run out and get the Win32 book, I never thought I would get stuck doing a project on that platform so it was not in my collection. Thanks again for everything.


        -Waswas

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://309152]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2021-02-27 03:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?