Running an NT4 server with service pack 6 I have been trying to set some user information fields by use of various modules: Win32::NetAdmin, Win32::Lanman, and Win32API::Net. None of them work; failed snippets follow. Server, user and group names have been changed. My perl version is:
TSE-Shell P:\devtest>perl -v
This is perl, v5.6.0 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2000, Larry Wall
Binary build 618 provided by ActiveState Tool Corp. http://www.ActiveState.com
Built 21:03:54 Sep 13 2000
Each of these modules provide tools that have allowed me to read informatiion, and even reset passwords; but I can't set Comment or UserComment. Does anyone know why?
Snippets that fail:
(the first snippet fails silently)
# Imports the Lanman symbols and functions.
use Win32::Lanman;
# Import ODBC to extract contract expiration.
use Win32::ODBC;
# Get the list of users.
Win32::Lanman::NetUserEnum("\\\\servername", &FILTER_NORMAL_ACCOUNT, \@suspect);
foreach $suspect (@suspect) {
Win32::Lanman::NetUserGetInfo("\\\\servername", $suspect, \%$suspect);
}
# Connect to account database.
if (!($db = new Win32::ODBC("AccountInfo"))){
print "Error connecting to Accounts\n";
print "Error: " . Win32::ODBC::Error() . "\n";
exit;
}
$sql = "SELECT * FROM tblUsers, tblContacts WHERE tblUsers.ContactID = tblContacts.`Contact ID`";
if ($db->Sql($sql)) {
print "Sql($sql) failed.\nError: ". $db->Error()."\n";
}
while($db->FetchRow()){
undef %user;
%user = $db->DataHash();
foreach $suspect (@suspect) {
if ($suspect eq $user{Username}) {
foreach $atom ('Prefix', 'FirstName', 'MiddleInitial', 'LastName', 'Suffix') {
if ($user{$atom}) {
$$suspect{fullName} .= $atom;
unless (($atom eq 'LastName') || ($atom eq 'Suffix')) {
$$suspect{fullName} .= ' ';
}
if (($atom eq 'Lastname') && ($user{Suffix})) {
$$suspect{fullName} .= ', ';
}
}
}
if ($user{Email} =~ /\S/) {
$$suspect{email} = $user{Email};
}
if (!($user{Organization} =~ /\S/)) {
$$suspect{org} = "UNKNOWN";
}
else {
$$suspect{org} = $user{Organization};
}
if ($suspect eq 'test') {
unless (&Win32::Lanman::NetUserSetInfo("\\\\servername", $suspect,
{'name' => $suspect,
'password' => '',
'home_dir' => '\\\\servername\\perl',
'comment' => $$suspect{email},
'flags' => UF_NORMAL_ACCOUNT(),
'script_path' => '',
'full_name' => $suspect{fullName},
'usr_comment' => $$suspect{org},
'parms' => 'test users parameters',
'workstations' => '',
'profile' => '',
'home_dir_drive' => '',
'acct_expires' => '-1',
'country_code' => 0,
'code_page' => 0,
'logon_hours' => pack("b168", "111111111111111111111111" x 7),
'password_expired' => 0})) {
print &Win32::Lanman::GetLastError();
}
}
}
}
}
# close the database connection when you're done with it.
$db->Close();
-----------------------------------------------------------------------------------------------------------------------------
(the second fails with a "Modification attempted on read only value" error.)
# Imports the Win32API module's User symbols
use Win32API::Net qw(:User :Get :Group);
# Imports date calculations
use Date::Calc qw(:all);
# Import ODBC to extract contract expiration.
use Win32::ODBC;
# Import Sendmail
use Mail::Sendmail;
# Import for str2time
use HTTP::Date;
# Get the list of users.
UserEnum("\\\\servername", \@suspect); #makes an array containing all local users
# Get the list of Interesting users.
GroupGetUsers("\\\\servername", "Interesting", \@interesting); #makes an array containing the members of the Interesting group
# Make a hash for each user to hold properties of interest. Add boredom status.
foreach $suspect (@suspect) {
UserGetInfo("\\\\servername", $suspect, 3, \%$suspect);
$$suspect{Boring} = Boring($suspect);
}
# This opens the log files appropriately.
if ($ENV{COMPUTERNAME} eq 'SERVERNAME') { ### running from the server; points the logs in the right direction.
open (DELETED, ">> d:\\adminscripts\\deletions.log");
open (NOTIFICATIONS, ">>d:\\adminscripts\\notifications.log");
}
else { ### running from another machine. Note that the logs go to CWD.
open (DELETED, ">>deletions.log"); #opens the deletion log
open (NOTIFICATIONS, ">>notifications.log"); #opens the notification log
}
($year, $month, $day, $hour, $min, $sec) = Today_and_Now();
# Make the log times readable. Note that this converts them to *strings*; don't try any more math.
if ($hour < 10 ) {
$hour = "0" . $hour;
}
if ($min < 10) {
$min = "0" . $min;
}
if ($sec < 10) {
$sec = "0" . $sec;
}
print DELETED "Opened for deletions $month/$day/$year at $hour:$min:$sec\n";
# Connect to account database.
if (!($db = new Win32::ODBC("AccountInfo"))){
print "Error connecting to Accounts\n";
print "Error: " . Win32::ODBC::Error() . "\n";
exit;
}
$sql = "SELECT * FROM tblUsers, tblContacts WHERE tblUsers.ContactID = tblContacts.`Contact ID`";
if ($db->Sql($sql)) {
print "Sql($sql) failed.\nError: ". $db->Error()."\n";
}
while($db->FetchRow()){
undef %user;
%user = $db->DataHash();
foreach $suspect (@suspect) {
if ($suspect eq $user{Username}) {
$$suspect{email} = $comment{comment} = $user{Email};
$error = USER_COMMENT_PARMNUM();
UserSetInfo('//servername', $user, 1007, \%comment, $error);
if ($user{Organization} =~ /\S/) {
$$suspect{org} = $user{Organization};
}
else {
$$suspect{org} = "UNKNOWN";
}
$usrComment{usrComment} = $$suspect{org};
$error = USER_USR_COMMENT_PARMNUM();
UserSetInfo('//servername', $user, 1012, \%usrComment, $error);
if ($user{ContractDate}) {
$$suspect{contractDate} = $user{ContractDate};
push @contractors, $suspect;
}
}
}
}
# close the database connection when you're done with it.
$db->Close();
--
Ed Ahlsen-Girard [EMAIL PROTECTED] 46TS OG/OGET
Network Administrator 850-882-6540x5349 205 West D Avenue
TYBRIN Corporation DSN:872-6540x5349 Suite 628 Bldg 350
Lan Integration FAX: 850-882-5594 Eglin AFB, FL 32542
http://www.tybrin.com http://www.eglin.af.mil/mission-planning
