Using Perl to create user accounts on Windows 2003

  • Follow


Hello all,

I have Windows 2003 FTP servers that I store content on for external
users to pick up on a schedule.  Unfortunately I have about 300 of
such users, and multiple servers.  The time and energy to create these
user accounts is obviously a factor, especially if I have to rebuild a
box and have it up and running quickly.

So, I went looking for Perl scripts / modules that could do this, but
all I came up with was some old (for NT4) ones that used
Win32::Lanman.  I'm not creating domain (Active Directory) accounts,
just local ones on the box.  I have the users in a comma-delimited
file, and really just need a shove in the right direction.

Any suggestions would be most appreciated.
0
Reply rev_maynard3 6/22/2004 9:33:29 PM

Maynard wrote:
> Hello all,
> 
> I have Windows 2003 FTP servers that I store content on for external
> users to pick up on a schedule.  Unfortunately I have about 300 of
> such users, and multiple servers.  The time and energy to create these
> user accounts is obviously a factor, especially if I have to rebuild a
> box and have it up and running quickly.
> 
> So, I went looking for Perl scripts / modules that could do this, but
> all I came up with was some old (for NT4) ones that used
> Win32::Lanman.  I'm not creating domain (Active Directory) accounts,
> just local ones on the box.  I have the users in a comma-delimited
> file, and really just need a shove in the right direction.
> 
> Any suggestions would be most appreciated.

What's wrong with Win32::Lanman? AFAIK it should work under W2k+3.
Alternatively use Win32::OLE to do it via the WMI interface.

Thomas

-- 
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</  #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..
0
Reply Thomas 6/23/2004 9:16:08 AM


rev_maynard3@hotmail.com (Maynard) wrote in message news:<a4847dc.0406221333.227bc2c7@posting.google.com>...
> Hello all,
> 
> I have Windows 2003 FTP servers that I store content on for external
> users to pick up on a schedule.  Unfortunately I have about 300 of
> such users, and multiple servers.  The time and energy to create these
> user accounts is obviously a factor, especially if I have to rebuild a
> box and have it up and running quickly.
> 
> So, I went looking for Perl scripts / modules that could do this, but
> all I came up with was some old (for NT4) ones that used
> Win32::Lanman.  I'm not creating domain (Active Directory) accounts,
> just local ones on the box.  I have the users in a comma-delimited
> file, and really just need a shove in the right direction.
> 
> Any suggestions would be most appreciated.

Win32::NetAdmin.  Available on CPAN.

(The name is derived from the corresponding Win32 API calls)

Regards,

Dan
0
Reply djberg96 6/23/2004 5:13:01 PM

Maynard wrote:
> Hello all,
> 
> I have Windows 2003 FTP servers that I store content on for external
> users to pick up on a schedule.  Unfortunately I have about 300 of
> such users, and multiple servers.  The time and energy to create these
> user accounts is obviously a factor, especially if I have to rebuild a
> box and have it up and running quickly.
> 
> So, I went looking for Perl scripts / modules that could do this, but
> all I came up with was some old (for NT4) ones that used
> Win32::Lanman.  I'm not creating domain (Active Directory) accounts,
> just local ones on the box.  I have the users in a comma-delimited
> file, and really just need a shove in the right direction.
> 
> Any suggestions would be most appreciated.

Win32::Lanman is really nice as I recall, and I think it's had some 
updating done since WNT 4.0.  Almost positive.  Anyway, I'm recalling my 
thoughts from about 2-3 years back.

I think if you depend on the ActiveState documentation (assuming that is 
what you are using, which it is almost sure to be), it may take you some 
time to come to grips with actually pulling it off.  Again, as I recall, 
it took some time experimenting before I got user adds (deletes, etc.) 
exactly right.

Enclosed is a snippet which might help.  Some extraneous lines removed. 
  Just view the hash reference passed in as a data structure holding the 
relevant information I had gathered before calling the Win32API::Net 
module (is what I chose at the time for doing my adds).  This shouldn't 
be too hard to follow:

(I know you want just a local machine add -- but keep reading)

use Win32API::Net qw( :User );

sub AddUserToDomain {

    ## Get parameters.

    my $req = shift;  # A request hash reference

    ## Load up local info hash needed by UserAdd, GetInfo, etc.

    my $h = {
       name            => $req->{userid},
       password        => $req->{password},
       passwordAge     => 0,
       priv            => USER_PRIV_USER(),
       homeDir         => $req->{homedir},
       comment         => $req->{comment},
       flags           => (UF_SCRIPT & UF_NORMAL_ACCOUNT),
       scriptPath      => $req->{loginscript},
       authFlags       => 0,
       fullName        => $req->{fullname},
       usrComment      => $req->{comment},
       parms           => $Script{DESC},
       workstations    => '',
       lastLogon       => 0,
       lastLogoff      => 0,
       acctExpires     => -1,
       maxStorage      => -1,
       unitsPerWeek    => 0,
       logonHours      => [ 0x0F, 0x0F, 0x0F,
                            0x0F, 0x0F, 0x0F,
                            0x0F, 0x0F, 0x0F,
                            0x0F, 0x0F, 0x0F,
                            0x0F, 0x0F, 0x0F,
                            0x0F, 0x0F, 0x0F,
                            0x0F, 0x0F, 0x0F, ],
       badPwCount      => 0,
       numLogons       => 0,
       logonServer     => '',
       countryCode     => 0,
       codePage        => 0,
       userId          => 0,
       primaryGroupId  => 0x201,
       profile         => $req->{userprofile},
       homeDirDrive    => $req->{homedrive},
       passwordExpired => $req->{expirepwd},
    };

    ## Add the user and get the return value.
    ## (This is Win32API::Net::UserAdd())

    my $rv = 0;                          # Return value (assume OK)
    UserAdd( $req->{pdc}, 3, $h, $rv );  # Add the user

    ## Return success or error code.

    $rv;

}
__END__

