DemonAngel Posted January 17, 2011 Share Posted January 17, 2011 Morning guys, I have this vbscript that provides details on the subnet that a pc is logged on to. It obtains this information from AD sites and services. The problem I have is when I change the script extention to AU3 and make the relevant formatting changes the information comes back as blank. Here is the VBScript Subnet = "SubnetName" set rootDse = GetObject( "LDAP://RootDSE" ) ConfigContainer = rootDse.Get( "configurationNamingContext" ) set con = createobject("adodb.connection") set Com = createobject("adodb.command") con.provider="ADsDSOOBJECT" con.open "ADs Provider" set Com.ActiveConnection = con Com.CommandText= "<LDAP://" & ConfigContainer & ">;(&(objectCategory=subnet)(name=" & subnet & "*));name,siteObject,location;subtree" set rs = com.execute RS.movefirst getlocation = rs.fields("location") wscript.echo getlocation This is the AutoIT Code I converted it into. $Subnet = "SubnetName" $rootDse = ObjGet( "LDAP://RootDSE" ) $ConfigContainer = $rootDse.Get( "configurationNamingContext" ) $Conn = objcreate("adodb.connection") $Com = objcreate("adodb.command") $Conn.provider="ADsDSOObject" $Conn.open("ADs Provider") $Com.ActiveConnection = $Conn $Com.CommandText = "<LDAP://" & $ConfigContainer & ">;(&(name=" & $subnet & "));name,siteObject,location;subtree" $rs = $Com.execute $rs.movefirst MsgBox(0,"",$rs.fields("location")) Thank you in advance for any assistance provided. Link to comment Share on other sites More sharing options...
kylomas Posted January 17, 2011 Share Posted January 17, 2011 DemonAngel, I added a check after objget and it looks like you are not getting the object that you expect. $rootDse = ObjGet( "LDAP://RootDSE" ) if $rootdse = 0 then msgbox(0,'','Error from objget RootDSE = ' & @error) kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
DemonAngel Posted January 17, 2011 Author Share Posted January 17, 2011 Hi Kylomas, I ran the code mentioned above, however no errors were generated. Furthermore I used a msgbox on the first instance of $ConfigContainer and it returned the expected value. CN=Configuration,DC=XXXX,DC=yyy So I think the initial objget is working as extected. Link to comment Share on other sites More sharing options...
kylomas Posted January 17, 2011 Share Posted January 17, 2011 DemonAngel, Tried to run the origional VBS on my pc without success. You're going to need a "real" expert for this, sorry! kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
DemonAngel Posted January 17, 2011 Author Share Posted January 17, 2011 Thank you for trying Kulomas. The original vbs will only run if you have AD Subnets configured and change the Subnet = "SubnetName" Section to reflect the name of your configured subnet. I have searched the entire AutoIT form and it doesnt seem like anyone has been working with obtaining subnet information from AD yet. Link to comment Share on other sites More sharing options...
kylomas Posted January 17, 2011 Share Posted January 17, 2011 DemonAngel, There are some realy sharp and helpfull people in this forum...I suspect that one of them may be playing with this now, Good Luck! kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
ptrex Posted January 18, 2011 Share Posted January 18, 2011 (edited) @DemonAngel I hope this get's you going. expandcollapse popup#include <Array.au3> ; List all Sites Dim $avArray[1] $objRootDSE = ObjGet("LDAP://RootDSE") $strConfigurationNC = $objRootDSE.Get("configurationNamingContext") $strSitesContainer = "LDAP://cn=Sites," & $strConfigurationNC $objSitesContainer = ObjGet($strSitesContainer) $objSitesContainer.Filter = _ArrayAdd($avArray, "site") ; ArrayCreate For $objSite In $objSitesContainer ConsoleWrite("Name: " & $objSite.Name & @CRLF) Next ; List all Subnets on AD Sites Dim $avArray1[1] Dim $avArray2[1] $objRootDSE = ObjGet("LDAP://RootDSE") $strConfigurationNC = $objRootDSE.Get("configurationNamingContext") $strSubnetsContainer = "LDAP://cn=Subnets,cn=Sites," & $strConfigurationNC ConsoleWrite($strSubnetsContainer & @CRLF) $objSubnetsContainer = ObjGet($strSubnetsContainer) $objSubnetsContainer.Filter = _ArrayAdd($avArray1, "subnet") $objHash = ObjCreate("Scripting.Dictionary") For $objSubnet In $objSubnetsContainer $objSubnet.GetInfoEx (_ArrayAdd($avArray2, "siteObject"), 0) $strSiteObjectDN = $objSubnet.Get("siteObject") $strSiteObjectName = StringSplit(StringSplit($strSiteObjectDN, ",",0), "=",1) If $objHash.Exists($strSiteObjectName) Then $objHash($strSiteObjectName) = $objHash($strSiteObjectName) & "," & _ StringSplit($objSubnet.Name, "=",1) Else $objHash.Add ($strSiteObjectName, StringSplit($objSubnet.Name, "=",1)) EndIf Next For $strKey In $objHash.Keys ConsoleWrite($strKey & "," & $objHash($strKey) & @CRLF) Next But I can't test it because I don't have subnets configured. rgds ptrex Edited January 18, 2011 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...
DemonAngel Posted January 18, 2011 Author Share Posted January 18, 2011 Hi ptrex The first section of the code provided above executed and returned the expected information. The List all subnets on AD sites however returns the following error message. \TEST\Subnet3.au3 (36) : ==> The requested action with this object has failed.: $objSubnet.GetInfoEx (_ArrayAdd($avArray2, "siteObject"), 0) $objSubnet.GetInfoEx (_ArrayAdd($avArray2, "siteObject"), 0)^ ERROR ->14:45:19 AutoIT3.exe ended.rc:1 >Exit code: 1 Time: 2.759 Thank you for your time so far, we are definitely getting closer. Link to comment Share on other sites More sharing options...
DemonAngel Posted January 19, 2011 Author Share Posted January 19, 2011 @ptrex + anyone that would require this code. I modified your second example a bit and its doing exactly what I need now. Thank you for your assistance. Dim $avArray1[1] $Subnet = "SubnetNameGoesHere" $objRootDSE = ObjGet("LDAP://RootDSE") $strConfigurationNC = $objRootDSE.Get("configurationNamingContext") $strSubnetsContainer = "LDAP://cn=Subnets,cn=Sites," & $strConfigurationNC $objSubnetsContainer = ObjGet($strSubnetsContainer) $objSubnetsContainer.Filter = _ArrayAdd($avArray1, "subnet") For $objSubnet In $objSubnetsContainer If StringInStr($objSubnet.cn,$Subnet) Then $objSubnetInfo = ObjGet($objSubnet.adspath) MsgBox(0,"",$objSubnetInfo.Location) ExitLoop EndIf Next 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