kabeldag has asked for the wisdom of the Perl Monks concerning the following question:

Creating Windows accounts is never fun when doing it via a user manager GUI. It is obviously mundane and slow. Especially when you may need to add multiple amounts of users at a time.

What needs to happen in this case is to read in each user_id and the account parameters, then go ahead and create them in a batch process. At our organisation we use a text file to replicate the accounts to a Novell system from a Windows domain controller via a simple comma ',' delimited text file using DirXML. Now that part of the process is not what I seek answers for. But what I do seek answers for is the interfacing of Perl to Windows user accounts.

So I have the obvious choice of Windows Script, which takes for ever to read in user account Objects and is quite frankly not really how I want to approach this because of speed and functionality. Batch files are also out of the question I think. And the user manager apps are just out of the question...

I want to use Perl because I know it can do everything and , does the job efficiently, gives a good array of functionality and is a joy to work with.

I am probably going to use Win32API::Net within a TK interface that prompts for all required/possible account paramaters from one main Window.

Just fishing for ideas :)

Here is a wacky Windows Script which I just knocked up which adds one user at a time. Im really just looking for an example or two of some interfacing from Perl to Windows accounts.

Here comes the Wscript :P (/me cannot believe he is posting a Windows Script on a Perl board ...)
<job id="add_user"> <script language=vbscript> ' Script name : addusers.wsf ' Description : A lame example of user creation using Wscript msgbox("This script will create the username under the windows domain +'"&domain&"' with the information you specify. " _ & VbCrLf & "Please wait while I build a list of user objects on th +e domain/computer ...") domain = "some_windows_domain" Set domainObj = GetObject("WinNT://"&domain) add_users = 1 Do While add_users = 1 Dim domain Dim user_exists_check Dim user_id Dim user_fullname Dim user_location Dim user_password Dim add_users user_id=inputbox("Username:","Enter the userid/username") user_fullname=inputbox("Full Name of user:","Enter the user's full + name") user_location=inputbox("User's location:","Branch/Location of user +") user_password=inputbox("Password:","Enter user's password") If user_id = "" or user_fullname = "" or user_location = "" or use +r_password = "" Then msgbox("NULL user paramater specified. Please make sure you en +ter a value for each paramater!") Else ListUsers If user_exists_check = "EXISTS" Then msgbox("User '"&user_id&"' already exists ... USER NOT ADD +ED") user_exists_check = "" Else Add_user End If End If keep_adding=msgbox("Add another user ?",VbOkCancel) If keep_adding <> 1 Then add_users = 0 End If Loop Sub ListUsers domainObj.Filter = Array( "User" ) For Each objUser In domainObj existingUser=objUser.Name If existingUser = user_id Then user_exists_check="EXISTS" Exit Sub End If Next End Sub Sub Add_user Set oUser = domainObj.Create ("user", user_id) oUser.SetInfo oUser.Fullname = user_fullname oUser.SetPassword user_password oUser.Description = user_location & " blah blah user" oUser.AccountDisabled = False oUser.IsAccountLocked = False oUser.SetInfo ListUsers If user_exists_check = "EXISTS" Then msgbox("Added user '"&user_id&"' ...OK") Else msgbox("User not added!") End If End Sub </script> </job>
Show us your code ;)

Replies are listed 'Best First'.
Re: Using Perl to create Windows NT/2000 user accounts
by jdtoronto (Prior) on Jul 05, 2006 at 14:34 UTC
    Using the reciped in "Win32 Perl Programming" (Roth, New Riders 2002) I use Win32::NetAdmin which installs with AS Perl on Win32. There are some other modules, particularly Win32::AdminMisc which can be found at http://www.roth.net/perl/adminmisc/.

    No guarantees, but they work for me. However, looking at the POD for Win32API::Net I might give it a look!

    jdtoronto

    Updated fixed link.

      Yeah, when I was learning Perl I was creating accounts via Win32::NetAdmin. Dave Roth, was the man! I don't know how I would been able to do anything administratively on Windows without his work.
Re: Using Perl to create Windows NT/2000 user accounts
by kabeldag (Hermit) on Jul 06, 2006 at 06:11 UTC
    Looks good. Thanks guys :)
Re: Using Perl to create Windows NT/2000 user accounts
by bsdz (Friar) on Jul 11, 2006 at 16:33 UTC
    No code as such but maybe a few pointers. You could use Active Directory for creating/manipulating user accounts. The Active Directory Cookbook has some excellent examples on this. You could also use Win32::GUI to build your application if you only plan to run it on Windows.