Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Perl to Create Windows Accounts 1

Status
Not open for further replies.

1DMF

Programmer
Joined
Jan 18, 2005
Messages
8,795
Location
GB
Hello,

Is it posible to use perl to create windows user accounts (not AD).

I have a password protected members area, and would like to receive a sign up form and automate the user name and password proces to give access to the protected web area.

Is it possible and what do I nd to use to do it.

Thanks 1DMF.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Haven't tried it yet, but it certainly looks promising, thanks.

However I only want to allow access to specific area/webspace , and i can't see here where you specify what can be accessed.

I've created a group and can give that access to the web area, any idea how you add a created user to a group via perl?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I've been reading the tech tasks code centre and it seems these tips / code snippets are for a DC...
Code:
cn=SalesGroup,ou=Groups,dc=rallencorp,dc=com
however I did say this was NOT AD (Active Directory) this is a windows 2003 server but is not a domain. It is in the workgroup "WORKGROUP". I'm concerend about trying these example as they seem to be for a different type of set up, adding people to the domain etc...

I don't want to try something that could cause damage to the server, this is a live production websever.

Any suggestions / thoughts as to how I should proceed , if this code will still work or how it can be modified?

I'm not an expert on Windows Servers, but am assuming that the box standard workgroup windows accounts aren't in AD , AD is MS's home baked DNS isn't it? and if we aren't running DNS / DC then I'm assuming AD doesn't exist on this server, is this right?

All input appreciated.
1DMF.


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
try adding the users to your own machine, and see how that goes, I can't see it messing up the server bar denying access to those users in a worst case scenario ... but then again ;-)

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
but what to i put in these options DC ? there isn't one, what do i use for parentDN,
LDAP://<ParentDN>");
if this stands for domain name, there isn't one.

I'm a bit confused what I put where in a non-domain environment, when it is showing domain examples.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
try the local machine name

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
well I've tried a little test script just to see if I can connect and get the following error.

Win32::OLE(0.1707) error 0x8007203a: "The server is not operational" after character 0 in "LDAP://MyServer/OU=OnlyUsers"

using this string...
Code:
my $objParent = Win32::OLE->GetObject('LDAP://MyServer/OU=OnlyUsers');

So do I take it LDAP isn't the way to go as I understand it to mean Lightweight Directory Access Protocol , and AD isn't running!

Maybe the Win32::OLE is still the right module for the job, but I'm assuming I need to create a different object relating to Local Machine Accounts, any thoughts?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I've found a link that has indicated to use WinNT:// instead of LDAP, I have run this code sucessfully , but don't seem to have anything in the hash ref...
Code:
my $objParent = Win32::OLE->GetObject("WinNT://MyServer") or die "Unable to get object";

    foreach my $k (%$objParent) {
        print "key: $k,<br />";
    }

die "obj = " . $objParent;

All I get as output is ...
Software error:
obj = Win32::OLE=HASH(0x216ffc)

Although a hash ref is created it doesn't seem to have anything in it.

Can anyone help ?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Code:
use Data::Dumper
print Dumper $objParent;

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
produces
$VAR1 = bless( {}, 'Win32::OLE' );

So I did some googling and found a site that gives this heads up....

TIP
Here's a tip that may save you some consternation. If you run these two lines of code in the Perl debugger and examine the contents of the returned object reference, you might see something like this:

DB<3> x $adsobj
0 Win32::OLE=HASH(0x10fe0d4)
empty hash
Don't panic. Win32::OLE uses the power of tied variables. The seemingly empty data structure you see here will magically yield information from our object when we access it properly.

Perl's hash reference syntax is used to access the interface property values of an ADSI object:

$value = $adsobj->{key}
For instance, if that object had a Name property defined as part of its interface (and they all do), you could:

print $adsobj->{Name}."\n";

So I guess I need to studdy the Win32:OLE methods / hash reference a bit more but it looks like i'm on the right track :-)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
yup just ran a test with this code
Code:
##################
# Use Win32::OLE #
##################
use Win32::OLE 'in';

##############
# Error Flag #
##############
$Win32::OLE::Warn = 3;

# Create Object

my $objParent = Win32::OLE->GetObject("WinNT://MyServerName") or die "Unable to get object";

# Output content

print "Content-type: text/html\n\n";

foreach my $child (in $objParent){
    print $child->{Name} . "<br />";
}

and got the following output....
Administrators
Backup Operators
Distributed COM Users
Guests
Network Configuration Operators
Performance Log Users
Performance Monitor Users
Power Users
Print Operators
Remote Desktop Users
Replicator
Users
plus some real accounts I haven't shown ;-) but looks like i'm on the right track, thanks for the help Paul :-)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top