Wie viele Benutzer angemeldet

Windowsspezifisches Forum , API ,..
Beiträge, die plattformübergreifend sind, gehören ins 'Allgemein'-Forum.
Benutzeravatar
purebas
Beiträge: 127
Registriert: 11.03.2008 23:59
Wohnort: München

Wie viele Benutzer angemeldet

Beitrag von purebas »

Mit welcher API kann ich herausbekommen, wie viele Benutzer am System angemeldet sind?
Die genaue Anzahl brauche "ich" nicht zu wissen. Mich interessiert nur, ob überhaupt ein
weiterer Benutzer angemeldet ist.
Benutzeravatar
NicTheQuick
Ein Admin
Beiträge: 8807
Registriert: 29.08.2004 20:20
Computerausstattung: Ryzen 7 5800X, 64 GB DDR4-3200
Ubuntu 24.04.2 LTS
GeForce RTX 3080 Ti
Wohnort: Saarbrücken

Re: Wie viele Benutzer angemeldet

Beitrag von NicTheQuick »

Hilft dir das weiter? Oder wolltest du eine explizite API?
Useful commands for Windows administrators - Who is logged on to a computer?
Benutzeravatar
purebas
Beiträge: 127
Registriert: 11.03.2008 23:59
Wohnort: München

Re: Wie viele Benutzer angemeldet

Beitrag von purebas »

Das ist eine sehr schöne Zusammenfassung der cmd-Befehle.
Ich brauche aber eine API, die mir die Anzahl der angemeldeten Benutzer zurück gibt.

Ich habe mittlerweile wahrscheinlich eine zutreffende Funktion unter
http://msdn.microsoft.com/en-us/library/aa383833.aspx entdeckt.
Aber wie bekomme ich das in PB "übersetzt"? Damit habe ich nach wie vor die meisten Probleme.
Benutzeravatar
Shardik
Beiträge: 746
Registriert: 25.01.2005 12:19

Re: Wie viele Benutzer angemeldet

Beitrag von Shardik »

purebas hat geschrieben:Mit welcher API kann ich herausbekommen, wie viele Benutzer am System angemeldet sind?
NetWkstaUserEnum

jpd hat dazu ein Code-Beispiel für Windows erstellt (und im späteren Verlauf des Threads auch, wie man das in Linux mit der API-Funktion getutent_() realisiert):
http://www.purebasic.fr/german/viewtopi ... =8&t=22831
Benutzeravatar
purebas
Beiträge: 127
Registriert: 11.03.2008 23:59
Wohnort: München

Re: Wie viele Benutzer angemeldet

Beitrag von purebas »

NetWkstaUserEnum gibt die Anzahl der angelegten Benutzerkonten zurück.
Ich benötige aber die Anzahl der zur Laufzeit eingeloggten Benutzer.

Stichwort: Schnelle Benutzerumschaltung

Unter XP habe ich die schnelle Benutzerumschaltung verteufelt, da die
meisten Programme nicht wirklich richtig angepasst waren. Ab Vista
hat sich dies aber deutlich verbessert. Wobei dies nicht unbedingt dem
System zugrundeliegt, sondern, die Softwareentwicklung die schnelle
Benutzerumschaltung mittlerweile gut berücksichtigt.

Privat nutze ich diese Umschaltung auch sehr intensiv, da ich mich nicht ständig
abmelden will, meine Programme starten will und meine Tochter und mein Sohn
wollen dies auch nicht. Der Rechner läuft einfach und am Abend geht es in den
Ruhemodus.
Benutzeravatar
RSBasic
Admin
Beiträge: 8047
Registriert: 05.10.2006 18:55
Wohnort: Gernsbach
Kontaktdaten:

Re: Wie viele Benutzer angemeldet

Beitrag von RSBasic »

