Current location: Hot Scripts Forums » Programming Languages » Perl » perl newbie has a problem...


perl newbie has a problem...

Reply
  #1 (permalink)  
Old 08-15-03, 03:52 PM
fowler23 fowler23 is offline
New Member
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
perl newbie has a problem...

i wrote the following script:

#!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>;

print "\n";
#print "$computer";
print "$name";
print "$pass";

use Win32::Lanman;

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-19-03, 12:47 AM
Skeleton Man Skeleton Man is offline
Community Liaison
 
Join Date: Jun 2003
Location: Australia
Posts: 406
Thanks: 0
Thanked 0 Times in 0 Posts
Change this:

Code:
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;
}

To this:

Code:
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;
}
Note the removal of the "\" from infront of $name and $pass..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-19-03, 10:56 AM
fowler23 fowler23 is offline
New Member
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
i've already tried that. when i do that it gives me error 2202...

any other ideas?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 10-04-03, 11:57 PM
rob2132 rob2132 is offline
Newbie Coder
 
Join Date: Sep 2003
Location: USA
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by fowler23
i wrote the following script:

#!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>;

print "\n";
#print "$computer";
print "$name";
print "$pass";

use Win32::Lanman;

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 03-24-10, 06:14 PM
mhlelite_moose mhlelite_moose is offline
New Member
 
Join Date: Mar 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Not sure if you still need this but try:
$name = <STDIN>;
chomp $name;
$pass = <STDIN>;
chomp $pass;

Without chomp the \n (enter) is being included in the user's input.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
file download problem ukyankee Perl 6 10-04-03 11:39 PM
Running Perl scripts under Microsoft IIS retrocom Perl 3 08-23-03 05:38 PM
jpGraph axis labeling problem Squeezer PHP 2 08-20-03 08:53 AM
Flatfile single Forum with Perl Gaz General HotScripts Site Discussion 1 08-07-03 05:37 AM
Newbie Help DAL Perl 10 06-27-03 01:07 PM


All times are GMT -5. The time now is 12:51 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.