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

Hi,

Problem: I am unable to create a local user account on local and target machines. The error returned for each attempt is "87", which according to MSDN means. "The parameter is incorrect." The code for Win32::NetAdmin::UserCreate looks correct and came from ActiveState documentation and http://www.microsoft.com/technet/prodtechnol/ntwrkstn/maintain/operate/admin.mspx

Platform: Perl 5.6.1, Windows 2000 and Windows XP

Any help would be much appreciated, thanks.

foreach $server(@server) { %account = ( server => "\\\\$server", user => "Test", password => "12345678", homedir => "", priv => "USER_PRIV_USER", flags => "UF_SCRIPT |UF_TEMP_DUPLICATE_ACCOUNT", comment => "Test", logon => "", ); unless (Win32::NetAdmin::UserCreate($account{server}, $account{use +r}, $account{password}, 0, $account{priv}, $account{homedir}, $accoun +t{comment}, $account{flags}, $account{logon})) { print LOG "$server,Problem,Unable To Create Account,".Win32::N +etAdmin::GetError().",".localtime()."\n"; ++$errorct; } else { print LOG "$server,Good,Added Account,".localtime()."\n"; ++$goodct; } }

Replies are listed 'Best First'.
Re: NetAdmin::UserCreate
by clscott (Friar) on Nov 04, 2004 at 18:13 UTC
    I'm sure that the problem is with the values of $account{priv} and $account{flags}. You are quoting them, which turns the values into a string but USER_PRIV_USER et al are really named numerical constants exported by the Win32::NetAdmin package. You'll notice that they are not quoted in the example on the page that you linked to. Try removing the quotes around the values you are putting in $account{priv} and $account{flags} Try:
    foreach my $server (@servers ){ my %account = ( server => "\\\\$server", user => "Test", password => "12345678", homedir => "", priv => USER_PRIV_USER, flags => UF_SCRIPT |UF_TEMP_DUPLICATE_ACCOUNT, comment => "Test", logon => "", ); unless (Win32::NetAdmin::UserCreate(@account{ qw/server user passw +ord/}, 0, @account{ qw/priv homedir comment flags logon/})) { print LOG "$server,Problem,Unable To Create Account,".Win32::N +etAdmin::GetError().",".localtime()."\n"; ++$errorct; } else { print LOG "$server,Good,Added Account,".localtime()."\n"; ++$goodct; } }
    --
    Clayton
      Thanks for getting back to me. My orginal testing had them without the quotes. I just tried it again by removing the quotes, but the output is the same failure, 87.

        That was the only error I could see wit hte perl, the rest is likely in the actual permissions you are trying to set?

        Is there a way to get more information out of the error messages?

        --
        Clayton