shornw Posted September 25, 2009 Share Posted September 25, 2009 Hi, This is a very simple question (I hope) but I have limited time to investigate it as it impacts a major go-live on wed morning, so I apologise in advance, I'm not being lazy just incredibly pushed for time. Is there a simple way to identify which domain the computer account is on. The @logondomain and @logonDNSdomain identify the domain that the user is logging into. Thanks for looking and your help [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 25, 2009 Share Posted September 25, 2009 Hi, This is a very simple question (I hope) but I have limited time to investigate it as it impacts a major go-live on wed morning, so I apologise in advance, I'm not being lazy just incredibly pushed for time. Is there a simple way to identify which domain the computer account is on. The @logondomain and @logonDNSdomain identify the domain that the user is logging into. Thanks for looking and your help This is how it's done at the initialization of the ADFunctions.au3 UDF: Global $objConnection = ObjCreate("ADODB.Connection") ; Create COM object to AD $objConnection.ConnectionString = "Provider=ADsDSOObject" $objConnection.Open("Active Directory Provider") ; Open connection to AD Global $objRootDSE = ObjGet("LDAP://RootDSE") Global $strDNSDomain = $objRootDSE.Get("defaultNamingContext") ; Retrieve the current AD domain name Global $strHostServer = $objRootDSE.Get("dnsHostName") ; Retrieve the name of the connected DC ConsoleWrite("Domain = " & $strDNSDomain & @LF) ConsoleWrite("DC Used = " & $strHostServer & @LF) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
shornw Posted September 25, 2009 Author Share Posted September 25, 2009 Hi Thanks for that. Being an old DOS head I came up with this as a workable solution. #include <Process.au3> _RunDOS("net config workstation > %temp%\domain.txt") $fa = FileReadLine(@TempDir &"\domain.txt", 11) $fb = StringTrimLeft($fa, 37) MsgBox(0, "", $fb) its probably not the best way to do things but it's the simplest I could come up with in the short time frame I have available. If anyone has a better solution I'd be interested and grateful. Thanks [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 25, 2009 Share Posted September 25, 2009 (edited) Hi Thanks for that. Being an old DOS head I came up with this as a workable solution. #include <Process.au3> _RunDOS("net config workstation > %temp%\domain.txt") $fa = FileReadLine(@TempDir &"\domain.txt", 11) $fb = StringTrimLeft($fa, 37) MsgBox(0, "", $fb) its probably not the best way to do things but it's the simplest I could come up with in the short time frame I have available. If anyone has a better solution I'd be interested and grateful. Thanks Being an old DOS head myself, I wouldn't trust that at all! How do you know the domain will be line 11 for all PCs? On my current workstation, line 11 of that output is: NetBT_Tcpip_{99646A26-A16A-4C49-AB65-280AC31B419F} (000CDD00651A) At least parse it through FIND: $sExtCmd = 'net config workstation | find /i "Workstation Domain DNS Name"' _RunDOS($sExtCmd & ' > %temp%\domain.txt') $fa = StringTrimLeft(FileReadLine(@TempDir & '\domain.txt', 1), 37) Edited September 25, 2009 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
TurionAltec Posted September 25, 2009 Share Posted September 25, 2009 I'm also a DOShead. Rather than send it to a temporary file, I just read the Stdout directly. This is one of the few times in my life I've used @comspec and only because I'm piping it through find. Very frequently it's unnecessarily invoked, and no one else seems to have a problem with starting unnecessary programs. The only reason I use Find is is because it's easier than parsing for the CR/LF that follows the name. #include <Constants.au3> $pid=Run(@ComSpec & " /c "& @SystemDir&'\net config workstation | find /i "Workstation Domain DNS Name"',"",@sw_hide,$STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($pid) $output = StdoutRead($pid) ConsoleWrite($output&@crlf) $WSDNS=StringStripWS(StringMid($output,StringinStr($output,"Workstation Domain DNS Name")+37,20),3) Link to comment Share on other sites More sharing options...
TurionAltec Posted September 25, 2009 Share Posted September 25, 2009 Here's some code that processes the whole output. This is useful if you want to pull several different pieces of information from net config workstation. The "37" offset is for the columns output by the command. If you use this code to process the output of different programs you'll have to adjust it. #include <Constants.au3> $pid=Run(@SystemDir&'\net config workstation',"",@sw_hide,$STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($pid) $output = StdoutRead($pid) $WSdomain=_FindInString($output,"Workstation domain") $WSDNS=_FindInString($output,"Workstation Domain DNS Name") $logondomain=_FindInString($output,"Logon domain") ConsoleWrite($WSdomain&@crlf&$WSDNS&@crlf&$logondomain&@CRLF) Func _FindInString($data,$query) $startoffset=StringinStr($data,$query) +37 $endoffset=StringinStr($data,@CR,0,1,$startoffset) return StringStripWS(StringMid($data,$startoffset,$endoffset-$startoffset),3) EndFunc 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