I believe $Script{DESC} above was just some descriptive text about the 
script running which ended up in the record of the user account created. 
   Something like that.  Now that I look, I see the examples in 
Win32API::Net are a bit more descriptive than Win32::NetAdmin.

I believe if you substitute the name of your local machine 
($ENV{COMPUTERNAME}) with the "$req->{pdc}" above, this will work for a 
local machine add?  Sorry, I don't have time to test this in that scenario.

HTH,
-ceo
0
Reply ChrisO 6/24/2004 3:33:37 AM

Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de> wrote in message news:<40d94a58$0$14527$bb690d87@news.main-rheiner.de>...
> Maynard wrote:
> > Hello all,
> > 
> > I have Windows 2003 FTP servers that I store content on for external
> > users to pick up on a schedule.  Unfortunately I have about 300 of
> > such users, and multiple servers.  The time and energy to create these
> > user accounts is obviously a factor, especially if I have to rebuild a
> > box and have it up and running quickly.
> > 
> > So, I went looking for Perl scripts / modules that could do this, but
> > all I came up with was some old (for NT4) ones that used
> > Win32::Lanman.  I'm not creating domain (Active Directory) accounts,
> > just local ones on the box.  I have the users in a comma-delimited
> > file, and really just need a shove in the right direction.
> > 
> > Any suggestions would be most appreciated.
> 
> What's wrong with Win32::Lanman? AFAIK it should work under W2k+3.
> Alternatively use Win32::OLE to do it via the WMI interface.
> 
> Thomas

Can you provide a link for Win32::Lanman?  It's not on CPAN, and I
couldn't seem to find it on roth.net.  Is it part of a larger package
that I'm missing?  Google had lots of references to it, but no place
to actually download it.

As for WMI, I don't think you can create user accounts with it.  You
can only list them.  Please correct me if I'm wrong.

Regards,

Dan
0
Reply djberg96 6/25/2004 1:40:59 PM

Daniel Berger wrote:

> Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de> wrote in message news:<40d94a58$0$14527$bb690d87@news.main-rheiner.de>...
> 
>>Maynard wrote:
>>
>>>Hello all,
>>>
>>>I have Windows 2003 FTP servers that I store content on for external
>>>users to pick up on a schedule.  Unfortunately I have about 300 of
>>>such users, and multiple servers.  The time and energy to create these
>>>user accounts is obviously a factor, especially if I have to rebuild a
>>>box and have it up and running quickly.
>>>
>>>So, I went looking for Perl scripts / modules that could do this, but
>>>all I came up with was some old (for NT4) ones that used
>>>Win32::Lanman.  I'm not creating domain (Active Directory) accounts,
>>>just local ones on the box.  I have the users in a comma-delimited
>>>file, and really just need a shove in the right direction.
>>>
>>>Any suggestions would be most appreciated.
>>
>>What's wrong with Win32::Lanman? AFAIK it should work under W2k+3.
>>Alternatively use Win32::OLE to do it via the WMI interface.
>>
>>Thomas
> 
> 
> Can you provide a link for Win32::Lanman?  It's not on CPAN, and I
> couldn't seem to find it on roth.net.  Is it part of a larger package
> that I'm missing?  Google had lots of references to it, but no place
> to actually download it.

It's on CPAN, but doesn't follow the usual naming conventions und I think 
this prevents search.cpan.org from finding it. Look in:

http://cpan.org/modules/by-authors/id/J/JH/JHELBERG/

or

http://cpan.org/modules/by-module/Win32/

the filename is 'lanman.1.0.10.0.zip'

It includes the source without supporting the standard procedure ( perl 
makefile.pl, make, make test, make install), but I could compile it easily 
with MSV6. There are even compiled versions with a ppd file included.

> 
> As for WMI, I don't think you can create user accounts with it.  You
> can only list them.  Please correct me if I'm wrong.

You are right, I suppose. You can do it with ADSI though. Look at

http://www.microsoft.com/technet/community/scriptcenter/user/default.mspx

The VB syntax is easily translatable to Perl and Win32::OLE.

Thomas
-- 
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</  #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..
0
Reply Thomas 6/25/2004 2:38:21 PM

5 Replies
3229 Views

(page loaded in 0.146 seconds)

Similiar Articles:













7/23/2012 7:33:05 AM


Reply: