Jump to content

Adding User


Recommended Posts

Hy, I know there is an Error on my side

and it seems no one really can or wants to answer questions about this AU3

but since I am doing something worng maybe some one can help?

It is basicly a syntax question.

ADfunctins.au3

_ADAddUserToGroup($Var2,$Var1)

All I need to know is the Syntax of the Variables.

I tried it like discribed,

; _ADAddUserToGroup

; Takes the group (SamAccountName without leading 'CN=') and the user (SamAccountName without leading 'CN=')

; Adds the user to the group

; Returns 0 if the user is already a member of the group,

; Returns 1 if the user was added to the group

; Returns -1 if there was an error

but it did not work!

I tried

$Var2=Group $Var1=User

$Var2=Group,Global Group,Domain,Domain $Var1=User,Global Group,Domain,Domain

$Var2=CN=Group,CN=Global Group,DC=Domain,DC=Domain $Var1=CN=User,CN=Global Group,DC=Domain,DC=Domain

I think you get the Idea...

What is worng?! Please Help

Link to comment
Share on other sites

Perhaps you could try:

DIM $USER
$USER=InputBox ( "User", "Enter username:")
RunWait('net localgroup "Network Configuration Operators" domain\' & $USER & ' /add', '', @SW_HIDE)

This is a bit easier way with using native windows commands for adding users to a group. From this it should be fairly easy for you to modify it :D

Ofcourse you can change "localgroup" with "group" if you don't want to add user to local group.

Link to comment
Share on other sites

Perhaps you could try:

DIM $USER
$USER=InputBox ( "User", "Enter username:")
RunWait('net localgroup "Network Configuration Operators" domain\' & $USER & ' /add', '', @SW_HIDE)

This is a bit easier way with using native windows commands for adding users to a group. From this it should be fairly easy for you to modify it :D

Ofcourse you can change "localgroup" with "group" if you don't want to add user to local group.

Hy thanks for the Idea :-)

ofcourse you are right, this is one way to do it,

but I wanted to understand the Function. And I know i am making a primal mistake,

and thats what I would like to know... What mistake I am making. :-/

So if you got an Idea?

Link to comment
Share on other sites

Func _ADAddUserToGroup($group, $user)
    If _ADIsMemberOf($group, $user) Then Return 0
    $oUsr = ObjGet("LDAP://" & $strHostServer & "/" & $user)  ; Retrieve the COM Object for the user
    $oGroup = ObjGet("LDAP://" & $strHostServer & "/" & $group)  ; Retrieve the COM Object for the group
    
    $OGroup.Add ($oUsr.AdsPath)
    $OGroup.SetInfo
    $oGroup = 0
    $oUser = 0
    Return _ADIsMemberOf($group, $user)
EndFunc

Im guessing _ADAddUserToGroup("example-group","example-user")? Since ADFunctions.au3 already includes variables. So your "example-group" is actualy $group within the ADFunctions.au3 and "exampel-user" is actualy $user :D

Never really tried using these functions, but I think this should do it.

Edited by skysel
Link to comment
Share on other sites

Func _ADAddUserToGroup($group, $user)
    If _ADIsMemberOf($group, $user) Then Return 0
    $oUsr = ObjGet("LDAP://" & $strHostServer & "/" & $user)  ; Retrieve the COM Object for the user
    $oGroup = ObjGet("LDAP://" & $strHostServer & "/" & $group)  ; Retrieve the COM Object for the group
    
    $OGroup.Add ($oUsr.AdsPath)
    $OGroup.SetInfo
    $oGroup = 0
    $oUser = 0
    Return _ADIsMemberOf($group, $user)
EndFunc

Im guessing _ADAddUserToGroup("example-group","example-user")? Since ADFunctions.au3 already includes variables. So your "example-group" is actualy $group within the ADFunctions.au3 and "exampel-user" is actualy $user :D

Never really tried using these functions, but I think this should do it.

One would guess so....

So I did to.... Unfortunattly it does not work like this... For some reason i always get an error on that :-(

No metter what i try i get the Message...

Wrong Syntax or this Object can not be found :-/

And I tried it with testusers an an actual User of my testusers!

Link to comment
Share on other sites

One would guess so....

So I did to.... Unfortunattly it does not work like this... For some reason i always get an error on that :-(

No metter what i try i get the Message...

Wrong Syntax or this Object can not be found :-/

And I tried it with testusers an an actual User of my testusers!

In your script, do you use #include <ADFunctions.au3> on top of the script (check spelling!)? And did you put ADFunctions.au3 to your Program Files\Autoit3\Include directory or did you forget about that? Just checking..

Eitherway, I'm out of ideas. Guess someone else could help you :D

Edited by skysel
Link to comment
Share on other sites

In your script, do you use #include <ADFunctions.au3> on top of the script (check spelling!)? And did you put ADFunctions.au3 to your Program Files\Autoit3\Include directory or did you forget about that? Just checking..

Eitherway, I'm out of ideas. Guess someone else could help you :D

Yes i Did that and create User and Create Group both work fine, thats why i can't say whats wrong... If every thing wouldn't work I would entirely take the blame, but like this im not sure. :-(

Link to comment
Share on other sites

nitron, try this WinAPI UDFs
; ==================================================================================================
; Name...........: _NetAPI_GroupAddUser
; Description ...: Gives an existing user account membership in an existing global group
; Syntax.........: _NetAPI_GroupAddUser($sUser, $sGroup, $sServer)
; Parameters ....: $sUser   - User to be given membership in the Global Group
;                : $sGroup  - Name of the Global Group in which the User is to be given membership
;                : $sServer - DNS or NetBIOS name of the remote Server or Null for Local use
; Return values .: Success  - True
;                  Failure  - False and @Extended set error NERR code
; Author ........: amel27
; Example .......: _NetAPI_GroupAddUser ("User", "Domain Admins", "DC1")
; ===================================================================================================
Func _NetAPI_GroupAddUser($sUser, $sGroup, $sServer = '')
    Local $aRet = DllCall("netapi32.dll", "int", "NetGroupAddUser", "wstr", $sServer, "wstr", $sGroup, "wstr", $sUser)
    If $aRet[0] Then Return SetError(1, $aRet[0], False)
    Return True
EndFunc ; ==> _NetAPI_GroupAddUser

; ===================================================================================================
; Name...........: _NetAPI_LocalGroupAddMember
; Description ...: Adds membership of one existing user or global group account to an existing local group
; Syntax.........: _NetAPI_LocalGroupAddMember($sAccount, $sGroup, $sServer)
; Parameters ....: $sAccount - Account name of the Local Group member prefixed by the domain name and the "\" separator
;                : $sGroup   - Name of the Local Group to which the specified users or global groups will be added
;                : $sServer  - DNS or NetBIOS name of the remote Server or Null for Local use
; Return values .: Success   - True
;                  Failure   - False and @Extended set error code
; Author ........: amel27
; Example .......: _NetAPI_LocalGroupAddMember ("Domain\User", "Administrators")
; ===================================================================================================
Func _NetAPI_LocalGroupAddMember($sAccount, $sGroup, $sServer = '')
    Local $twUser = DllStructCreate("wchar["& StringLen($sAccount)+1 &"]")
    Local $tpUser = DllStructCreate("ptr")
    DllStructSetData($twUser, 1, $sAccount)
    DllStructSetData($tpUser, 1, DllStructGetPtr($twUser))

    Local $aRet = DllCall("netapi32.dll", "int", "NetLocalGroupAddMembers", _
        "wstr", $sServer, "wstr", $sGroup, "int", 3, "ptr", DllStructGetPtr($tpUser), "int", 1 )
    If $aRet[0] Then Return SetError(1, $aRet[0], False)
    Return True
EndFunc ; ==> _NetAPI_LocalGroupAddMember
Edited by amel27
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...