kpu Posted January 8, 2006 Share Posted January 8, 2006 First, I thought I posted this yesterday, but I can't find my own post... Is it possible to set the following code to continue on error? What it's doing is adding a user to a Security group in Acitive Directory. The issue is when the user is already part of the group, it will error out and shutdown and I need it to continue on. ;$member = "cn=Username," $OUlocation = "ou=UserOU,dc=domain,dc=com" $group = "cn=Group,ou=Groups,dc=domain,dc=com" $filex = FileOpen("user.txt", 0) If $filex = -1 Then Exit EndIf While 1 $member = FileReadLine($filex) If @error = -1 Then ExitLoop _AddUserToSecurityGroup() Wend FileClose($filex) Func _AddUserToSecurityGroup() ;MSgBox(32,"User Info",$member & $OUlocation & @CRLF & "Tier Level" & $group) Const $ADS_PROPERTY_APPEND = 3 $objGroup = ObjGet ("LDAP://" & $group) GUICtrlSetData($Label4,"Adding user:" & $member) $objGroup.PutEx ($ADS_PROPERTY_APPEND, "member", _ArrayCreate("CN=" & $member & $OUlocation)) $objGroup.SetInfo() EndFunc Here's the VBscript I used. Const ADS_PROPERTY_APPEND = 3 On Error Resume Next Set objGroup = GetObject _ ("LDAP://cn=Atl-Users,cn=Users,dc=NA,dc=fabrikam,dc=com") objGroup.PutEx ADS_PROPERTY_APPEND, _ "member", Array("cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com") objGroup.SetInfo http://www.kpunderground.com Link to comment Share on other sites More sharing options...
Danny35d Posted January 8, 2006 Share Posted January 8, 2006 Try using AutoItSetOptions. Add this line to you code. Opt("RunErrorsFatal", 0) ;1=fatal default setting, 0=silent set @errorI advice you to add just to the function and then when the function is done set back to default or flag(1) AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
kpu Posted January 8, 2006 Author Share Posted January 8, 2006 ...that easy huh. Thanks. http://www.kpunderground.com Link to comment Share on other sites More sharing options...
Developers Jos Posted January 8, 2006 Developers Share Posted January 8, 2006 think you really need something like: $oMyError = ObjEvent("AutoIt.Error", "ComError") $objGroup.PutEx ($ADS_PROPERTY_APPEND, "member", _ArrayCreate("CN=" & $member & $OUlocation)) $objGroup.SetInfo() If @error then ; User already in the Group EndIf ;COM Error function Func ComError() If IsObj($oMyError) Then $HexNumber = Hex($oMyError.number, 8) SetError($HexNumber) EndIf Return 0 EndFunc ;==>ComError SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
kpu Posted January 8, 2006 Author Share Posted January 8, 2006 think you really need something like:Thanks, that works Great! http://www.kpunderground.com Link to comment Share on other sites More sharing options...
kpu Posted January 9, 2006 Author Share Posted January 9, 2006 Okay, It was working, but now it seems it still errors on: $objGroup.SetInfo() $objGroup.SetInfo()^ ERROR Below is my code. Do I have it in the correct place? expandcollapse popup;$member = "cn=Username," $OUlocation = "ou=UserOU,dc=domain,dc=com" $group = "cn=Group,ou=Groups,dc=domain,dc=com" $filex = FileOpen("user.txt", 0) If $filex = -1 Then Exit EndIf While 1 $member = FileReadLine($filex) If @error = -1 Then ExitLoop _AddUserToSecurityGroup() Wend FileClose($filex) Func _AddUserToSecurityGroup() ;MsgBox(32,"User Info",$member & $OUlocation & @CRLF & "Tier Level" & $group) Const $ADS_PROPERTY_APPEND = 3 $objGroup = ObjGet("LDAP://" & $group) GUICtrlSetData($lbl_status, "Adding user:" & $member) $oMyError = ObjEvent("AutoIt.Error", "ComError") $objGroup.PutEx ($ADS_PROPERTY_APPEND, "member", _ArrayCreate("CN=" & $member & $OUlocation)) If @error then ; User already in the Group EndIf $objGroup.SetInfo() EndFunc ;==>_AddUserToSecurityGroup ;COM Error function Func ComError() If IsObj($oMyError) Then $HexNumber = Hex($oMyError.number, 8) SetError($HexNumber) EndIf Return 0 EndFunc ;==>ComError http://www.kpunderground.com Link to comment Share on other sites More sharing options...
Developers Jos Posted January 9, 2006 Developers Share Posted January 9, 2006 Okay,It was working, but now it seems it still errors on:Below is my code. Do I have it in the correct place?It should be: $objGroup.SetInfo SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
kpu Posted January 9, 2006 Author Share Posted January 9, 2006 It should be: $objGroup.SetInfoI'm still getting the same error. Although for some reason right now it doesn't seem to be working at all. The VB script works still, but either Scite or AutoIt isn't playing very nice. Do you see anything else wrong with the code? http://www.kpunderground.com Link to comment Share on other sites More sharing options...
Developers Jos Posted January 9, 2006 Developers Share Posted January 9, 2006 (edited) I'm still getting the same error. Although for some reason right now it doesn't seem to be working at all. The VB script works still, but either Scite or AutoIt isn't playing very nice. Do you see anything else wrong with the code?I cannot test at this moment but believe you are missing a comma in the array value.$objGroup.PutEx ($ADS_PROPERTY_APPEND, "member", _ArrayCreate("CN=" & $member & "," & $OUlocation))One other thing to try is to seperate the creation of the array and the command$User = _ArrayCreate("CN=" & $member & "," & $OUlocation)$objGroup.PutEx ($ADS_PROPERTY_APPEND, "member", $User) Edited January 9, 2006 by JdeB SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
kpu Posted January 9, 2006 Author Share Posted January 9, 2006 Your right, but It seems I just messed it up when I copied it over to the forum trying to save the schema information for my place of employment. I tested it out on Saturday and my code worked great with the new code from you. Today, it doens't seem to be going so hot. I'm not a network admin and am only setup to "Manage" to group I'm adding users to. I sent my script/program to a Network Admin to see if he gets the same results. thanks for your help.I cannot test at this moment but believe you are missing a comma in the array value.$objGroup.PutEx ($ADS_PROPERTY_APPEND, "member", _ArrayCreate("CN=" & $member & "," & $OUlocation))One other thing to try is to seperate the creation of the array and the command$User = _ArrayCreate("CN=" & $member & "," & $OUlocation)$objGroup.PutEx ($ADS_PROPERTY_APPEND, "member", $User) http://www.kpunderground.com Link to comment Share on other sites More sharing options...
kpu Posted January 10, 2006 Author Share Posted January 10, 2006 (edited) Okay, I figured out that the "CN=username" was missing the rest of the information since AD has it differently then NDS. However, It's still crashing on $objGroup.SetInfo with or without "()" I changed a couple things around again. Any ideas? JdeB, Is the $HexNumber suppose to return the same error code that the *.vbs script would return? expandcollapse popup;$member = "CN=MyTest Account (mytest)" $OUlocation = ",OU=MPS,OU=CHCUsers,dc=domain,dc=domain,dc=com" $group = "cn=Tier III User Group Policy,ou=Groups,dc=domain,dc=domain,dc=com" $filex = FileOpen("user.txt", 0) If $filex = -1 Then Exit EndIf While 1 $member = FileReadLine($filex) If @error = -1 Then ExitLoop _AddUserToSecurityGroup() Wend FileClose($filex) Func _AddUserToSecurityGroup() Const $ADS_PROPERTY_APPEND = 3 $oMyError = ObjEvent("AutoIt.Error", "ComError") $objGroup = ObjGet _ ("LDAP://" & $group) _FileWriteLog($Tier & "-" & $context & ".log","Added User " & $member & " to " & $tier) GUICtrlSetData($lbl_status, "Adding user:" & $member) Sleep(500) $objGroup.PutEx ($ADS_PROPERTY_APPEND, _ "member", _ArrayCreate ("CN=" & $member & $OUlocation)) If @error Then ; User already in the Group _FileWriteLog("error2.log", "Error: " & $HexNumber & " user already added to group") EndIf $objGroup.SetInfo EndFunc ;==>_AddMemberToSecurityGroup Func ComError() If IsObj($oMyError) Then $HexNumber = Hex($oMyError.number, 8) SetError($HexNumber) Select Case $HexNumber = "80020009" _FileWriteLog("error.log", "Error: " & $HexNumber & " user already added to group") EndSelect Else EndIf Return 0 EndFunc ;==>ComError I had it write to a log file to see where it was dieing at and the weired this is that it looks like it runs twice but errors on the first name. It's what it looks like 2006-01-09 13:23:26 : Const $ADS_PROPERTY_APPEND = 3 2006-01-09 13:23:26 : $oMyError = ObjEvent("AutoIt.Error", "ComError") 2006-01-09 13:23:26 : $objGroup = ObjGet("LDAP://" & $group) 2006-01-09 13:23:26 : $objGroup.PutEx ($ADS_PROPERTY_APPEND,"member", _ArrayCreate ("CN=" & $member & $OUlocation)) 2006-01-09 13:23:27 : $objGroup.SetInfo 2006-01-09 13:23:27 : Const $ADS_PROPERTY_APPEND = 3 2006-01-09 13:23:27 : $oMyError = ObjEvent("AutoIt.Error", "ComError") 2006-01-09 13:23:27 : $objGroup = ObjGet("LDAP://" & $group) 2006-01-09 13:23:27 : $objGroup.PutEx ($ADS_PROPERTY_APPEND,"member", _ArrayCreate ("CN=" & $member & $OUlocation)) Edited January 10, 2006 by kpu http://www.kpunderground.com Link to comment Share on other sites More sharing options...
John Posted January 10, 2006 Share Posted January 10, 2006 In your code below you have this section; If @error then ; User already in the Group EndIf $objGroup.SetInfo() EndFunc ;==>_AddUserToSecurityGroup So you caught the error but tried to SetInfo anyway!!! Okay, It was working, but now it seems it still errors on: Below is my code. Do I have it in the correct place? ;$member = "cn=Username," $OUlocation = "ou=UserOU,dc=domain,dc=com" $group = "cn=Group,ou=Groups,dc=domain,dc=com" $filex = FileOpen("user.txt", 0) If $filex = -1 Then Exit EndIf While 1 $member = FileReadLine($filex) If @error = -1 Then ExitLoop _AddUserToSecurityGroup() Wend FileClose($filex) Func _AddUserToSecurityGroup() ;MsgBox(32,"User Info",$member & $OUlocation & @CRLF & "Tier Level" & $group) Const $ADS_PROPERTY_APPEND = 3 $objGroup = ObjGet("LDAP://" & $group) GUICtrlSetData($lbl_status, "Adding user:" & $member) $oMyError = ObjEvent("AutoIt.Error", "ComError") $objGroup.PutEx ($ADS_PROPERTY_APPEND, "member", _ArrayCreate("CN=" & $member & $OUlocation)) If @error then ; User already in the Group EndIf $objGroup.SetInfo() EndFunc ;==>_AddUserToSecurityGroup ;COM Error function Func ComError() If IsObj($oMyError) Then $HexNumber = Hex($oMyError.number, 8) SetError($HexNumber) EndIf Return 0 EndFunc;==>ComError Link to comment Share on other sites More sharing options...
Developers Jos Posted January 10, 2006 Developers Share Posted January 10, 2006 (edited) JdeB, Is the $HexNumber suppose to return the same error code that the *.vbs script would return?Yes .... and you can also retrieve the error description... see helpfile for all details.. This version works for me .... #include<file.au3> #include<array.au3> ;$member = "CN=MyTest Account (mytest)" $oMyError = "" $HexNumber = 0 $OUlocation = ",OU=Users,OU=IT Admins,dc=SubDom,dc=mydomain,dc=com" $group = "CN=Test,OU=Users,OU=Test,OU=Locations,dc=SubDom,dc=mydomain,dc=com" $member = "vanderZande\, Jos P." _AddUserToSecurityGroup() Func _AddUserToSecurityGroup() Const $ADS_PROPERTY_APPEND = 3 $oMyError = ObjEvent("AutoIt.Error", "ComError") _FileWriteLog("error.log", " Objget: " & $group) $objGroup = ObjGet("LDAP://" & $group) If @error Then return 0 _FileWriteLog("error.log", " PutEx: CN=" & $member & $OUlocation) $objGroup.PutEx ($ADS_PROPERTY_APPEND, "member", _ArrayCreate ("CN=" & $member & $OUlocation)) If @error Then return 0 _FileWriteLog("error.log", " SetInfo") $objGroup.SetInfo If @error Then return 0 Return 1 EndFunc;==>_AddMemberToSecurityGroup Func ComError() If IsObj($oMyError) Then $HexNumber = Hex($oMyError.number, 8) _FileWriteLog("error.log", "Error: " & $HexNumber & " " & $oMyError.windescription) Else _FileWriteLog("error.log", "Unknown Error") EndIf SetError($HexNumber) Return 0 EndFunc;==>ComError And creates this log: 2006-01-10 21:29:31 : Objget: CN=Test,OU=Users,OU=Test,OU=Locations,dc=SubDom,dc=MyDomain,dc=com 2006-01-10 21:29:32 : PutEx: CN=vanderZande\, Jos P.,OU=Users,OU=IT Admins,dc=SubDom,dc=MyDomain,dc=com 2006-01-10 21:29:32 : SetInfo 2006-01-10 21:30:19 : Objget: CN=Test,OU=Users,OU=Test,OU=Locations,dc=SubDom,dc=MyDomain,dc=com 2006-01-10 21:30:20 : PutEx: CN=vanderZande\, Jos P.,OU=Users,OU=IT Admins,dc=SubDom,dc=MyDomain,dc=com 2006-01-10 21:30:20 : SetInfo 2006-01-10 21:30:20 : Error: 80020009 The object already exists. Edited January 10, 2006 by JdeB SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
kpu Posted January 10, 2006 Author Share Posted January 10, 2006 Since it's still crashing on me, Here's my code. Is there something else that's causing the issue? expandcollapse popup#include <GuiConstants.au3> #include <array.au3> #include <File.au3> Dim $member, $OUlocation, $list, $oMyError, $HexNumber,$objGroup GUICreate("A.D. Add users to Group V1.2", 420, 230, 430, 346) $cmb_tiers = GUICtrlCreateCombo("Select Tier Level", 184, 16, 201, 21) GUICtrlSetData($cmb_tiers, "Tier I|Tier II|Tier III|Power User(TIER IV)|Adminsitrator") $cmb_context = GUICtrlCreateCombo("Select Context", 184, 48, 201, 21) GUICtrlSetData($cmb_context, "CPT|MPS|STP") $edt_file = GUICtrlCreateInput("Locate List of Users (Click Browse)", 184, 80, 201, 21) $btn_browse = GUICtrlCreateButton("Bro&wse", 312, 112, 75, 25) $btn_Execute = GUICtrlCreateButton("Execute", 232, 168, 75, 25) $btn_exit = GUICtrlCreateButton("Exit", 312, 168, 75, 25) $Label1 = GUICtrlCreateLabel("Select Tier Goup to add users to:", 16, 24, 156, 13) $Label2 = GUICtrlCreateLabel("Select user context:", 16, 56, 94, 13) $Label3 = GUICtrlCreateLabel("Locate the file that has user list:", 16, 88, 152, 13) $Animate1 = GUICtrlCreateAvi("shell32.dll", 152, 5, 210, 16, 16) GUICtrlSetState($Animate1, 0) $lbl_status = GUICtrlCreateLabel("", 19, 210, 210, 13) GUICtrlSetColor($lbl_status, 0x0000ff) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $btn_browse $u_list = FileOpenDialog("Select file that has list of Users", @ScriptDir, "Text (*.txt)", 1) If @error Then MsgBox(32, "", "No File(s) chosen") Else GUICtrlSetData($edt_file, $u_list) EndIf Case $msg = $btn_Execute $tier = GUICtrlRead($cmb_tiers) $context = GUICtrlRead($cmb_context) $list = GUICtrlRead($edt_file) ;Start----Tier Info If $tier = "Select Tier Level" Then MsgBox(16, "Warning!", "You must specify a Tier Level") EndIf If $tier = "Tier I" Then $group = "CN=Tier I User Group Policy,ou=Groups,dc=Domain,dc=domain,dc=com" EndIf If $tier = "Tier II" Then $group = "CN=Tier II User Group Policy,ou=Groups,dc=Domain,dc=domain,dc=com" EndIf If $tier = "Tier III" Then $group = "CN=Tier III User Group Policy,ou=Groups,dc=Domain,dc=domain,dc=com" EndIf If $tier = "Power User(TIER IV)" Then $group = "CN=Tier IV User Group Policy,ou=Groups,dc=Domain,dc=domain,dc=com" EndIf If $tier = "Adminsitrator" Then $group = "" EndIf ;End------Tier Info ;Start-----Context Info---------- If $context = "Select Context" Then MsgBox(16, "Warning!", "You must specify a Context") EndIf If $context = "MPS" Then $OUlocation = ",OU=MPS,OU=CHCUsers,dc=Domain,dc=domain,dc=com" EndIf If $context = "CPT" Then $OUlocation = ",OU=CPT,OU=CHCUsers,dc=Domain,dc=domain,dc=com" EndIf If $context = "STP" Then $OUlocation = ",OU=STP,OU=CHCUsers,dc=Domain,dc=domain,dc=com" EndIf ;END -----Context Info---------- If $list = "Locate List of Users (Click Browse)" Then MsgBox(16, "Warning!", "You must specify a file") Else $f_count = _FileCountLines($list) _ExecuteCommand() EndIf Case $msg = $btn_exit ExitLoop Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;; EndSelect WEnd Exit Func _ExecuteCommand() $file = FileOpen($list, 0) If $file = -1 Then MsgBox(16, "Error", "Unable to open " & $list) Exit EndIf While 1 $member = FileReadLine($file) If @error = -1 Then ExitLoop MsgBox(32,"Member",$member & $OUlocation) _AddUserToSecurityGroup() WEnd GUICtrlSetData($lbl_status, "Complete") GUICtrlSetState($Animate1, 0) MsgBox(32, "Complete", "Added " & $f_count & " member(s) to " & '"' & $group & '"') FileClose($file) EndFunc ;==>_ExecuteCommand Func _AddUserToSecurityGroup() Const $ADS_PROPERTY_APPEND = 3 $oMyError = ObjEvent("AutoIt.Error", "ComError") _FileWriteLog("error.log", " Objget: " & $group) $objGroup = ObjGet("LDAP://" & $group) If @error Then return 0 _FileWriteLog("error.log", " PutEx: CN=" & $member & $OUlocation) GUICtrlSetData($lbl_status, "Adding user:" & $member) Sleep(10) $objGroup.PutEx ($ADS_PROPERTY_APPEND, "member", _ArrayCreate ("CN=" & $member & $OUlocation)) If @error Then return 0 _FileWriteLog("error.log", " SetInfo") $objGroup.SetInfo If @error Then return 0 Return 1 EndFunc;==>_AddMemberToSecurityGroup Func ComError() If IsObj($oMyError) Then $HexNumber = Hex($oMyError.number, 8) _FileWriteLog("error.log", "Error: " & $HexNumber & " " & $oMyError.windescription) Else _FileWriteLog("error.log", "Unknown Error") EndIf SetError($HexNumber) Return 0 EndFunc;==>ComError Here's the log file as well. Notice that it's allways loging "Unknown Error". 2006-01-09 15:20:44 : Unknown Error 2006-01-09 15:20:44 : Objget: CN=Tier III User Group Policy,ou=Groups,DC=domain,DC=domain,DC=com 2006-01-09 15:20:44 : PutEx: CN=user,OU=MPS,OU=CHCUsers,DC=domain,DC=domain,DC=com 2006-01-09 15:20:44 : SetInfo 2006-01-09 15:20:44 : Objget: CN=Tier III User Group Policy,ou=Groups,DC=domain,DC=domain,DC=com 2006-01-09 15:20:44 : PutEx: CN=user2,OU=MPS,OU=CHCUsers,DC=domain,DC=domain,DC=com 2006-01-09 15:20:44 : SetInfo 2006-01-09 15:20:45 : Unknown Error 2006-01-09 15:20:45 : Objget: CN=Tier III User Group Policy,ou=Groups,DC=domain,DC=domain,DC=com 2006-01-09 15:20:45 : PutEx: CN=User1,OU=MPS,OU=CHCUsers,DC=domain,DC=domain,DC=com 2006-01-09 15:20:45 : SetInfo http://www.kpunderground.com Link to comment Share on other sites More sharing options...
Developers Jos Posted January 10, 2006 Developers Share Posted January 10, 2006 (edited) Since it's still crashing on me, Here's my code. Is there something else that's causing the issue? Your log starts with an Unknown error ... strange ?? could you try this version : Func _AddUserToSecurityGroup() Const $ADS_PROPERTY_APPEND = 3 $oMyError = ObjEvent("AutoIt.Error", "ComError") _FileWriteLog("error.log", " Objget: " & $group) $objGroup = ObjGet("LDAP://" & $group) If Not @error Then _FileWriteLog("error.log", " PutEx: CN=" & $member & $OUlocation) GUICtrlSetData($lbl_status, "Adding user:" & $member) Sleep(10) $objGroup.PutEx ($ADS_PROPERTY_APPEND, "member", _ArrayCreate ("CN=" & $member & $OUlocation)) If Not @error Then _FileWriteLog("error.log", " SetInfo") $objGroup.SetInfo EndIf EndIf $oMyError = ObjEvent("AutoIt.Error") Return EndFunc ;==>_AddUserToSecurityGroup Edit: A bit cleaner code Edited January 10, 2006 by JdeB SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
kpu Posted January 11, 2006 Author Share Posted January 11, 2006 That did the trick! It's still logging some "unkown error" in the log file, but the user was added to the group so not a big deal.I just made one change to "$oMyError = ObjEvent("AutoIt.Error","")" and it added 1253 users to a group in less then 50 seconds!Thanks for all your help! http://www.kpunderground.com Link to comment Share on other sites More sharing options...
kpu Posted January 12, 2006 Author Share Posted January 12, 2006 Okay, I made some minor changes and I think I have it working 100% now. Here's the code. I hope this helps others. Func _AddUserToSecurityGroup() $f_count = $f_count + 1 Const $ADS_PROPERTY_APPEND = 3 $oMyError = ObjEvent("AutoIt.Error", "ComError") $objGroup = ObjGet("LDAP://" & $group) If Not @error Then GUICtrlSetData($lbl_status, "Adding user:" & $member) ;Sleep(10) $objGroup.PutEx ($ADS_PROPERTY_APPEND, "member", _ArrayCreate ("CN=" & $member & $OUlocation)) If Not @error Then ;_FileWriteLog("error.log", " SetInfo") $objGroup.SetInfo EndIf EndIf $oMyError = ObjEvent("AutoIt.Error","") Return EndFunc ;==>_AddUserToSecurityGroup Func ComError() If IsObj($oMyError) Then $HexNumber = Hex($oMyError.number, 8) $f_count = $f_count - 1 _FileWriteLog("error.log", " PutEx: CN=" & $member & $OUlocation) _FileWriteLog("error.log", " Objget: " & $group) _FileWriteLog("error.log", "Error: " & $oMyError.windescription) _FileWriteLog("error.log","---------------------------------------------------------------------------------" Else ;_FileWriteLog("error.log", "Unknown Error") EndIf SetError($HexNumber) Return 0 EndFunc;==>ComError http://www.kpunderground.com Link to comment Share on other sites More sharing options...
seandisanti Posted January 12, 2006 Share Posted January 12, 2006 Okay, I made some minor changes and I think I have it working 100% now. Here's the code. I hope this helps others. Func _AddUserToSecurityGroup() $f_count = $f_count + 1 Const $ADS_PROPERTY_APPEND = 3 $oMyError = ObjEvent("AutoIt.Error", "ComError") $objGroup = ObjGet("LDAP://" & $group) If Not @error Then GUICtrlSetData($lbl_status, "Adding user:" & $member) ;Sleep(10) $objGroup.PutEx ($ADS_PROPERTY_APPEND, "member", _ArrayCreate ("CN=" & $member & $OUlocation)) If Not @error Then ;_FileWriteLog("error.log", " SetInfo") $objGroup.SetInfo EndIf EndIf $oMyError = ObjEvent("AutoIt.Error","") Return EndFunc;==>_AddUserToSecurityGroup Func ComError() If IsObj($oMyError) Then $HexNumber = Hex($oMyError.number, 8) $f_count = $f_count - 1 _FileWriteLog("error.log", " PutEx: CN=" & $member & $OUlocation) _FileWriteLog("error.log", " Objget: " & $group) _FileWriteLog("error.log", "Error: " & $oMyError.windescription) _FileWriteLog("error.log","---------------------------------------------------------------------------------" Else ;_FileWriteLog("error.log", "Unknown Error") EndIf SetError($HexNumber) Return 0 EndFunc;==>ComErrorthere were a few posts by new users looking for something like this, you may want to put a copy in scripts and scraps. Link to comment Share on other sites More sharing options...
kpu Posted January 12, 2006 Author Share Posted January 12, 2006 there were a few posts by new users looking for something like this, you may want to put a copy in scripts and scraps.I'm running it again on some 2000 users. If it goes as good as it's been, I'll be sure to stick out there. http://www.kpunderground.com Link to comment Share on other sites More sharing options...
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