Alternativ kannst du es über WMI ermitteln: http://stackoverflow.com/questions/8987 ... d-in-users
Es ist zwar VB/VBS, aber mit PB mit einer Include/Library kannst du WMI auch ansprechen. Ich habs aber nicht getestet.
Aus privaten Gründen habe ich leider nicht mehr so viel Zeit wie früher. Bitte habt Verständnis dafür.
Bild
Bild
Benutzeravatar
jpd
Beiträge: 380
Registriert: 14.02.2005 10:33

Re: Wie viele Benutzer angemeldet

Beitrag von jpd »

Hi erstmal grüße an Alle,

die WTSEnumerateSessionsEX ist die lösung (möglicherweise), hier ein beispiel (wurde nur auf Win 7 getestet).

Code: Alles auswählen

;jpd April 2013

Structure WTS_SESSION_INFO_1
  ExecEnvId.l;
  State.l
  SessionId.l
  pSessionName.s
  pHostName.s
  pUserName.s
  pDomainName.s
  pFarmName.s
EndStructure
;

Enumeration ;WTS_TYPE_CLASS
  #WTSTypeProcessInfoLevel0
  #WTSTypeProcessInfoLevel1
  #WTSTypeSessionInfoLevel1
EndEnumeration


Prototype  WTSEnumerateSessionsEx(hServer, *pLevel, Filter, *ppSessionInfo.WTS_SESSION_INFO_1, *pCount)
Prototype  WTSFreeMemoryEx(WTSTypeClass, pMemory, NumberOfEntries);.WTS_TYPE_CLASS
Prototype  WTSOpenServer(pServerName)
Prototype  WTSCloseServer(hServer)

Global WTSEnumerateSessionsEx.WTSEnumerateSessionsEx
Global WTSFreeMemoryEx.WTSFreeMemoryEx
Global WTSOpenServer.WTSOpenServer
Global WTSCloseServer.WTSCloseServer


Macro lpComputerName(Computername)
  
  Protected lpComputername,lpNullComputername
  
  If ComputerName = "." 
    lpNullComputername = 0
    lpComputername=@lpNullComputername
  Else
    lpComputername=@Computername
  EndIf
  
EndMacro

