habe mir immer die frage gestellt ob ein rechner im netzwerk mitglied einer domäne oder einer arbeitsgruppe ist,
die darstellung bei Windows ist ziemlich verwirrend diesbezueglich.
zum beispiel wenn ein rechner der arbeitsgruppe "Purebasic" gehört und es existiert eine Domäne mit gleichen Namen,
dann würde es aussehen(nezwerkumgebung) als ob mein rechner mitglied der Domäne währe!
Windows gibt keinerlei hinweise dazu .
anbei ein beispiel das es ermöglicht festzustellen ob ein rechner einer Arbeitsgruppe der Domäne dazugehört.
dafür wird ein Api call "NetGetJoinInformation" der Netapi32.dll verwendet.
Ciao
jpd
Code: Alles auswählen
; ***********************************************
; *
; * 'NetJoinInformation.pb'
; *
; * Author: jpd
; * Created: October 2007
; * Version: PureBasic V4.02,V4.10b4
; *
; * idea: http://vbnet.mvps.org/index.html?code/network/netgetjoininformation.htm
; * VB Author: Randy Birch
; ***********************************************
; EnableUnicode
; PureBasic Visual Designer v3.95 build 1485 (PB4Code)
#NERR_SUCCESS = 0
#MAX_PREFERRED_LENGTH = -1
#NetJoinInformation=1
;- Window Constants
;
Enumeration
#Win_join
EndEnumeration
;- Gadget Constants
;
Enumeration
#SComp
#Txt_Group
#Txt_join
#SStatus
#Btn_join
EndEnumeration
Procedure Open_Win_join()
If OpenWindow(#Win_join, 220, 0, 602, 151, "NetGetJoinInformation", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
If CreateGadgetList(WindowID(#Win_join))
StringGadget(#SComp, 300, 20, 280, 30, "")
TextGadget(#Txt_Group, 20, 20, 260, 30, "Computer:")
TextGadget(#Txt_join, 20, 60, 270, 30, "Join status:")
StringGadget(#SStatus, 300, 60, 280, 30, "")
ButtonGadget(#Btn_join, 20, 100, 560, 30, "NetGetJoinInformation")
EndIf
EndIf
EndProcedure
;IncludeFile "NetJoinInformation_Common.pb"
Procedure.s GetJoinStatus(dwStatus.l)
Protected GetJoinStatus.s
Select dwStatus
Case 0: GetJoinStatus = "The status is unknown"
Case 1: GetJoinStatus = "The computer is not joined"
Case 2: GetJoinStatus = "The computer is joined to a workgroup"
Case 3: GetJoinStatus = "The computer is joined to a domain"
Default: GetJoinStatus = "dwStatus outside valid enum range"
EndSelect
ProcedureReturn GetJoinStatus
EndProcedure
Procedure.s NetJoinInformation(Comp.s)
Comp=RemoveString(comp, "\" );[, Modus])
Comp="\\"+Comp
If OpenLibrary(#NetJoinInformation,"Netapi32.dll")
Callres= CallFunction(#NetJoinInformation,"NetGetJoinInformation",Comp,@*bufptr,@dwBufferType) ;= #NERR_SUCCESS
If Callres =#NERR_SUCCESS
;If NetGetJoinInformation_(Comp,@*bufptr, @dwBufferType) = #NERR_SUCCESS
Debug Callres
group.s=PeekS(*bufptr)
info.s=GetJoinStatus(dwBufferType)
CloseLibrary(#NetJoinInformation)
NetApiBufferFree_(*bufptr)
ProcedureReturn info+": "+Group
Else
error.s="NERR="+Str(Callres)
;EndIf
CloseLibrary(#NetJoinInformation)
NetApiBufferFree_(*bufptr)
ProcedureReturn error
EndIf
ProcedureReturn "loading Netapi32.dll failed"
EndIf
EndProcedure
Open_Win_join()
Repeat ; Start of the event loop
Event = WaitWindowEvent() ; This line waits until an event is received from Windows
WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
GadgetID = EventGadget() ; Is it a gadget event?
EventType = EventType() ; The event type
;You can place code here, and use the result as parameters for the procedures
If Event = #PB_Event_Gadget
If GadgetID = #SComp
ElseIf GadgetID = #SStatus
ElseIf GadgetID = #Btn_join
If GetGadgetText(#SComp) <> ""
SetGadgetText(#SStatus, NetJoinInformation(GetGadgetText(#SComp)))
EndIf
EndIf
EndIf
Until Event = #PB_Event_CloseWindow ; End of the event loop
End