Re: List of groups on Win32
by clemburg (Curate) on Feb 16, 2001 at 17:35 UTC
|
Get your copy of Win32 Perl Programming by Dave Roth.
Pages 80-88 (Group Account Management) list want you want.
Seems that you can retrieve a list of groups by using the Win32::AdminMisc::GetGroups() function.
Christian Lemburg
Brainbench MVP for Perl
http://www.brainbench.com
| [reply] [d/l] |
|
|
For anyone who's interested, I posted a review on Win32 Perl Scripting: Administrator's Handbook by Dave Roth and its here
$code or die
Using perl at
The Spiders Web
| [reply] |
|
|
But I have a problem with AdminMisc - it seemed to install OK, but every time I call my little program:
#!/usr/bin/perl -w
use Win32::AdminMisc qw(GetDC GetGroups);
my $dc;
my @groups;
$dc = GetDC();
GetGroups($dc, GROUP_TYPE_ALL, \@groups);
my $item;
foreach $item(@groups) {
print "$item\n";
}
I get an error message:
bash-2.02$ perl dominfo.pl
"GetDC" is not exported by the Win32::AdminMisc module at dominfo.pl line 3
"GetGroups" is not exported by the Win32::AdminMisc module at dominfo.pl line 3
Can't continue after import errors at dominfo.pl line 3
BEGIN failed--compilation aborted at dominfo.pl line 3.
bash-2.02$
I'm not up on how perl modules and such work, so I don't know how to fix this :-( | [reply] |
|
|
First off: baku's given you a good fix
Here's the 'why' ... Perl modules that export symbols usually use the Exporter module internally. Such modules maintain lists of symbols (names of variables and subroutines) they automatically export (@EXPORT) and ones that they may export if asked to (@EXPORT_OK). (exported symbols can be accessed without fully qualifying their names).
The module you're using doesn't list either of the symbols you're asking it to export (with the qw() construct) in its list of exportable symbols, hence the error.
Philosophy can be made out of anything. Or less -- Jerry A. Fodor
| [reply] [d/l] [select] |
|
|
| [reply] [d/l] [select] |
|
|
I'm not up on how perl modules and such work,
This can also be said for many authors of Win32:: modules. ): You'd think Dave Roth would know better by now, but perhaps it is just "history" for this particular module.
A simple @EXPORT_OK= qw( list of subs ) would make this module easier to use (and fit the common expectations for a Perl module).
-
tye
(but my friends call me "Tye")
| [reply] [d/l] |
|
|
Those messages indicate that the module uses Exporter
but did not put those functions in @EXPORT_OK to indicate
that they could be exported. I would first check the
module's documentation to see whether you have the names
correct (including documentation) and if you do I would
just stop trying to import them and use them directly,
or I would add the lines:
*GetDC = *Win32::AdminMisc::GetDC;
*GetGroups = *Win32::AdminMisc::GetGroups;
to manually import. (Well I would also go into the
module, add a patch, and then send a bug report to the
author, but that is just me...) | [reply] [d/l] |
|
|
|
|
|
|
Re: List of groups on Win32
by rrwo (Friar) on Feb 17, 2001 at 22:49 UTC
|
I think Win32::Lanman (see http://jenda.krynicky.cz/)
might be more appropriate.
You probably want to check out <cite>Win32 Perl Scripting:
The Administrator's Handbook</cite> by Dave Roth (see the
author's home page at http://www.roth.net/packages).
It's got a lot of useful information and using Perl for various
sysadmin tasks.
| [reply] |
That's one small step for a pwhysall...
by pwhysall (Acolyte) on Feb 20, 2001 at 19:42 UTC
|
The first task was to print a comma separated list of users and groups:
#!/usr/bin/perl -w
use Win32::AdminMisc;
use Win32::NetAdmin qw (GroupGetMembers);
use strict;
my $dc;
my @groups;
$dc = Win32::AdminMisc::GetDC();
Win32::AdminMisc::GetGroups($dc, GROUP_TYPE_ALL, \@groups);
my $item;
my %groups_with_users;
foreach $item(@groups) {
my @tmp_user_list;
GroupGetMembers($dc, $item, \@tmp_user_list);
$groups_with_users{$item} = [@tmp_user_list];
}
my $group;
open USERGROUP, ">usergroup.csv" || die "Can't open file for writing:$
+!";
print USERGROUP "Group, User\n";
foreach $item(keys %groups_with_users) {
my $i;
foreach $i (0 .. $#{ $groups_with_users{$item} } ) {
print USERGROUP "$item, $groups_with_users{$item}[$i]\n";
}
}
close USERGROUP;
| [reply] [d/l] |