Obtain the Name of the Domain to which the Computer Belongs
Keywords: domain account computer machine member
Question:
I need to get the domain name that my machine is a member of. How can this be accomplished?Answer:
;Sample code to obtain the name of the domain to which the computer belongs #DefineFunction GetDomainName() Locator = ObjectOpen("WbemScripting.SWbemLocator") Service = Locator.ConnectServer() Security = Service.Security_ Security.ImpersonationLevel = 3 Class = "Win32_ComputerSystem" Instance = Service.InstancesOf(Class) hEnum = ObjectCollectionOpen(Instance) While 1 Obj = ObjectCollectionNext(hEnum) If Obj == 0 Then Break domain = Obj.Domain EndWhile ObjectCollectionClose(hEnum) ObjectClose(Instance) ObjectClose(Security) ObjectClose(Service) ObjectClose(Locator) return domain #EndFunction dom = GetDomainName() Message("Name of the domain to which the computer belongs", dom)