Procedure.i wtsapi32_LoadDLL()
  Protected.i hDLL
  
  hDLL = OpenLibrary(#PB_Any, "wtsapi32.dll")
  If hDLL <> 0
    
    WTSCloseServer = GetFunction(hDLL, "WTSCloseServer")
    
    
    
    CompilerIf #PB_Compiler_Unicode
      
      WTSEnumerateSessionsEx = GetFunction(hDLL, "WTSEnumerateSessionsExW")
      WTSFreeMemoryEx = GetFunction(hDLL, "WTSFreeMemoryExW")
      WTSOpenServer = GetFunction(hDLL, "WTSOpenServerW")
      
    CompilerElse
      
      WTSEnumerateSessionsEx = GetFunction(hDLL, "WTSEnumerateSessionsExA")
      WTSFreeMemoryEx = GetFunction(hDLL, "WTSFreeMemoryExA")
      WTSOpenServer = GetFunction(hDLL, "WTSOpenServerA")
      
    CompilerEndIf
    
    ProcedureReturn hDLL
  EndIf
  
  ProcedureReturn #False
EndProcedure


Procedure GetWTSSessions(List ppSessionInfo.WTS_SESSION_INFO_1(), ComputerName.s = ".")
  
  
  Protected WTSHandle.i
  Protected pLevel=1
  Protected Filter=0
  Protected *SessionInfo
  Protected pCount
  lpComputerName(Computername)
  
  WTSHandle=WTSOpenServer(lpComputerName)
  
  If WTSHandle
    
    Ret=WTSEnumerateSessionsEx(WTSHandle, @pLevel, Filter,@*SessionInfo,@pCount)
    
    Debug GetLastError_()
    
    If Ret <> 0
      For i = 0 To pCount - 1
        AddElement(ppSessionInfo())
        CopyMemory (*SessionInfo+SizeOf(WTS_SESSION_INFO_1)*i, ppSessionInfo(),SizeOf(WTS_SESSION_INFO_1)*SizeOf(Character))
      Next
      WTSFreeMemoryEx(#WTSTypeSessionInfoLevel1, *SessionInfo, pCount-1)
    EndIf
    
    WTSCloseServer(WTSHandle)
  EndIf
  
  
EndProcedure

Define.i hDLL
Define NewList ppSessionInfo.WTS_SESSION_INFO_1()

hDLL=wtsapi32_LoadDLL()

If hDLL=0
  End
EndIf


GetWTSSessions(ppSessionInfo.WTS_SESSION_INFO_1())
CloseLibrary(hDll)


ForEach ppSessionInfo()
  Debug "Session ID: "+ ppSessionInfo()\SessionId
  Debug "Session Name: "+ppSessionInfo()\pSessionName
  Debug "UserName: "+ ppSessionInfo()\pUserName
Next
Ciao
jpd
PB 5.10 Windows 7 x64
Benutzeravatar
purebas
Beiträge: 127
Registriert: 11.03.2008 23:59
Wohnort: München

Re: Wie viele Benutzer angemeldet

Beitrag von purebas »

Ja, genau das ist es was ich brauche!

Jetzt muss ich bloß noch herausfinden, welche State's ich als Benutzer zählen kann und was zum System gehört. Habe gesehen, dass SessionId "0" immer "Services" ist. Dies ist natürlich kein Benutzer und kann wahrscheinlich beim zählen ausgelassen werden. Ansonsten zähle ich wahrscheinlich alle Einträge mit State 0 (aktiv) und State 4 (angemeldet aber eben nicht aktiv) zusammen. Aber das bekomme ich schon noch genau durch testen heraus.

Danke vielmals!
Benutzeravatar
jpd
Beiträge: 380
Registriert: 14.02.2005 10:33

Re: Wie viele Benutzer angemeldet

Beitrag von jpd »

Hi Purebas,

habe das angepasst so das auch auf XP arbeitet...


Code: Alles auswählen

;jpd April 2013


Structure WTS_SESSION_INFO
  SessionId.l
  pWinStationName.s
  State.l;.WTS_CONNECTSTATE_CLASS
EndStructure

Structure WTS_SESSION_INFO_1
  ExecEnvId.l;
  State.l
  SessionId.l
  pSessionName.s
  pHostName.s
  pUserName.s
  pDomainName.s
  pFarmName.s
EndStructure
;



Enumeration ;WTS_CONNECTSTATE_CLASS 
  #WTSActive
  #WTSConnected;
  #WTSConnectQuery;
  #WTSShadow;
  #WTSDisconnected;
  #WTSIdle;
  #WTSListen;
  #WTSReset;
  #WTSDown;
  #WTSInit;
EndEnumeration


Enumeration ;WTS_TYPE_CLASS
  #WTSTypeProcessInfoLevel0
  #WTSTypeProcessInfoLevel1
  #WTSTypeSessionInfoLevel1
EndEnumeration


Prototype  WTSEnumerateSessionsEx(hServer, *pLevel, Filter, *ppSessionInfo.WTS_SESSION_INFO_1, *pCount)
Prototype  WTSEnumerateSessions(hServer, Reserved, Version, *ppSessionInfo.WTS_SESSION_INFO, *pCount)
Prototype  WTSFreeMemoryEx(WTSTypeClass, pMemory, NumberOfEntries);.WTS_TYPE_CLASS
Prototype  WTSFreeMemory(pMemory)
Prototype  WTSOpenServer(pServerName)
Prototype  WTSCloseServer(hServer)

Global WTSEnumerateSessionsEx.WTSEnumerateSessionsEx
Global WTSEnumerateSessions.WTSEnumerateSessions
Global WTSFreeMemoryEx.WTSFreeMemoryEx
Global WTSFreeMemory.WTSFreeMemory
Global WTSOpenServer.WTSOpenServer
Global WTSCloseServer.WTSCloseServer


Macro lpComputerName(Computername)
 
  Protected lpComputername,lpNullComputername
 
  If ComputerName = "."
    lpNullComputername = 0
    lpComputername=@lpNullComputername
  Else
    lpComputername=@Computername
  EndIf
 
EndMacro

Procedure.i wtsapi32_LoadDLL()
  Protected.i hDLL
 
  hDLL = OpenLibrary(#PB_Any, "wtsapi32.dll")
  If hDLL <> 0
   
    WTSCloseServer = GetFunction(hDLL, "WTSCloseServer")
    WTSFreeMemory = GetFunction(hDLL, "WTSFreeMemory")
   
   
    CompilerIf #PB_Compiler_Unicode
     
      WTSEnumerateSessionsEx = GetFunction(hDLL, "WTSEnumerateSessionsExW")
      WTSEnumerateSessions = GetFunction(hDLL, "WTSEnumerateSessionsW")
      WTSFreeMemoryEx = GetFunction(hDLL, "WTSFreeMemoryExW")
      WTSOpenServer = GetFunction(hDLL, "WTSOpenServerW")
     
    CompilerElse
     
      WTSEnumerateSessionsEx = GetFunction(hDLL, "WTSEnumerateSessionsExA")
      WTSEnumerateSessions = GetFunction(hDLL, "WTSEnumerateSessionsA")
      WTSFreeMemoryEx = GetFunction(hDLL, "WTSFreeMemoryExA")
      WTSOpenServer = GetFunction(hDLL, "WTSOpenServerA")
     
    CompilerEndIf
   
    ProcedureReturn hDLL
  EndIf
 
  ProcedureReturn #False
EndProcedure


Procedure GetWTSSessions(List ppSessionInfo.WTS_SESSION_INFO_1(), ComputerName.s = ".")
 
 
  Protected WTSHandle.i
  Protected pLevel=1
  Protected Filter=0
  Protected *SessionInfo
  Protected pCount
  lpComputerName(Computername)
 
  WTSHandle=WTSOpenServer(lpComputerName)
 
  If WTSHandle
   
    Ret=WTSEnumerateSessionsEx(WTSHandle, @pLevel, Filter,@*SessionInfo,@pCount)
   
    Debug GetLastError_()
   
    If Ret <> 0
      For i = 0 To pCount - 1
        AddElement(ppSessionInfo())
        CopyMemory (*SessionInfo+SizeOf(WTS_SESSION_INFO_1)*i, ppSessionInfo(),SizeOf(WTS_SESSION_INFO_1)*SizeOf(Character))
      Next
      WTSFreeMemoryEx(#WTSTypeSessionInfoLevel1, *SessionInfo, pCount-1)
    EndIf
   
    WTSCloseServer(WTSHandle)
  EndIf
 
 
EndProcedure

Procedure.s WTS_CONNECTSTATE_CLASS(ValState.l) 
  
  Select ValState
      
    Case  #WTSActive
      ProcedureReturn "A user is logged on To the WinStation."
    Case #WTSConnected
      ProcedureReturn "The WinStation is connected To the client."
    Case #WTSConnectQuery
      ProcedureReturn "The WinStation is in the process of connecting To the client."
    Case #WTSShadow
      ProcedureReturn "The WinStation is shadowing another WinStation."
    Case #WTSDisconnected
      ProcedureReturn "The WinStation is active but the client is disconnected."
    Case #WTSIdle 
      ProcedureReturn "The WinStation is waiting For a client To connect."
    Case #WTSListen
      ProcedureReturn "The WinStation is listening For a connection. A listener session waits For requests For new client connections. No user is logged on a listener session. A listener session cannot be reset, shadowed, Or changed To a regular client session."
    Case #WTSReset
      ProcedureReturn "The WinStation is being reset."
    Case #WTSDown
      ProcedureReturn "The WinStation is down due To an error."
    Case #WTSInit
      ProcedureReturn "The WinStation is initializing."
      
  EndSelect
  
EndProcedure



Procedure IsUserLoggedOn(List ppSessionInfo.WTS_SESSION_INFO(), ComputerName.s = ".")
  
  
  Protected WTSHandle.i
  Protected Version=1
  Protected Filter=0
  Protected *SessionInfo
  Protected pCount
  
  If OSVersion() > #PB_OS_Windows_Vista
  lpComputerName(Computername)
  
  WTSHandle=WTSOpenServer(lpComputerName)
Else
  
  WTSHandle=WTSOpenServer(0)
EndIf

  If WTSHandle
    
    Ret=WTSEnumerateSessions(WTSHandle, #Null, Version,@*SessionInfo,@pCount)
    
    Debug GetLastError_()
    
    If Ret <> 0
      For i = 0 To pCount - 1
        AddElement(ppSessionInfo())
        CopyMemory (*SessionInfo+SizeOf(WTS_SESSION_INFO)*i, ppSessionInfo(),SizeOf(WTS_SESSION_INFO)*SizeOf(Character))
      Next
      WTSFreeMemory(*SessionInfo)
    EndIf
    
    WTSCloseServer(WTSHandle)
  EndIf
  
  
EndProcedure


Define.i hDLL
Define NewList ppSessionInfoEx.WTS_SESSION_INFO_1()
Define NewList ppSessionInfo.WTS_SESSION_INFO()

hDLL=wtsapi32_LoadDLL()

If hDLL=0
  End
EndIf

If OSVersion() > #PB_OS_Windows_Vista
GetWTSSessions(ppSessionInfoEx.WTS_SESSION_INFO_1())

EndIf 
IsUserLoggedOn(ppSessionInfo.WTS_SESSION_INFO())
CloseLibrary(hDll)

Debug "---WTSEnumerateSessionsEx---"

ForEach ppSessionInfoEx()
  If ppSessionInfoEx()\State = #WTSActive
  Debug "Session ID: "+ ppSessionInfoEx()\SessionId
  Debug "Session Name: "+ppSessionInfoEx()\pSessionName
  Debug "UserName: "+ ppSessionInfoEx()\pUserName
  Debug "Connect Status: "+ WTS_CONNECTSTATE_CLASS(ppSessionInfoEx()\State)
EndIf

Next

Debug "---WTSEnumerateSessions---"
ForEach ppSessionInfo()
 If ppSessionInfo()\State = #WTSActive
  Debug "WinStationName: "+ ppSessionInfo()\pWinStationName
  Debug "Session ID: "+ppSessionInfo()\SessionId
  Debug "Connect Status: "+ WTS_CONNECTSTATE_CLASS(ppSessionInfo()\State)
  EndIf
Next

PB 5.10 Windows 7 x64
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Re: Wie viele Benutzer angemeldet

Beitrag von ts-soft »

:allright:
Ich hab es auch noch ein bissel angepasst, jetzt klappts auch mit 64-Bit und EnableExplicit.

Code: Alles auswählen

 ;jpd April 2013

Structure WTS_SESSION_INFO Align #PB_Structure_AlignC 
  SessionId.l
  pWinStationName.s
  State.l;.WTS_CONNECTSTATE_CLASS
EndStructure

Structure WTS_SESSION_INFO_1 Align #PB_Structure_AlignC 
  ExecEnvId.l
  State.l
  SessionId.l
  pSessionName.s
  pHostName.s
  pUserName.s
  pDomainName.s
  pFarmName.s
EndStructure
;



Enumeration ;WTS_CONNECTSTATE_CLASS
  #WTSActive
  #WTSConnected;
  #WTSConnectQuery;
  #WTSShadow;
  #WTSDisconnected;
  #WTSIdle;
  #WTSListen;
  #WTSReset;
  #WTSDown;
  #WTSInit;
EndEnumeration


Enumeration ;WTS_TYPE_CLASS
  #WTSTypeProcessInfoLevel0
  #WTSTypeProcessInfoLevel1
  #WTSTypeSessionInfoLevel1
EndEnumeration


Prototype  WTSEnumerateSessionsEx(hServer, *pLevel, Filter, *ppSessionInfo.WTS_SESSION_INFO_1, *pCount)
Prototype  WTSEnumerateSessions(hServer, Reserved, Version, *ppSessionInfo.WTS_SESSION_INFO, *pCount)
Prototype  WTSFreeMemoryEx(WTSTypeClass, pMemory, NumberOfEntries);.WTS_TYPE_CLASS
Prototype  WTSFreeMemory(pMemory)
Prototype  WTSOpenServer(pServerName)
Prototype  WTSCloseServer(hServer)

Global WTSEnumerateSessionsEx.WTSEnumerateSessionsEx
Global WTSEnumerateSessions.WTSEnumerateSessions
Global WTSFreeMemoryEx.WTSFreeMemoryEx
Global WTSFreeMemory.WTSFreeMemory
Global WTSOpenServer.WTSOpenServer
Global WTSCloseServer.WTSCloseServer


Macro lpComputerName(Computername)
 
  Protected lpComputername,lpNullComputername
 
  If ComputerName = "."
    lpNullComputername = 0
    lpComputername=@lpNullComputername
  Else
    lpComputername=@Computername
  EndIf
 
EndMacro

Procedure.i wtsapi32_LoadDLL()
  Protected.i hDLL
 
  hDLL = OpenLibrary(#PB_Any, "wtsapi32.dll")
  If hDLL <> 0
   
    WTSCloseServer = GetFunction(hDLL, "WTSCloseServer")
    WTSFreeMemory = GetFunction(hDLL, "WTSFreeMemory")
   
   
    CompilerIf #PB_Compiler_Unicode
     
      WTSEnumerateSessionsEx = GetFunction(hDLL, "WTSEnumerateSessionsExW")
      WTSEnumerateSessions = GetFunction(hDLL, "WTSEnumerateSessionsW")
      WTSFreeMemoryEx = GetFunction(hDLL, "WTSFreeMemoryExW")
      WTSOpenServer = GetFunction(hDLL, "WTSOpenServerW")
     
    CompilerElse
     
      WTSEnumerateSessionsEx = GetFunction(hDLL, "WTSEnumerateSessionsExA")
      WTSEnumerateSessions = GetFunction(hDLL, "WTSEnumerateSessionsA")
      WTSFreeMemoryEx = GetFunction(hDLL, "WTSFreeMemoryExA")
      WTSOpenServer = GetFunction(hDLL, "WTSOpenServerA")
     
    CompilerEndIf
   
    ProcedureReturn hDLL
  EndIf
 
  ProcedureReturn #False
EndProcedure


Procedure GetWTSSessions(List ppSessionInfo.WTS_SESSION_INFO_1(), ComputerName.s = ".")
 
 
  Protected WTSHandle.i
  Protected pLevel=1
  Protected Filter=0
  Protected *SessionInfo
  Protected pCount
  Protected Ret, i
  
  lpComputerName(Computername)
 
  WTSHandle=WTSOpenServer(lpComputerName)
 
  If WTSHandle
   
    Ret=WTSEnumerateSessionsEx(WTSHandle, @pLevel, Filter,@*SessionInfo,@pCount)
   
    Debug GetLastError_()
   
    If Ret <> 0
      For i = 0 To pCount - 1
        AddElement(ppSessionInfo())
        CopyMemory (*SessionInfo+SizeOf(WTS_SESSION_INFO_1)*i, ppSessionInfo(),SizeOf(WTS_SESSION_INFO_1)*SizeOf(Character))
      Next
      WTSFreeMemoryEx(#WTSTypeSessionInfoLevel1, *SessionInfo, pCount-1)
    EndIf
   
    WTSCloseServer(WTSHandle)
  EndIf
 
 
EndProcedure

Procedure.s WTS_CONNECTSTATE_CLASS(ValState.l)
 
  Select ValState
     
    Case  #WTSActive
      ProcedureReturn "A user is logged on To the WinStation."
    Case #WTSConnected
      ProcedureReturn "The WinStation is connected To the client."
    Case #WTSConnectQuery
      ProcedureReturn "The WinStation is in the process of connecting To the client."
    Case #WTSShadow
      ProcedureReturn "The WinStation is shadowing another WinStation."
    Case #WTSDisconnected
      ProcedureReturn "The WinStation is active but the client is disconnected."
    Case #WTSIdle
      ProcedureReturn "The WinStation is waiting For a client To connect."
    Case #WTSListen
      ProcedureReturn "The WinStation is listening For a connection. A listener session waits For requests For new client connections. No user is logged on a listener session. A listener session cannot be reset, shadowed, Or changed To a regular client session."
    Case #WTSReset
      ProcedureReturn "The WinStation is being reset."
    Case #WTSDown
      ProcedureReturn "The WinStation is down due To an error."
    Case #WTSInit
      ProcedureReturn "The WinStation is initializing."
     
  EndSelect
 
EndProcedure



Procedure IsUserLoggedOn(List ppSessionInfo.WTS_SESSION_INFO(), ComputerName.s = ".")
 
 
  Protected WTSHandle.i
  Protected Version=1
  Protected Filter=0
  Protected *SessionInfo
  Protected pCount
  Protected Ret, i
  
  If OSVersion() > #PB_OS_Windows_Vista
  lpComputerName(Computername)
 
  WTSHandle=WTSOpenServer(lpComputerName)
Else
 
  WTSHandle=WTSOpenServer(0)
EndIf

  If WTSHandle
   
    Ret=WTSEnumerateSessions(WTSHandle, #Null, Version,@*SessionInfo,@pCount)
   
    Debug GetLastError_()
   
    If Ret <> 0
      For i = 0 To pCount - 1
        AddElement(ppSessionInfo())
        CopyMemory (*SessionInfo+SizeOf(WTS_SESSION_INFO)*i, ppSessionInfo(),SizeOf(WTS_SESSION_INFO)*SizeOf(Character))
      Next
      WTSFreeMemory(*SessionInfo)
    EndIf
   
    WTSCloseServer(WTSHandle)
  EndIf
 
 
EndProcedure


Define.i hDLL
Define NewList ppSessionInfoEx.WTS_SESSION_INFO_1()
Define NewList ppSessionInfo.WTS_SESSION_INFO()

hDLL=wtsapi32_LoadDLL()

If hDLL=0
  End
EndIf

If OSVersion() > #PB_OS_Windows_Vista
GetWTSSessions(ppSessionInfoEx.WTS_SESSION_INFO_1())

EndIf
IsUserLoggedOn(ppSessionInfo.WTS_SESSION_INFO())
CloseLibrary(hDll)

Debug "---WTSEnumerateSessionsEx---"

ForEach ppSessionInfoEx()
  If ppSessionInfoEx()\State = #WTSActive
  Debug "Session ID: "+ ppSessionInfoEx()\SessionId
  Debug "Session Name: "+ppSessionInfoEx()\pSessionName
  Debug "UserName: "+ ppSessionInfoEx()\pUserName
  Debug "Connect Status: "+ WTS_CONNECTSTATE_CLASS(ppSessionInfoEx()\State)
EndIf

Next

Debug "---WTSEnumerateSessions---"
ForEach ppSessionInfo()
 If ppSessionInfo()\State = #WTSActive
  Debug "WinStationName: "+ ppSessionInfo()\pWinStationName
  Debug "Session ID: "+ppSessionInfo()\SessionId
  Debug "Connect Status: "+ WTS_CONNECTSTATE_CLASS(ppSessionInfo()\State)
  EndIf
Next

PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
Antworten