Именно это мне и нужнотогда только скрипт на получение пользователей, сравнивание имен и времени подключения и тушить тех "одноименцев", которые подключились позже
#include <Array.au3>
#include "WinAPI.au3"
Global $sBufer, $iS = 0, $Bufer
Global Const $WTSUserName = 5;*
Global Const $WTS_CURRENT_SERVER_HANDLE = 0
Global Const $tag_SESSION_INFO = "dword SessionId;dword pWinStationName;dword WTS_CONNECTSTATE_CLASS"
Local $aResult = DllCall("Wtsapi32.dll", "int", "WTSEnumerateSessions", "HANDLE", 0, "dword", 0, "dword", 1, "ptr*", 0, "dword*", 0)
_ArrayDisplay($aResult)
For $i=1 To $aResult[5]
$tInfo = DllStructCreate($tag_SESSION_INFO, $aResult[4])
$SessionId = DllStructGetData($tInfo, "SessionId") ; Получили сесион id
$ClassId = DllStructGetData($tInfo, "WTS_CONNECTSTATE_CLASS")
MsgBox(0,0,$ClassId)
$ResultCall = DllCall("Wtsapi32.dll", "int", "WTSQuerySessionInformation", "HANDLE", 0, "dword", $SessionId, "dword", $ClassId, "dword*", 0, "dword*", 0 )
_ArrayDisplay($ResultCall)
Next
DllCall("Wtsapi32.dll", "int", "WTSFreeMemory", "ptr",$aResult[4])
$DllFunc = DllCall("Wtsapi32.dll", "Bool","WTSQuerySessionInformation","Dword",0 ,"Dword",0,"Dword",5, "str*", $Bufer, "Dword*",1024)
_ArrayDisplay($DllFunc)
#include <Array.au3>
#include "WinAPI.au3"
Global $sBufer, $iS = 0, $Bufer
Global Const $WTSUserName = 5;*
Global Const $WTS_CURRENT_SERVER_HANDLE = 0
Global Const $tag_SESSION_INFO = "dword SessionId;dword pWinStationName;dword WTS_CONNECTSTATE_CLASS"
Local $aResult = DllCall("Wtsapi32.dll", "int", "WTSEnumerateSessions", "HANDLE", 0, "dword", 0, "dword", 1, "ptr*", 0, "dword*", 0)
_ArrayDisplay($aResult)
For $i=1 To $aResult[5]
$tInfo = DllStructCreate($tag_SESSION_INFO, $aResult[4])
$SessionId = DllStructGetData($tInfo, "SessionId") ; Получили сесион id
;$ClassId = DllStructGetData($tInfo, "WTS_CONNECTSTATE_CLASS")
$ResultCall = DllCall("Wtsapi32.dll", "Bool","WTSQuerySessionInformation","Dword",0 ,"Dword",$SessionId,"Dword",5, "str*", $Bufer, "Dword*",1024)
_ArrayDisplay($ResultCall)
Next
DllCall("Wtsapi32.dll", "int", "WTSFreeMemory", "ptr",$aResult[4])
Func __EnumerateSessions()
;~ QWINSTA.exe или этой командой
Local Const $tagWTS_SESSION_INFO = 'dword SessionId;ptr WinStationName;uint State'
Local $Ret = DllCall('wtsapi32.dll', 'int', 'WTSEnumerateSessionsW', 'ptr', 0, 'dword', 0, 'dword', 1, 'ptr*', 0, 'dword*', 0)
Local $Offset = 0,$tInfo
For $i = 1 To $Ret[5]
$tInfo = DllStructCreate($tagWTS_SESSION_INFO, $Ret[4] + $Offset)
$Offset += DllStructGetSize($tInfo)
ConsoleWrite('SessionId: ' & DllStructGetData($tInfo, 'SessionId') & @CR)
ConsoleWrite('WinStationName: ' & DllStructGetData(DllStructCreate('wchar[1024]', DllStructGetData($tInfo, 'WinStationName')), 1) & @CR)
ConsoleWrite('State: ' & DllStructGetData($tInfo, 'State') & @CR)
ConsoleWrite('--------------' & @CR)
Next
DllCall('wtsapi32.dll', 'none', 'WTSFreeMemory', 'ptr', $Ret[4])
EndFunc ;==>__EnumerateSessions
SessionId: 0
WinStationName: Services
State: 4
--------------
SessionId: 1
WinStationName: Console
State: 0
--------------
Эм... Вот:думаю что сложно будет по такой инфе искать одинаковых пользователейи знать нужно не только имена. а и время подключения. иначе как выбрать - кого надо отключить?
_GAPI_GetServerSession()
Func _GAPI_GetServerSession()
Local $Offset = 0,$tInfo, $Temp, $Bufer
Local $Ret = DllCall('wtsapi32.dll', 'int', 'WTSEnumerateSessionsW', 'ptr', 0, 'dword', 0, 'dword', 1, 'ptr*', 0, 'dword*', 0)
if @error Then Return -1
Local $Return[$Ret[5]+1][5]
$Return[0][0] = $Ret[4]
For $i = 1 To $Ret[5]
$tInfo = DllStructCreate($GAPI_WTS_SESSION_INFO, $Ret[4] + $Offset)
$Bufer = ''
$Offset += DllStructGetSize($tInfo)
$Return[$i][0] = DllStructGetData($tInfo, 'SessionId')
$Return[$i][1] = DllStructGetData(DllStructCreate('wchar[1024]', DllStructGetData($tInfo, 'WinStationName')), 1)
$Return[$i][2] = DllStructGetData($tInfo, 'State')
$Dll = DllCall("Wtsapi32.dll", "Bool","WTSQuerySessionInformation","Dword",0 ,"Dword",$Return[$i][0],"Dword",5, "str*", $Bufer, "Dword*",1024)
_ArrayDisplay($Dll)
Next
DllCall('wtsapi32.dll', 'none', 'WTSFreeMemory', 'ptr', $Ret[4])
Return $Return
EndFunc
ConsoleWrite(_WinAPI_UserNameFromSessionID(1) & @LF)
Func _WinAPI_UserNameFromSessionID($iSSID)
Local $tag_LUIDS = 'DWORD LUIDLowPart; LONG LUIDHighPart'
Local $tag_SECURITY_LOGON_SESSION_DATA = _
'ULONG Size;' & _
'DWORD LogonIdLowPart; LONG LogonIdHighPart;' & _
'USHORT UserNameLength; USHORT UserNameMaximumLength; PTR UserNameBuffer;' & _
'USHORT LogonDomainLength; USHORT LogonDomainMaximumLength; PTR LogonDomainBuffer;' & _
'USHORT AuthenticationPackageLength; USHORT AuthenticationPackageMaximumLength;PTR AuthenticationPackageBuffer;' & _
'ULONG LogonType;' & _
'ULONG Session;' & _
'PTR Sid;' & _
'UINT64 LogonTime;' & _
'USHORT LogonServerLength; USHORT LogonServerNameMaximumLength; PTR LogonServerNameBuffer;' & _
'USHORT DnsDomainNameLength; USHORT DnsDomainNameNameMaximumLength;PTR DnsDomainNameNameBuffer;' & _
'USHORT UpnLength; USHORT UpnNameMaximumLength;PTR UpnNameBuffer;'
Local $Ret_Enumerate,$Ret_Get, $Error = 1, $iSession, $sUserName
Do
$Ret_Enumerate = DllCall("Secur32.dll", "int", 'LsaEnumerateLogonSessions', "ptr*", 0, 'ptr*', 0)
If (@error) Or ($Ret_Enumerate[0]) Or (Not $Ret_Enumerate[1]) Or (Not $Ret_Enumerate[2]) Then
ExitLoop
EndIf
Local $Offset = 0
For $i = 0 To $Ret_Enumerate[1]
Local $tInfo = DllStructCreate($tag_LUIDS, $Ret_Enumerate[2] + $Offset)
$Offset += DllStructGetSize($tInfo)
$Ret_Get = DllCall("Secur32.dll", "dword", 'LsaGetLogonSessionData', "ptr", DllStructGetPtr($tInfo), 'ptr*', 0)
If (@error) Or ($Ret_Get[0]) Or (Not $Ret_Get[1]) Or (Not $Ret_Get[2]) Then
ExitLoop 1
EndIf
$iSession = DllStructGetData(DllStructCreate($tag_SECURITY_LOGON_SESSION_DATA, $Ret_Get[2]), 'Session')
If $iSession = $iSSID Then
Local $UserNameLength = DllStructGetData(DllStructCreate($tag_SECURITY_LOGON_SESSION_DATA, $Ret_Get[2]), 'UserNameLength')
Local $UserNameBuffer = DllStructGetData(DllStructCreate($tag_SECURITY_LOGON_SESSION_DATA, $Ret_Get[2]), 'UserNameBuffer')
$sUserName = DllStructGetData(DllStructCreate("wchar [" & $UserNameLength & "]", $UserNameBuffer), 1)
$Error = 0
ExitLoop 1 ;При успехе
EndIf
Next
DllCall("Secur32.dll", "int", 'LsaFreeReturnBuffer', 'ptr', $Ret_Enumerate[2])
Until 1
If $Error Then
Return SetError(1, 0, "")
EndIf
Return SetError(0, 0, $sUserName)
EndFunc ;==>_WinAPI_UserNameFromSessionID
#include <WinApi.au3>
;~ _WinAPI_GetCurrentProcess()
$PID=_WinAPI_GetCurrentProcessID()
ConsoleWrite($PID & @LF)
$ret = DllCall("kernel32.dll", "int", "ProcessIdToSessionId", "dword", $PID, "dword*", 0)
If Not @error And $ret[0] Then
ConsoleWrite("Процесс запущен в сессии: "&$ret[2] & @LF)
ConsoleWrite("PID: "&$ret[1] & @LF)
ConsoleWrite("Процесс запущен в сессии: "&$ret[0] & @LF)
EndIf
Func _GAPI_KillServerSessionId($SSID)
;BOOL WTSDisconnectSession(
; _In_ HANDLE hServer,
; _In_ DWORD SessionId,
; _In_ BOOL bWait
;);
DllCall('wtsapi32.dll', 'bool', 'WTSLogoffSession', 'handle', 0, 'dword', $SSID, 'bool', 0)
EndFunc
Func _GAPI_GetServerSession()
Local $Offset = 0,$tInfo, $Temp, $Bufer, $DLL
Local $Ret = DllCall('wtsapi32.dll', 'int', 'WTSEnumerateSessionsW', 'ptr', 0, 'dword', 0, 'dword', 1, 'ptr*', 0, 'dword*', 0)
if @error Then Return -1
Local $Return[$Ret[5]+1][5]
$Return[0][0] = $Ret[5]
For $i = 1 To $Ret[5]
$tInfo = DllStructCreate($GAPI_WTS_SESSION_INFO, $Ret[4] + $Offset)
$Bufer = ''
$Offset += DllStructGetSize($tInfo)
$Return[$i][0] = DllStructGetData($tInfo, 'SessionId')
$Return[$i][1] = DllStructGetData(DllStructCreate('wchar[1024]', DllStructGetData($tInfo, 'WinStationName')), 1)
$Return[$i][2] = DllStructGetData($tInfo, 'State')
$Dll = DllCall("Wtsapi32.dll", "Bool","WTSQuerySessionInformation","Dword",0 ,"Dword",$Return[$i][0],"Dword",5, "str*", $Bufer, "Dword*",1024)
$Return[$i][3] = $Dll[4]
Next
DllCall('wtsapi32.dll', 'none', 'WTSFreeMemory', 'ptr', $Ret[4])
Return $Return
EndFunc
Func _GAPI_GetServerSessionId()
Local $ret = DllCall("kernel32.dll", "int", "ProcessIdToSessionId", "dword", _WinAPI_GetCurrentProcessID(), "dword*", 0)
If Not @error And $ret[0] Then Return $ret[2]
Return -1
EndFunc
Global $Name = @UserName, $SID = _GAPI_GetServerSessionId()
_GAPI_CreateThread('_Thread_KillSessuonId',200)
Func _Thread_KillSessuonId()
$Ret = _GAPI_GetServerSession()
If IsArray($Ret) Then
For $i=1 To $Ret[0][0]
if $Ret[$i][3] == $Name And $Ret[$i][0] <> $SID Then
_GAPI_KillServerSessionId($Ret[$i][0])
EndIf
Next
EndIf
EndFunc
то есть скрипт следит только за одним именем? а как же с другими ?И еще, я заметил что меня тоже иногда киляет