Jump to content

Online PC list


Tec
 Share

Recommended Posts

I use a Script to get the online PCs from Domain with Username. After a few hours when i close the Process the Window ist closed but the Process is running. Dont now why.

#include <Array.au3>
Opt("MustDeclareVars", 1)

Local $gui, $begin, $msg, $lv
Dim $list[1]

$gui = GUICreate("Online Users",220,250, 100,200,-1,$WS_EX_ACCEPTFILES)
$lv = GUICtrlCreateListView ("Username | Computer",10,10,200,230);,$LVS_SORTDESCENDING)
GUISetState()
_getPCUser()
_checkOnline($list)

$begin = TimerInit()

While 1
    If TimerDiff($begin) > 300000 Then
        _checkOnline($list)
        $begin = TimerInit()
    EndIf
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    Sleep (50)
WEnd    


Func _getPCUser()
    Local $objCommand = ObjCreate("ADODB.Command")
    Local $objConnection = ObjCreate("ADODB.Connection")
    
    $objConnection.Provider = "ADsDSOObject"
    $objConnection.Open ("Active Directory Provider")
    $objCommand.ActiveConnection = $objConnection

    Local $strBase = "<GC://dc=[b]DOMAIN[/b],dc=[b]LOCAL[/b]>"
    Local $strFilter = "(&(objectCategory=computer)(name=PC*))"
    Local $strAttributes = "cn,operatingSystem,operatingSystemVersion,operatingSystemServicePack"
    Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree"


    $objCommand.CommandText = $strQuery
    $objCommand.Properties ("Page Size") = 10
    $objCommand.Properties ("Timeout") = 30
    $objCommand.Properties ("Cache Results") = False
    Local $ADS_SCOPE_SUBTREE = 2
    $objCommand.Properties ("searchscope") = $ADS_SCOPE_SUBTREE

    Local $objRecordSet = $objCommand.Execute

    While Not $objRecordSet.EOF
        If $list[Ubound($list)-1] <> '' Then
            ReDim $list[Ubound($list)+1]
        EndIf

        $list[Ubound($list)-1] = $objRecordSet.Fields ("cn").Value 

        $objRecordSet.MoveNext
    WEnd
    
    $objConnection.Close
    $objConnection = ""
    $objCommand = ""
    $objRecordSet = ""  
    
EndFunc 


Func _checkOnline($list)
    Dim $listonline[1][2]   
    For $i = 1 to Ubound ($list) - 1
        Local $aUser
        Local $strUser
        Dim $objWMIService, $objClass       
        if Ping($list[$i], 20) Then
            If $listonline[Ubound($listonline)-1][0] <> '' Then
                ReDim $listonline[Ubound($listonline)+1][2]
            EndIf           
            $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $list[$i] & "\root\cimv2")
            If IsObj($objWMIService) Then
            $objClass = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
            For $obj in $objClass
                $strUser = $obj.UserName
                if $strUser Then 
                    $aUser = StringSplit($strUser, '\')
                    $strUser = $aUser[2]
                EndIf
            Next
            EndIf

            $listonline[Ubound($listonline)-1][0] = $list[$i]
            $listonline[Ubound($listonline)-1][1] = $strUser            
        EndIf
    Next
    _ArraySort($listonline, 0,0,0,2,1)
    _clearlistview($lv)
    WinSetTitle ($gui, "", UBound($listonline) & " PCs Online")
    For $a = 0 To UBound($listonline) - 1
        GUICtrlCreateListViewItem($listonline[$a][1] & "|" & $listonline[$a][0], $lv)
    Next
    $listonline = 0
EndFunc


Func _clearlistview($List_View)
   Local $LVM_DELETEALLITEMS = 0x1009
   GUICtrlSendMsg($LIST_VIEW, $LVM_DELETEALLITEMS, 0, 0)
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...