Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

userdel for NT/2K

by idnopheq (Chaplain)
on Apr 23, 2001 at 15:04 UTC ( #74685=sourcecode: print w/ replies, xml ) Need Help??

Category: NT Admin
Author/Contact Info idnopheq
Description: userdel -- Delete a user account.

userdel modifies the system account files, deleting all entries that refer to login. The named user must exist.

#!/usr/local/bin/perl -w
#-*-perl-*-
#

use strict;
use Win32API::Net;
use Win32::NetAdmin;

my ($VERSION) = '$Revision: 1.0 $' =~ /([.\d]+)/;

my $warnings = 0;

die "Must have perl 5.006\nSorry\n" if $] < 5.006;

# Print a usuage message on a unknown option.

$SIG {__WARN__} = sub {
    if (substr ($_ [0], 0, 14) eq "Unknown option") {die "Usage"};
    require File::Basename;
    $0 = File::Basename::basename ($0);
    $warnings = 1;
    warn "$0: @_";
};

$SIG {__DIE__} = sub {
    require File::Basename;
    $0 = File::Basename::basename ($0);
    if (substr ($_ [0], 0,  5) eq "Usage") {
        die <<EOF;
$0 (NT Perl bin utils) $VERSION
$0 [ -r ] username
EOF
    }
    die "$0: @_";
};

# Get the options.

die "Usage" unless @ARGV;
die "Usage" if $ARGV[0] eq "-?";

# don't waste time if the user doesn't exist

my $Server     = "";

if ( ! Existance() ) {
    print "$0: $ARGV[0] does not exist\n";
    exit;
}

print "$0: $ARGV[0] could not be removed:\n$^E\n" unless DelUser();

sub Existance {
  return "1" if Win32::NetAdmin::UsersExist ( 
                         $Server,
                         $ARGV[0] 
                        )
    or return;
}

sub DelUser {
    return "1" if Win32API::Net::UserDel (
                      $Server,
                      $ARGV[0]
                     )
      or return;
}

=pod

=head1 NAME

B<userdel> -- Delete a user account.

=head1 SYNOPSIS

B<userdel> [ I<userid> ] [ -h ]

=head1 DESCRIPTION

B<userdel> modifies  the system account files, deleting all entries 
that refer to login.  The named  user must exist.

=head2 OPTIONS

The following options are supported:

=item -h

Display syntax.

=back

=head1 EXAMPLE

Below are exampls of B<userdel>:


=head1 ENVIRONMENT

The working of B<userdel> is not influenced by any environment variabl
+es.

=head1 BUGS

B<userdel> isn't as nice as I would like, but Win32 isn't Unix, now is
+ it?  This I<really> doesn't like Samba domain controllers, which is 
+why I added the 'unknown' entry in the output.

Samba causes problems, which is why an entry might return "unknown".

=head1 STANDARDS

It does not make sense to talk about standards in a B<userdel> manual 
+page.

=head1 REVISION HISTORY

    lastlogin
    Revision 1.0  2000/06/22 12:13:22  idnopheq
    Initial revision

=head1 AUTHOR

The Perl implementation of B<userdel> was written by Dexter Coffin, I<
+idnopheq@home.com>.

=head1 COPYRIGHT and LICENSE

This program is copyright by Dexter Coffin 2000.

This program is free and open software. You may use, copy, modify, dis
+tribute,
and sell this program (and any modified variants) in any way you wish,
provided you do not restrict others from doing the same.

=head1 SEE ALSO

=head1 NEXT TOPIC

=cut

Comment on userdel for NT/2K
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (18)
As of 2015-07-06 13:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (75 votes), past polls