#109478 - 2003-12-03 10:08 AM
Re: Add user to a local SAM database
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11631
Loc: CA
|
Hello Mima,
Please give this code a try. You must have Admin rights on the remote system in order to add a user.
Debug Off Break On Dim $iRC $iRC=SetOption('Explicit','On') $iRC=SetOption('NoVarsInStrings','On') Dim $Computer,$Group,$User $Computer = "workstation name" $Group = GetObject("WinNT://" + $Computer + "/Administrators,group") $User = GetObject("WinNT://" + $Computer + "/dave,user") $Group.Add($User.ADsPath) ? 'Return value: ' +@ERROR +' '+@SERROR
|
|
|
Top
|
|
|
|
#109479 - 2003-12-03 01:16 PM
Re: Add user to a local SAM database
|
mima
Hey THIS is FUN
Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
|
Hi Ntdoc This workes fine ! if I only want to add a local user in a local group. BUT I want to add Domain Users group into the local Administrators group. Is that possibly with som change in your code ??  /Mima
|
|
Top
|
|
|
|
#109480 - 2003-12-03 01:57 PM
Re: Add user to a local SAM database
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You can do this KiXtart. Your "add" method would like this... Code:
$Group.Add("WinNT://$Domain/Domain Admins")
Checkout my GrpMaint.exe listed on my Perl utilities web page.
To add a user: Code:
$cont = GetObject("WinNT://" + $Computer + ",computer") $oUser = $cont.Create("user", $sUser)
|
|
Top
|
|
|
|
#109481 - 2003-12-03 02:10 PM
Re: Add user to a local SAM database
|
mima
Hey THIS is FUN
Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
|
I dont get this to work. I have done like this:
Dim $iRC $iRC=SetOption('Explicit','On') $iRC=SetOption('NoVarsInStrings','On') $Domain = "MYDomain" Dim $Computer,$Group,$User $Computer = "ws001" $Group = GetObject("WinNT://" + $Computer + "/LGrp,group") ** I changed the following line: ** ; $User = GetObject("WinNT://" + $Computer + "/dave,user") to the following because it is Domain Users I am looking for: $User = GetObject("LDAP://CN=Domain Users,CN=Users,DC=intra,DC=se")
then I dont understand how I will get this into the local SAM. I tried this: $Group.Add($User.ADsPath) but it wont work.
Howard your reply was : $Group.Add("WinNT://$Domain/Domain Users")
but that wont work.
/Mima
|
|
Top
|
|
|
|
#109482 - 2003-12-03 02:16 PM
Re: Add user to a local SAM database
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Why won't my suggestion work? You can not pass an "LDAP://" path to the "WinNT://" ADSI provider.
|
|
Top
|
|
|
|
#109483 - 2003-12-03 03:03 PM
Re: Add user to a local SAM database
|
mima
Hey THIS is FUN
Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
|
Hi Howard I'm lost........ 
If I write the line, what does this line do ? $Group.Add("WinNT://$Domain/Domain Admins") I only want to add Domain Users in to the LOCAL Administrator group
/mima 
|
|
Top
|
|
|
|
#109484 - 2003-12-03 03:15 PM
Re: Add user to a local SAM database
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I typed the name of the wrong group name - sorry. Change "Domain Admins" to "Domain Users". That is the ADsPath of a group to add to add to the group object defined by $Group.
[edit]
What is the exact problem you have...is it technical or understanding the ADSI code?
Edited by Howard Bullock (2003-12-03 03:18 PM)
|
|
Top
|
|
|
|
#109485 - 2003-12-03 04:55 PM
Re: Add user to a local SAM database
|
mima
Hey THIS is FUN
Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
|
Sorry. Wrong DNS in the workstation that I tested with, not to the Active Directory DNS. that gave all the errors....
 So now the script works perfect. Here is the code to all if you want to ADD a group from the Domain into a Local group on a workstation:
Dim $iRC $iRC=SetOption('Explicit','On') $iRC=SetOption('NoVarsInStrings','On') Dim $Computer,$Group,$User $Domain = "MyDOM" $Computer = "ws001" $Group = GetObject("WinNT://" + $Computer + "/Administrators,group") $Group.Add("WinNT://$Domain/Domain Users")
/Mima
|
|
Top
|
|
|
|
#109486 - 2003-12-03 05:01 PM
Re: Add user to a local SAM database
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
This should not work with "NoVarsInStrings"
$Group.Add("WinNT://$Domain/Domain Users")
should be:
$Group.Add("WinNT://" + $Domain + "/Domain Users")
You should also check @error to insure the process completed without errors.
Edited by Howard Bullock (2003-12-03 05:01 PM)
|
|
Top
|
|
|
|
#109487 - 2003-12-03 05:13 PM
Re: Add user to a local SAM database
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
|
|
Top
|
|
|
|
#109489 - 2003-12-11 02:09 PM
Re: Add user to a local SAM database
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You have not explained sufficiently what exactly you want to accomplish, but I think this may be it...
function IsGroupMember
|
|
Top
|
|
|
|
#109491 - 2003-12-11 02:39 PM
Re: Add user to a local SAM database
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Did you read the link I posted in my previous post? That does the check to see if an object is already a member. Also you could just perform the add and process the errorcode. Ignore the error code that occurs when the object is already a member.
|
|
Top
|
|
|
|
#109493 - 2003-12-11 05:33 PM
Re: Add user to a local SAM database
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
The error returned should be consistent. Read the FAQ: Error Code Look up.. for a small UDF that will make the error usable. Lonkero also has a ComError function that is similiar.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|