#!perl
my $name;
my $pass;
#print "Please enter a computer on which to create the account...\n";
#$computer = <STDIN>;
print "Please enter the username to be created...\n";
$name = <STDIN>;
print "Please enter the user's password...\n";
$pass = <STDIN>;
if(!Win32::Lanman::NetUserAdd("\\\\doomsday", {'name' => \$name,
'password' => \$pass,
'comment' => 'perl test addition'}))
{
print "Sorry, account could not be created...";
print Win32::Lanman::GetLastError();
exit 1;
}
everything prints correctly, and the script gets no errors, however the user that is created is not the username specified in $name. the username is something like SCALAR(0x1a45100)...
is there something i'm doing wrong. i'm new to perl and fairly new to programming so please no flames...
#!perl
my $name;
my $pass;
#print "Please enter a computer on which to create the account...\n";
#$computer = <STDIN>;
print "Please enter the username to be created...\n";
$name = <STDIN>;
print "Please enter the user's password...\n";
$pass = <STDIN>;
if(!Win32::Lanman::NetUserAdd("\\\\doomsday", {'name' => \$name,
'password' => \$pass,
'comment' => 'perl test addition'}))
{
print "Sorry, account could not be created...";
print Win32::Lanman::GetLastError();
exit 1;
}
everything prints correctly, and the script gets no errors, however the user that is created is not the username specified in $name. the username is something like SCALAR(0x1a45100)...
is there something i'm doing wrong. i'm new to perl and fairly new to programming so please no flames...
thanks in advance for your help.
Does this do a thing for you and your problem (or are you still having a problem?), did you set the home dir, etc.? Do you have permission as the user you're running it as?
Code:
#!perl
print "Please enter the username to be created...\n";
chomp($name = <STDIN>);
print "Please enter the user's password...\n";
chomp($pass = <STDIN>);
use Win32::Lanman; # for account creation
use Win32::Perms; # to set the permissions on the home directory
$homeNTdirs = "\\\\doomsday"; # home directory root dir
Try and incorporate a sub routine such as this from the sys admin recipes:
sub CreateNTAccount {
my ($account, $record) = @_;
# create this account on the local machine
# (i.e. empty first parameter)
$result = Win32::Lanman::NetUserAdd("",
{ 'name' => $account,
'password' => $record->{password},
'home_dir' => "$homeNTdirs\\$account",
'full_name' => $record->{fullname}}
);
return Win32::Lanman::GetLastError() unless ($result);
# add to appropriate LOCAL group (first get the SID of the account)
# we assume the group name is the same as the account type
die "SID lookup error: ".Win32::Lanman::GetLastError() . "\n" unless
(Win32::Lanman::LsaLookupNames("", [$account], \@info));
$result = Win32::Lanman::NetLocalGroupAddMember("", $record->{type}, ${$info[0]}{sid});
return Win32::Lanman::GetLastError() unless ($result);
# create home directory
mkdir "$homeNTdirs\\$account",0777 or return "Unable to make homedir:$!";
# now set the ACL and owner of the directory
$acl = new Win32::Perms("$homeNTdirs\\$account");
$acl->Owner($account);
# we give the user full control of the directory and all of the
# files that will be created within it (hence the two separate calls)
$acl->Allow($account, FULL, DIRECTORY|CONTAINER_INHERIT_ACE);
$acl->Allow($account, FULL, FILE|OBJECT_INHERIT_ACE|INHERIT_ONLY_ACE);
$result = $acl->Set();
$acl->Close();
return($result ? "" : $result);
}
If that's overkill or you don't know how to use the sub routine (call it), or if you want to see if some simple things will work first with your existing script--assuming it fails still, let me know.