RagnaroktA Posted October 31, 2005 Share Posted October 31, 2005 Will this code work properly when converted? The original vb script: expandcollapse popupOption Explicit Dim objRootDSE, strDNSDomain, objConnection, objCommand, strQuery Dim objRecordSet, strComputerDN, strOS ' Determine DNS domain name from RootDSE object. Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext") ' Use ADO to search Active Directory for all computers. Set objCommand = CreateObject("ADODB.Command") Set objConnection = CreateObject("ADODB.Connection") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" objCommand.ActiveConnection = objConnection strQuery = "<LDAP://" & strDNSDomain & ">;(objectCategory=computer);distinguishedName,operatingSystem;subtree" objCommand.CommandText = strQuery objCommand.Properties("Page Size") = 100 objCommand.Properties("Timeout") = 30 objCommand.Properties("Cache Results") = False Set objRecordSet = objCommand.Execute ' Enumerate computer objects with server operating systems. Do Until objRecordSet.EOF strOS = objRecordSet.Fields("operatingSystem") If InStr(UCase(strOS), "SERVER") > 0 Then strComputerDN = objRecordSet.Fields("distinguishedName") Wscript.Echo strComputerDN End If objRecordSet.MoveNext Loop ' Clean up. objConnection.Close Set objRootDSE = Nothing Set objCommand = Nothing Set objConnection = Nothing Set objRecordSet = Nothing Wscript.Echo "Done" My (probably borked) converted AutoIt code: ; Determine DNS domain name from RootDSE object. $objRootDSE = ObjGet("LDAP://RootDSE") $strDNSDomain = $objRootDSE.Get("defaultNamingContext") ; Use ADO to search Active Directory for all computers. $objCommand = ObjCreate("ADODB.Command") $objConnection = ObjCreate("ADODB.Connection") $objConnection.Provider = "ADsDSOObject" $objConnection.Open "Active Directory Provider" $objCommand.ActiveConnection = $objConnection $strQuery = "<LDAP://" & $strDNSDomain & ">;(objectCategory=computer);distinguishedName,operatingSystem;subtree" $objCommand.CommandText = $strQuery $objCommand.Properties("Page Size") = 100 $objCommand.Properties("Timeout") = 30 $objCommand.Properties("Cache Results") = False $objRecordSet = $objCommand.Execute ; Enumerate computer objects with server operating systems. Do $strOS = $objRecordSet.Fields("operatingSystem") If StringInStr(StringUpper($strOS), "SERVER") > 0 Then $strComputerDN = $objRecordSet.Fields("distinguishedName") ConsoleWrite($strComputerDN) EndIf $objRecordSet.MoveNext Until $objRecordSet.EOF ; Clean up. $objConnection.Close Will it convert and work? If so, what am I doing wrong? Thanks! Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki Link to comment Share on other sites More sharing options...
DaleHohm Posted October 31, 2005 Share Posted October 31, 2005 There's nothing glaringly wrong syntax-wise. What happens when you try to run it? Does the vbs script work for you? Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
RagnaroktA Posted October 31, 2005 Author Share Posted October 31, 2005 (edited) There's nothing glaringly wrong syntax-wise.What happens when you try to run it? Does the vbs script work for you?DaleWhen run, the VBScript will enumerate all servers on the domain and list them in the console. (I use PrimalScript, so it's putting the list in the Output window.)The au3 seems to just exit with the following exit code:Exit code: 0 , 0000hSo nothing seems to be wrong with it persey... it's just not listing the domain servers... Edited October 31, 2005 by RagnaroktA Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki Link to comment Share on other sites More sharing options...
DaleHohm Posted October 31, 2005 Share Posted October 31, 2005 I'd suggest some basic troubleshooting to narrow down where the problem is. Use isObj() to test your object variables. If your COM commands fail they typically will not be. Check your recordset .Count to see if it actually gets filled with anything etc. Narrow down where the trouble lies and then you can focus on specific operations. Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
jefhal Posted November 8, 2005 Share Posted November 8, 2005 Did you ever get this script debugged? I'm trying to do a similar script, but am lost... Option Explicit Dim objRootDSE, strDNSDomain, objConnection, objCommand, strQuery Dim objRecordSet, strComputerDN, strOS ...... ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format Link to comment Share on other sites More sharing options...
jonesy Posted November 10, 2006 Share Posted November 10, 2006 Did you ever get this to work? I can get the VB script to work, but can't see what's wrong with the AutoIT script. Have you incorporated it into your Remote Administration Suite? (This is looking very impressive by the way). My requirement is to compare records of PCs built using Symantec iCommand, recorded in Active Directory and Centennial, and see which ones still exist and are still in use! I'm fairly happy with extracting the info from other sources, but getting the list of PCs from multiple OUs in 4 domains is a bit of a pain. The VB script shows it can be done. One extra bit of info I will need to track down is the last time the computer password (not user) was changed within AD. I can get a manual export using Hyena, but doing it programmatically would be great. Ideally I'd like to delete redundant computers, which will be the last stage. Lots and lots of requirements. I keep trawling the AutoIT forums, picking up bits here and there, and reading MSDN, but I've still not solved it yet. To give you some idea of the scale of my problem - I can find references to nearly 8,000 PCs, and yet we should only have less than 5,000. So which 3,000 PCs should be deleted? Get it wrong and up to 3,000 users could be complaining... Link to comment Share on other sites More sharing options...
ptrex Posted November 10, 2006 Share Posted November 10, 2006 This is how you would search users in AD expandcollapse popupLocal $objCommand = ObjCreate("ADODB.Command") Local $objConnection = ObjCreate("ADODB.Connection") $objConnection.Provider = "ADsDSOObject" $objConnection.Open ("Active Directory Provider") $objCommand.ActiveConnection = $objConnection Local $strBase = "<GC://dc=YOURDOMAINNAME,dc=COM>" Local $strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=*))" Local $strAttributes = "cn,sAMAccountName,displayName,sn,distinguishedName" Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree" $objCommand.CommandText = $strQuery $objCommand.Properties ("Page Size") = 100 $objCommand.Properties ("Timeout") = 30 $objCommand.Properties ("Cache Results") = False $ADS_SCOPE_SUBTREE = 2 $objCommand.Properties ("searchscope") = $ADS_SCOPE_SUBTREE Local $objRecordSet = $objCommand.Execute ConsoleWrite("Users"&@CR&"---------"&@CR) While Not $objRecordSet.EOF $strName = $objRecordSet.Fields ("sAMAccountName").Value $strCN = $objRecordSet.Fields ("cn").value $strdisplayName = $objRecordSet.Fields ("displayName").value $strSN = $objRecordSet.Fields ("SN").value $strdistinguishedName = $objRecordSet.Fields ("distinguishedName").value ;FileWriteLine("Users.txt",$objRecordSet.Fields ("sAMAccountName").Value) ConsoleWrite($objRecordSet.Fields ("sAMAccountName").Value&@cr) $objRecordSet.MoveNext WEnd $objConnection.Close $objConnection = "" $objCommand = "" $objRecordSet = "" 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...
arcker Posted November 10, 2006 Share Posted November 10, 2006 or add the objget("LDAP//RootDSE") to connect to the default domain (the domain where you are connected) -- Arck System _ Soon -- Ideas make everything "La critique est facile, l'art est difficile" Projects :[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list] 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