Steven Meier Posted January 23, 2007 Share Posted January 23, 2007 Folks, I have posted a few queries here over the week , I have managed to nut everything bar my last task. Using ADSI I believe to create the mailbox. I will post my working code for app here... I have created the LDAP string but unsure where to go from here. The asterisks are for client confidentiality, but feel free to use if wish. I am not much of a scripter so if my code is untidy, I am happy to hear about it, but it does work, so I am happy. CODE#include <GUIConstants.au3> Func _RunDOS($sCommand) Return RunWait(@ComSpec & " /C " & $sCommand, "", @SW_HIDE) EndFunc ;==>_RunDOS $mainwindow = GUICreate("**************** User Application", 400, 460) GUICtrlCreateLabel("USER DETAILS", 15, 8) GuiCtrlCreateLabel(" **************************** v1.0 16/1/2007", 10, 440) $App1 = GUICtrlCreateButton("Create User ", 80, 380, 100) $App2 = GUICtrlCreateButton("Modify User ", 180, 380, 100) GuiCtrlCreateLabel(" First Name", 30, 25) $FirstN = GUICtrlCreateInput ( " " , 85, 23, 90, 20, ) GuiCtrlCreateLabel(" Last Name", 180, 25) $LastN = GUICtrlCreateInput ( "" , 240, 23, 100, 20, ) GuiCtrlCreateLabel("Description : " , 30, 49) $DES = GUICtrlCreateInput ( "" , 85, 48, 150, 20 ) GuiCtrlCreateLabel("Office : " , 245, 52) $OFF = GUICtrlCreateCombo ("" , 275, 48, 100, 20 ) GUICtrlSetData(-1, "Christchurch|Westport|Spring Creek|Rapahoe|Ngakawa|Ohai|Reefton|Rotowaro|East Mine|Stockton|Natures Flame" , "Christchurch") GuiCtrlCreateLabel("Email : " , 30, 75) $Email = GUICtrlCreateInput ( "" , 85, 70, 280, 20 ) GuiCtrlCreateLabel("Logon Name : " , 30, 95) $LogonN = GUICtrlCreateInput ( "" , 95, 92, 100, 20 ) GuiCtrlCreateLabel("Password : " , 197, 95) $Passw = GUICtrlCreateInput ( "" , 250, 92, 100, 20 ) GuiCtrlCreateLabel("Users OU " , 30, 120) $UserOU = GUICtrlCreateCombo ("", 85,115, 100) GUICtrlSetData(-1,"SE_Users|SERF_Users","SE_USERS") GuiCtrlCreateLabel("Local File and Print Server for User files: " , 30, 140) $FP = GUICtrlCreateCombo ("", 220, 138, 100, 20 ) GUICtrlSetData(-1,"CHCHFP01|ROTOFP01|EASTFP01|OHAIFP01|STCKFP01|WESTFP01|RAPAFP01|NGAKFP01|SPRGFP01|REEFFP01|SERFA DFP01" , "CHCHFP01") GuiCtrlCreateLabel("MailBox Store Name : " , 30, 180) $MB = GUICtrlCreateCombo ( "" , 135, 178, 240, 20 ) GUICtrlSetData(-1,"Mailbox Store (Christchurch Users)|Mailbox Store (North Island Users)|Mailbox Store (West Coast - Southland Users)" , "Mailbox Store (Christchurch Users)") GUISetState() $dummywindow = GUICreate("Dummy window for testing ", 200, 100) GUISwitch($mainwindow) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg(1) Select Case $msg[0] = $App1 $sPath1 = @SystemDir & "\DSADD user " $sF = GUICtrlRead($FirstN) ; FirstName $sL = GUICtrlRead($LastN) ;LastName $sD = GUICtrlRead($DES) ;Description $sO = GUICtrlRead($OFF) ;Office $sE = GUICtrlRead($Email) ;Email address $sLo = GUICtrlRead($LogonN) ;Logon Name $sPass = GUICtrlRead($Passw) ;Password $sUserOU = GUICtrlRead($UserOU) ;OU users will be placed into $sHD = "H:" ; Letter for home drive $sLog = "login.bat" ; Login script Name $sFP = GUICtrlRead($FP) ;Local file and print Server $sHMD = "\\"& $sFP & "\" & $sLo & "$" ;Home drive in profile tab setting $OU = '"CN='& $sF & ' ' & $sL & ',OU=' & $sUserOU & ',DC=se,DC=***********,DC=co,DC=nz"' ; user to create $sDis = '"'& $sF & ' '& $sL &'"' ;display name $sUPN = $sLo & "@se.**********.co.nz" $Wdrive = "\\"& $sFP & "\d$\data\Users" $MBStore = GUICtrlRead($MB) If $sF And $sL And $sD And $sO And $sE And $sLo And $sPass And $sUserOU And $sFP Then MsgBox ( 1 , 'OUTPUT FOR USER CREATION ' , 'User:= ' & $sPath1 & ' ' & $OU & ' -samid ' & $sLo & ' -upn ' & $sUPN & ' -fn ' & $sF & ' -ln ' & $sL & ' -display ' & $sDis & ' -pwd ' & $sPass & ' -desc ' & $sD & ' -office ' & $sO & ' -email ' & $sE & ' -hmdir ' & $sHMD & ' -hmdrv ' & $sHD & ' -loscr ' & $sLog ) ;RunWait($sPath1 & ' ' & $OU & ' -samid ' & $sLo & ' -upn ' & $sUPN & ' -fn ' & $sF & ' -ln ' & $sL & ' -display ' & $sDis & ' -pwd ' & $sPass & ' -desc ' & $sD & ' -office ' & $sO & ' -email ' & $sE & ' -hmdir ' & $sHMD & ' -hmdrv ' & $sHD & ' -loscr ' & $sLog) DriveMapDel("W:") DriveMapAdd( "W:", ""& $Wdrive & "") DirCreate( "W:\" & $sLo & "" ) DirCreate( "W:\" & $sLo & "\data" ) DriveMapDel("W:") ;Creates Mail box below for user $s_strServer = "CHCHEX01" $s_strExchangeOrg = "*************" $s_strDomain = "DC=se,DC=**********,DC=co,DC=nz" ;' These are the defaults, compare with your server and amend. $s_strAdminGroup = "Christchurch" $s_strStorageGroup = "First Storage Group" $s_strStoreName = $MBStore $s_strMailbox= "cn="& $sLo &"," ; User name for mailbox ;' Build LDAP $s_string $s_strMailbox = $s_strMailbox & "CN=" & $s_strStoreName $s_strMailbox = $s_strMailbox & ",CN=" & $s_strStorageGroup $s_strMailbox = $s_strMailbox & ",CN=InformationStore" $s_strMailbox = $s_strMailbox & ",CN=" & $s_strServer $s_strMailbox = $s_strMailbox & ",CN=Servers" $s_strMailbox = $s_strMailbox & ",CN=" & $s_strAdminGroup $s_strMailbox = $s_strMailbox & ",CN=Administrative Groups" $s_strMailbox = $s_strMailbox & ",CN=" & $s_strExchangeOrg $s_strMailbox = $s_strMailbox & ",CN=Microsoft Exchange" $s_strMailbox = $s_strMailbox & ",CN=Services" $s_strMailbox = $s_strMailbox & ",CN=Configuration" $s_strMailbox = $s_strMailbox & "," & $s_strDomain MsgBox(0,"EMAIL String for user mailbox creation","$s_strMailbox="&$s_strMailbox) ; ; <================Mail creation code would go here. ; Else MsgBox(48, "User Creation Error", "You must provide all required information.") EndIf Case $msg = $GUI_EVENT_CLOSE Exit Case $msg[0] = $App2 $sPath1 = @SystemDir & "\DSMOD user " $sF = GUICtrlRead($FirstN) ; FirstName $sL = GUICtrlRead($LastN) ;LastName $sD = GUICtrlRead($DES) ;Description $sO = GUICtrlRead($OFF) ;Office $sE = GUICtrlRead($Email) ;Email address $sLo = GUICtrlRead($LogonN) ;Logon Name $sPass = GUICtrlRead($Passw) ;Password $sUserOU = GUICtrlRead($UserOU) ;OU users will be placed into $sHD = "H:" ; Letter for home drive $sLog = "login.bat" ; Login script Name $sFP = GUICtrlRead($FP) ;Local file and print Server $sHMD = "\\"& $sFP & "\" & $sLo & "$" ;Home drive in profile tab setting $OU = '"CN='& $sF & ' ' & $sL & ',OU=' & $sUserOU & ',DC=se,DC=************,DC=co,DC=nz"' ; user to create $sDis = '"'& $sF & ' '& $sL &'"' ;display name $sUPN = $sLo & "@se.***********.co.nz" $Wdrive = "\\"& $sFP & "\d$\data\Users" If $sF And $sL And $sUserOU Then MsgBox ( 1 , 'OUTPUT FOR USER CREATION ' , 'User:= ' & $sPath1 & ' ' & $OU & ' -samid ' & $sLo & ' -upn ' & $sUPN & ' -fn ' & $sF & ' -ln ' & $sL & ' -display ' & $sDis & ' -pwd ' & $sPass & ' -desc ' & $sD & ' -office ' & $sO & ' -email ' & $sE & ' -hmdir ' & $sHMD & ' -hmdrv ' & $sHD & ' -loscr ' & $sLog ) Else MsgBox(48, "User Modicfication Error", "You must provide First Name, Last Name , Users OU") EndIf Case $msg = $GUI_EVENT_CLOSE Exit Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $mainwindow ExitLoop EndSelect WEnd The code below is an example of ADSI mailbox creation but I am lost as to how to convert to autoit. I am happy with what I have so far, as it creates the complete script line (if you run app you will see the msg box produce the output line ) Any help with this last task would help greatly as I feel once I see how it works I will be fine. CODESub ADSICreateMailBoxEnabledUser _ (MDBName,StorageGroup,Server,AdminGroup,Organization,DomainName,emailname,FirstName,LastName) 'split the domain name to get the directory name for it DomainDN = "dc=" & Replace(DomainName,".",",dc=") recip = "CN=" & emailname ' get the container Set objContainer = GetObject("LDAP://CN=users," & DomainDN) ' create a recipient Set objUser = objContainer.Create("User", recip) objUser.Put "samAccountName", emailname objUser.Put "sn", LastName objUser.Put "givenName", FirstName objUser.Put "userPrincipalName", emailname objUser.SetInfo objUser.SetPassword "123456" objUser.AccountDisabled = False Set objMailbox = objUser objMailbox.CreateMailbox "LDAP://CN=" & MDBName & _ ",CN=" & StorageGroup & _ ",CN=InformationStore" & _ ",CN=" & Server & _ ",CN=Servers" & _ ",CN=" & AdminGroup & _ ",CN=Administrative Groups" & _ ",CN=" & Organization & _ ",CN=Microsoft Exchange,CN=Services" & _ ",CN=Configuration," & DomainDN objUser.SetInfo End Sub Link to comment Share on other sites More sharing options...
ptrex Posted January 24, 2007 Share Posted January 24, 2007 (edited) @Steven Meier this would give you a good start expandcollapse popupFunc ADSICreateMailBoxEnabledUser _($MDBName,$StorageGroup,$Server,$AdminGroup,$Organization,$DomainName,$emailname,$FirstName,$LastName) ;split the domain name to get the directory name for it $DomainDN = "dc=" & StringReplace($DomainName,".",",dc=") $recip = "CN=" & $emailname ; get the container $objContainer = ObjGet("LDAP://CN=users," & $DomainDN) ; create a recipient $objUser = $objContainer.Create("User", $recip) $objUser.Put ("samAccountName", $emailname) $objUser.Put ("sn", $LastName) $objUser.Put ("givenName", $FirstName) $objUser.Put ("userPrincipalName", $emailname) $objUser.SetInfo() $objUser.SetPassword ("123456" ) $objUser.AccountDisabled = 0 $objMailbox = $objUser $objMailbox.CreateMailbox ("LDAP://CN=" & $MDBName & _) ",CN=" & $StorageGroup & _ ",CN=InformationStore" & _ ",CN=" & $Server & _ ",CN=Servers" & _ ",CN=" & $AdminGroup & _ ",CN=Administrative Groups" & _ ",CN=" & $Organization & _ ",CN=Microsoft Exchange,CN=Services" & _ ",CN=Configuration," & $DomainDN $objUser.SetInfo() EndFunc regards, ptrex Edited January 24, 2007 by ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Steven Meier Posted January 25, 2007 Author Share Posted January 25, 2007 Thanks Ptrex for the reply. For my Understanding could you explain a bit what its doing it and how? I understand the basics from Autoit, But have had a great deal of difficulty understanding the email box creation stuff. Cheers Steve Link to comment Share on other sites More sharing options...
Steven Meier Posted January 25, 2007 Author Share Posted January 25, 2007 I added the code to my script . Didi not add any code to call the func..but I get errors Error Unknown Function Name $objContainer = ObjGet $objContainer = ^Error Link to comment Share on other sites More sharing options...
ptrex Posted January 26, 2007 Share Posted January 26, 2007 @ All parameters of the function need to have values specified, otherwise it will give errors !! ADSICreateMailBoxEnabledUser($MDBName,$StorageGroup,$Server,$AdminGroup,$Organization,$DomainName,$emailname,$FirstName,$LastName) When calling the function you need to set values for all these varialbles. I didn't write the script I only translated it for you from VBS to AU3. regards, ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Steven Meier Posted January 29, 2007 Author Share Posted January 29, 2007 No, I added the code for the func to my script, but no code to call the func, and that error I mentioned in the above post happened when I went to execute the code, so I am actually not at this stage calling the function. Cheers steve 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