jp10558 Posted July 8, 2015 Share Posted July 8, 2015 So I'm writing a post install script for my Win7 boxes, and I log in as a local user the first time to do some things that only seem to work from within a user account. I want to check that the domain join succeeded or try it again, but the obvious @LogonDomain or @LogonDNSDomain only show if the account currently logged in is part of the domain - which it isn't. How can I check the domain name from a local user account? If I right click on Computer and go to Properties, it says "Domain" and shows the domain name "example.com"... I want to check "example.com" against a value, but I'm not sure how to pull that value? Link to comment Share on other sites More sharing options...
water Posted July 8, 2015 Share Posted July 8, 2015 Does this script - generated by Scriptomatic - give you the needed information?expandcollapse popup; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NTDomain", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "Caption: " & $objItem.Caption & @CRLF $Output = $Output & "ClientSiteName: " & $objItem.ClientSiteName & @CRLF $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF $Output = $Output & "DcSiteName: " & $objItem.DcSiteName & @CRLF $Output = $Output & "Description: " & $objItem.Description & @CRLF $Output = $Output & "DnsForestName: " & $objItem.DnsForestName & @CRLF $Output = $Output & "DomainControllerAddress: " & $objItem.DomainControllerAddress & @CRLF $Output = $Output & "DomainControllerAddressType: " & $objItem.DomainControllerAddressType & @CRLF $Output = $Output & "DomainControllerName: " & $objItem.DomainControllerName & @CRLF $Output = $Output & "DomainGuid: " & $objItem.DomainGuid & @CRLF $Output = $Output & "DomainName: " & $objItem.DomainName & @CRLF $Output = $Output & "DSDirectoryServiceFlag: " & $objItem.DSDirectoryServiceFlag & @CRLF $Output = $Output & "DSDnsControllerFlag: " & $objItem.DSDnsControllerFlag & @CRLF $Output = $Output & "DSDnsDomainFlag: " & $objItem.DSDnsDomainFlag & @CRLF $Output = $Output & "DSDnsForestFlag: " & $objItem.DSDnsForestFlag & @CRLF $Output = $Output & "DSGlobalCatalogFlag: " & $objItem.DSGlobalCatalogFlag & @CRLF $Output = $Output & "DSKerberosDistributionCenterFlag: " & $objItem.DSKerberosDistributionCenterFlag & @CRLF $Output = $Output & "DSPrimaryDomainControllerFlag: " & $objItem.DSPrimaryDomainControllerFlag & @CRLF $Output = $Output & "DSTimeServiceFlag: " & $objItem.DSTimeServiceFlag & @CRLF $Output = $Output & "DSWritableFlag: " & $objItem.DSWritableFlag & @CRLF $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF $Output = $Output & "Name: " & $objItem.Name & @CRLF $Output = $Output & "NameFormat: " & $objItem.NameFormat & @CRLF $Output = $Output & "PrimaryOwnerContact: " & $objItem.PrimaryOwnerContact & @CRLF $Output = $Output & "PrimaryOwnerName: " & $objItem.PrimaryOwnerName & @CRLF $strRoles = $objItem.Roles(0) $Output = $Output & "Roles: " & $strRoles & @CRLF $Output = $Output & "Status: " & $objItem.Status & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_NTDomain" ) Endif Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2)) EndFunc My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki  Link to comment Share on other sites More sharing options...
jp10558 Posted July 8, 2015 Author Share Posted July 8, 2015 It does! Thanks! Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 8, 2015 Moderators Share Posted July 8, 2015 (edited) I guess I don't understand why @LogonDomain doesn't work for you? If you do something like this, it should give you the answer you're after:MsgBox(0, "", (@LogonDomain = @ComputerName) ? "Domain Join Failed!" : "Domain Join Successful!") Edited July 8, 2015 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
water Posted July 8, 2015 Share Posted July 8, 2015 As long as you do not need to know the name of the domain your solution should work as well. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki  Link to comment Share on other sites More sharing options...
jguinch Posted July 8, 2015 Share Posted July 8, 2015 (edited) Also, you can use the WinAPI NetGetJoinInformation function :expandcollapse popupConst Enum $NetSetupUnknownStatus = 0, $NetSetupUnjoined, $NetSetupWorkgroupName, $NetSetupDomainName Local $sJoinType Local $aNetGetJoinInformation = _WinAPI_NetGetJoinInformation() Switch $aNetGetJoinInformation[0] Case $NetSetupUnknownStatus $sJoinType = "The status is unknown." Case $NetSetupUnjoined $sJoinType = "The computer is not joined." Case $NetSetupWorkgroupName $sJoinType = "The computer is joined to a workgroup : " & $aNetGetJoinInformation[1] Case $NetSetupDomainName $sJoinType = "The computer is joined to a domain : " & $aNetGetJoinInformation[1] EndSwitch MsgBox(0, "NetGetJoinInformation", $sJoinType) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WinAPI_NetGetJoinInformation ; Description ...: Retrieves join status information for the specified computer. ; Syntax ........: _WinAPI_NetGetJoinInformation([$sComputerName = ""]) ; Parameters ....: $sComputerName - [optional] Computer name (default is the local computer) ; Return values .: Success : an array : ; - $array[0] = Join status of the specified compute (see remarks) ; - $array[1] = Name of the domain or workgroup to which the computer is joined ; Remarks .......: $array[0] can contain the following values : ; - $NetSetupUnknownStatus : The status is unknown. ; - $NetSetupUnjoined : The computer is not joined. ; - $NetSetupWorkgroupName : The computer is joined to a workgroup. ; - $NetSetupDomainName : The computer is joined to a domain. ; =============================================================================================================================== Func _WinAPI_NetGetJoinInformation($sComputerName = "") Local $aRet = DllCall("Netapi32.dll", "int", "NetGetJoinInformation", "wstr", $sComputerName, "ptr*", "", "int*", 0) If @error Then Return SetError(@error, 0, 0) Local $pNameBuffer = $aRet[2] Local $tName = DllStructCreate("wchar[" & _BufferSize($pNameBuffer) &"]", $pNameBuffer) Local $sName = DllStructGetData($tName, 1) DllCall("netapi32.dll", "int", "NetApiBufferFree", "ptr", $pNameBuffer) Local $aReturn[2] = [ Int($aRet[3]), $sName ] Return $aReturn EndFunc Func _BufferSize($pBuffer) Local $aResult = DllCall("Netapi32.dll", "int", "NetApiBufferSize", "ptr", $pBuffer, "dword*", 0) If @error OR $aResult[0] <> 0 Then Return SetError(@error, @extended, 0) Return $aResult[2] EndFunc Edited July 8, 2015 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList     Firefox ConfigurationArray multi-dimensions, Printer Management UDF  Link to comment Share on other sites More sharing options...
water Posted July 8, 2015 Share Posted July 8, 2015 Thanks for that. Might come in handy in the future My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki  Link to comment Share on other sites More sharing options...
orbs Posted July 8, 2015 Share Posted July 8, 2015 although the WinAPI method beats, there is also the registry way:Local $sDomain=RegRead('HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters','Domain') If @error Then ConsoleWrite('Error: unable to get domain from registry' & @LF) If $sDomain='' Then ConsoleWrite('not joined to a domain' & @LF) Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration -  literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff  Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 8, 2015 Moderators Share Posted July 8, 2015 As long as you do not need to know the name of the domain your solution should work as well.Agreed, I was taking it as a yes/no requirement only - did the domain join work or not. Perhaps the bigger question, however, is how the OP is doing his domain join. If he is doing that as part of the script, he should be checking the error at the point of calling the function rather than after a reboot. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! 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