alle zur zeit angemeldete benutzer
Verfasst: 13.07.2010 10:17
NetWkstaUserEnum listet informationen über alle zur zeit angemeldete benutzer and der Workstation.
lauffäig ab Win 2000
getestet auf XP/Win7/2003
lauffäig ab Win 2000
getestet auf XP/Win7/2003
Code: Alles auswählen
; ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
; coded by jpd, july 2010
; ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
; http://msdn.microsoft.com/en-us/library/aa370669(VS.85).aspx
; ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
EnableExplicit
#NERR_SUCCESS=0
#MAX_PREFERRED_LENGTH = -1
#ERROR_MORE_DATA = 234
Structure WKSTA_USER_INFO_1
wkui1_username.l
wkui1_logon_domain.l
wkui1_oth_domains.l
wkui1_logon_server.l
EndStructure
Prototype NetWkstaUserEnum(dwServer.p-unicode, level.l, bufptr.l, prefmaxlen.l, dwEntriesread.l, dwTotalentries.l, dwResumehandle.l)
Global NetWkstaUserEnum.NetWkstaUserEnum
Procedure LoadNETAPI()
Protected Result
Result = OpenLibrary(#PB_Any, "netapi32.dll")
If Result
NetWkstaUserEnum=GetFunction(Result, "NetWkstaUserEnum")
If NetWkstaUserEnum = 0
CloseLibrary(Result)
Result = 0
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Define initlib.l
Define bufptr.l
Define dwServer.l
Define dwEntriesread.l
Define dwTotalentries.l
Define dwResumehandle.l
Define nStatus.l
Define nStructSize.l
Define cnt.l
Define bServer.s
Define wui1.WKSTA_USER_INFO_1
initlib=LoadNETAPI()
If initlib
InitNetwork()
bServer = "\\" +Hostname()
nStatus=#ERROR_MORE_DATA
While nStatus = #ERROR_MORE_DATA
nStatus=0
nStatus = NetWkstaUserEnum(bServer, 1, @bufptr, #MAX_PREFERRED_LENGTH, @dwEntriesread, @dwTotalentries, @dwResumehandle)
Debug GetLastError_()
If nStatus = #NERR_SUCCESS Or nStatus = #ERROR_MORE_DATA
If dwEntriesread > 0
nStructSize = SizeOf(WKSTA_USER_INFO_1)
For cnt = 0 To dwEntriesread - 1
CopyMemory (bufptr + (nStructSize * cnt),@wui1,nStructSize); nStructSize
Debug "User Name: "+PeekS(wui1\wkui1_username,-1,#PB_Unicode)
Debug "Logon Domain: "+PeekS(wui1\wkui1_logon_domain,-1,#PB_Unicode)
Debug "Logon Server: "+PeekS(wui1\wkui1_logon_server,-1,#PB_Unicode)
Debug "Other Domain: "+PeekS(wui1\wkui1_oth_domains,-1,#PB_Unicode)
Debug "----------------------"
Next
EndIf
Else
Debug nStatus
EndIf
Wend
NetApiBufferFree_(bufptr)
CloseLibrary(initlib)
EndIf