nitron Posted April 14, 2008 Posted April 14, 2008 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
skysel Posted April 14, 2008 Posted April 14, 2008 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 Ofcourse you can change "localgroup" with "group" if you don't want to add user to local group.
nitron Posted April 14, 2008 Author Posted April 14, 2008 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 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?
skysel Posted April 14, 2008 Posted April 14, 2008 (edited) 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 Never really tried using these functions, but I think this should do it. Edited April 14, 2008 by skysel
nitron Posted April 14, 2008 Author Posted April 14, 2008 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 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!
skysel Posted April 14, 2008 Posted April 14, 2008 (edited) 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 Edited April 14, 2008 by skysel
nitron Posted April 14, 2008 Author Posted April 14, 2008 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 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. :-(
amel27 Posted April 16, 2008 Posted April 16, 2008 (edited) nitron, try this WinAPI UDFs expandcollapse popup; ================================================================================================== ; 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 April 16, 2008 by amel27
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now