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!

Win32::OLE doing my head in big style!

Status
Not open for further replies.

1DMF

Programmer
Joined
Jan 18, 2005
Messages
8,795
Location
GB
Apart from my other post unable to get IIS to run the perl script with admin permissions.

I decided to do some testing running script locally.

The script runs without the permissions error, I issue the add member to group code...
Code:
# Get group Object
my $objGroup = Win32::OLE->GetObject("WinNT://$server/" . $group) or die "Unable to get group object";

# Add a member
$objGroup->Add("WinNT://$server/" . $user);

and when I check the group sure enough the user has been added.

However, when i then try to display the members of the group I get the following error...
[Tue Feb 13 14:45:33 2007] ldap_test.pl: Win32::OLE(0.1707) error 0x80020003: "M
ember not found"
using this code...
Code:
print "Members of ", $objGroup->Name . ":\n";
foreach my $objMember (in $objGroup->Members) {
   print $objMember->Name,"\n";
}
taken from this link ...
any ideas why this won't work?

if I just get the top level .i.e. my $objGroup = Win32::OLE->GetObject("WinNT://$server/"); and loop displaying hash key 'Name' I get a list of all the user accounts and groups?

I need some help!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I worked it out woohoo !!!!!!

Code:
# Create parent object.
my $objParent = Win32::OLE->GetObject("WinNT://$server")  or &error("Unable to create PARENT object"); 

# Create user object.
my $objUser = $objParent->Create("user", "$userid") or &error("Unable to create USER object"); 

# Assign user details
$objUser->SetInfo;
$objUser->SetPassword("$pword");
$objUser->{AccountDisabled} = "FALSE";
$objUser->{Description} = "$description";
objUser->{FullName} = "$firstname $lastname";
#$objUser->{PasswordExpires} = 'TRUE';
$objUser->SetInfo;

# Get group Object
my $objGroup = Win32::OLE->GetObject("WinNT://$server/" . $group) or &error("Unable to get group object");

# Add user to group
$objGroup->Add("WinNT://$server/" . $userid);

print "Members of $group:\n";
foreach my $objMember (in $objGroup->Members) {
   print $objMember->Name,"\n";
}
 
exit();

The only problem I have now is how to set "Password Never Expires" , I cannot use the flags (PUT) method, none of the 'put' methods work , i'm assuming it is trying to use AD , but that's just a guess either way, all examples on here ... crash out with the 'put' method.

Does anyone know if you can set a hash ref (you can see i've tried various combo's but they keep failing), so need to know the 'key name' to use.

Also can I get a script running via IIS to run a script with local credentials therfore erradicating this access denied problem?

thanks 1DMF.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Solved it :-) , I was passing it a string by mistake, should have been...

$intNewUserFlags = 0x10000;
$objUser->Put('userFlags', $intNewUserFlags);

d'oh!





"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