Sign in to follow this  
Followers 0
Anteaus

Workgroup or Domain - how to identify?

2 posts in this topic

#1 ·  Posted (edited)

I'm writing a script which will limit access based on the computer's domain or workgroup membership. To do this I need to know what workgroup (or domain) the computer is a member of (as defined in the 'System' Control Panel.) Sounds trivial. Ain't, as I found out!

The environment-variables don't seem to include these items, so presumably they cannot be accessed by EnvGet() either. The @LogonDomain or @LogonDNSDomain values don't necessarily reflect these values either, it depends on circumstances, and although there is a 'USERDOMAIN' environment variable, on a workgroup computer, perversely this is the computer's name rather than its workgroup.

-Ah, I said, the values MUST be in the registry somewhere, so setting a workgroup-name that couldn't possibly occur as any other registry-string, after the obligtory restart I searched the registry for the same string. Not found. Hmmph... :)

-Any ideas?

Edited by Anteaus

Share this post


Link to post
Share on other sites



I'm writing a script which will limit access based on the computer's domain or workgroup membership. To do this I need to know what workgroup (or domain) the computer is a member of (as defined in the 'System' Control Panel.) Sounds trivial. Ain't, as I found out!

The environment-variables don't seem to include these items, so presumably they cannot be accessed by EnvGet() either. The @LogonDomain or @LogonDNSDomain values don't necessarily reflect these values either, it depends on circumstances, and although there is a 'USERDOMAIN' environment variable, on a workgroup computer, perversely this is the computer's name rather than its workgroup.

-Ah, I said, the values MUST be in the registry somewhere, so setting a workgroup-name that couldn't possibly occur as any other registry-string, after the obligtory restart I searched the registry for the same string. Not found. Hmmph... ;)

-Any ideas?

Try this:

$oMyError = ObjEvent("AutoIt.Error", "ComErrFunc") ; Prevents COM error crashing script

$oAD = ObjCreate("ADSystemInfo")
If IsObj($oAD) Then
    $sComputer = $oAD.ComputerName
    If @error Then
        MsgBox(64, "Results", "Not a domain member: " & @ComputerName)
    Else
        MsgBox(64, "Results", "Domain member: " & $sComputer)
    EndIf
Else
    MsgBox(16, "Error", "Failed to create $oAD ADSystemInfo object.")
EndIf

Func ComErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    Return SetError(1, $HexNumber, 0)
EndFunc   ;==>ComErrFunc

:)


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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0