It is currently Sat Mar 06, 2021 3:32 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: How to obtain the name of the current netbios workgroup?
PostPosted: Tue Nov 12, 2019 5:09 pm 
Offline
Addict
Addict

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 3371
How can I obtain information about the current workgroup and domain for the current user?


Top
 Profile  
Reply with quote  
 Post subject: Re: How to obtain the name of the current netbios workgroup?
PostPosted: Wed Nov 13, 2019 7:08 am 
Offline
Addict
Addict

Joined: Sat Feb 08, 2014 3:26 pm
Posts: 989
Mistrel wrote:
How can I obtain information about the current workgroup and domain for the current user?

Code:
RunProgram("wmic", "computersystem get workgroup, domain", "")

See also API

:wink:


Top
 Profile  
Reply with quote  
 Post subject: Re: How to obtain the name of the current netbios workgroup?
PostPosted: Thu Nov 14, 2019 8:12 pm 
Offline
Addict
Addict

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 3371
I mean with Win32 and library calls. Not the output from a console program.


Top
 Profile  
Reply with quote  
 Post subject: Re: How to obtain the name of the current netbios workgroup?
PostPosted: Fri Nov 15, 2019 8:36 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1814
Location: Germany
Tested succcessfully on Window 10 x64 V1809 with PB 5.46 in ASCII and Unicode mode and PB 5.71 (with 32-bit and 64-bit compilation):
Code:
EnableExplicit

#ComputerNameDnsDomain = 2

Enumeration NETSETUP_JOIN_STATUS
  #NetSetupUnknownStatus
  #NetSetupUnjoined
  #NetSetupWorkgroupName
  #NetSetupDomainName
EndEnumeration

Import ""
  GetComputerNameExA(NameType.I, *Buffer, *BufferSize)
EndImport

Prototype.I NetGetJoinInformation(Host.P-Unicode, *Buffer, BufferType.I)

Define BufferSize.I
Define *DomainBuffer
Define Info.S
Define JoinInfo.NetGetJoinInformation
Define JoinStatus.I
Define *NameBuffer

If InitNetwork()
  If OpenLibrary(0, "NetAPI32.DLL")
    JoinInfo = GetFunction(0, "NetGetJoinInformation")
   
    If JoinInfo
      If JoinInfo(ComputerName(), @*NameBuffer, @JoinStatus) = 0
        Select JoinStatus
          Case #NetSetupUnknownStatus
            Info = "Unknown network status!"
          Case #NetSetupUnjoined
            Info = "Not joined to any workgroup or domain!"
          Case #NetSetupWorkgroupName
            Info = "Joined to the workgroup " +
              PeekS(*NameBuffer, -1, #PB_Unicode)
          Case #NetSetupDomainName
            ; ----- Doesn't display top level domain, for example local in
            ;       xxx.local
            ; Info = "Joined to the domain " +
            ; PeekS(*NameBuffer, -1, #PB_Unicode)

            ; ----- Display second level domain plus top level domain
            GetComputerNameExA(#ComputerNameDnsDomain, 0, @BufferSize)
           
            If BufferSize
              *DomainBuffer = AllocateMemory(BufferSize)
             
              If GetComputerNameExA(#ComputerNameDnsDomain, *DomainBuffer,
                @BufferSize)
                Info = "Joined to the domain " +
                  PeekS(*DomainBuffer, -1, #PB_Ascii)
              EndIf
             
              FreeMemory(*DomainBuffer)
            EndIf
        EndSelect
      EndIf
    EndIf
   
    NetApiBufferFree_(*NameBuffer)
    CloseLibrary(0)
   
    MessageRequester("Detect if joined to domain or workgroup",
      Info,
      #MB_ICONINFORMATION)
  EndIf
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: How to obtain the name of the current netbios workgroup?
PostPosted: Fri Nov 15, 2019 8:52 am 
Offline
Addict
Addict

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 3371
That's it. Thank you. :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye