Jump to content

Array of Computers on the network?


 Share

Recommended Posts

I've looked around, and found only one script that claimed to do this, but failed.

I've tried "net view" but it autoit won't seem to capture the output. I'm not sure why. Anybody have an idea how to do this?

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Local $foo = Run(@ComSpec & " /c net view", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Dim $sLine
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 464, 414, 193, 125)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 463, 413)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    While @error <> -1
        If StdoutRead($foo) = "" or StdoutRead($foo) = "1" Then
;~      ;
        Else
            GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & $sLine & StdoutRead($foo))
        EndIf
        Sleep(500)
    Wend
    StdioClose($foo)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
;~          Exit
    EndSwitch
WEnd

It seems to work with lines 15, 17, and 19 commented out. But then there is a bunch of extra lines...Why doesn't it work like that?

Edited by Firestorm

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

I've looked around, and found only one script that claimed to do this, but failed.

I've tried "net view" but it autoit won't seem to capture the output. I'm not sure why. Anybody have an idea how to do this?

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Local $foo = Run(@ComSpec & " /c net view", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Dim $sLine
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 464, 414, 193, 125)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 463, 413)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    While @error <> -1
        If StdoutRead($foo) = "" or StdoutRead($foo) = "1" Then
;~  ;
        Else
            GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & $sLine & StdoutRead($foo))
        EndIf
        Sleep(500)
    Wend
    StdioClose($foo)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
;~          Exit
    EndSwitch
WEnd

It seems to work with lines 15, 17, and 19 commented out. But then there is a bunch of extra lines...Why doesn't it work like that?

Hi,

this code works. You may have to code some parts in another way:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Local $foo = Run(@ComSpec & " /c net view", @SystemDir, @SW_Hide , $STDERR_CHILD + $STDOUT_CHILD)
Dim $sLine
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 464, 414, 193, 125)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 463, 413)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    While 1
        $sline = StdoutRead($foo)
        If @error Then ExitLoop
        If $sline = "" Then ContinueLoop
        GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & $sLine)
    Wend
    StdioClose($foo)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
             Exit
    EndSwitch
WEnd

;-))

Stefan

Link to comment
Share on other sites

Or, you mentioned array:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 464, 414, 193, 125)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 463, 413)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Local $cmd = Run(@ComSpec & " /c net view", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD);

Local $output = "";
While 1
    $output = $output & StdoutRead( $cmd );
    If (@error) Then ExitLoop
WEnd
    
$strLines = StringSplit( $output, @CRLF );

For $i = 1 To $strLines[0]
    Local $strLine = StringStripWS( $strLines[$i], 2 );
    If (@error) Then 
        ExitLoop
    ElseIf $strLine = "" Then 
        ContinueLoop
    ElseIf ( StringLeft( $strLine, 2 ) = "\\" ) Then
        GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & $strLine & @CRLF );
    EndIf
Next
StdioClose( $cmd )

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
             Exit
    EndSwitch
WEnd

Only grabs the computer names, and in an array (amongst other stuff, but it's an example :P).

Link to comment
Share on other sites

Example from Amel27

#include <Array.au3>

Global Const $SV_TYPE_WORKSTATION = 0x1
Global Const $SV_TYPE_SERVER = 0x2
Global Const $SV_TYPE_SQLSERVER = 0x4
Global Const $SV_TYPE_DOMAIN_CTRL = 0x8
Global Const $SV_TYPE_DOMAIN_BAKCTRL = 0x10
Global Const $SV_TYPE_TIME_SOURCE = 0x20
Global Const $SV_TYPE_AFP = 0x40
Global Const $SV_TYPE_NOVELL = 0x80
Global Const $SV_TYPE_DOMAIN_MEMBER = 0x100
Global Const $SV_TYPE_PRINTQ_SERVER = 0x200
Global Const $SV_TYPE_DIALIN_SERVER = 0x400
Global Const $SV_TYPE_XENIX_SERVER = 0x800
Global Const $SV_TYPE_NT = 0x1000
Global Const $SV_TYPE_WFW = 0x2000
Global Const $SV_TYPE_SERVER_MFPN = 0x4000
Global Const $SV_TYPE_SERVER_NT = 0x8000
Global Const $SV_TYPE_POTENTIAL_BROWSER = 0x10000
Global Const $SV_TYPE_BACKUP_BROWSER = 0x20000
Global Const $SV_TYPE_MASTER_BROWSER = 0x40000
Global Const $SV_TYPE_DOMAIN_MASTER = 0x80000
Global Const $SV_TYPE_WINDOWS = 0x400000
Global Const $SV_TYPE_CLUSTER_NT = 0x1000000
Global Const $SV_TYPE_TERMINALSERVER = 0x2000000
Global Const $SV_TYPE_CLUSTER_VS_NT  = 0x4000000
Global Const $SV_TYPE_LOCAL_LIST_ONLY = 0x40000000
Global Const $SV_TYPE_DOMAIN_ENUM = 0x80000000
Global Const $SV_TYPE_ALL = 0xFFFFFFFF

$aCompList = _NetServerEnum($SV_TYPE_WORKSTATION)

_ArrayDisplay($aCompList)

Func _NetServerEnum ($iSrvType = -1, $sDomain = '')
    Local $uBufPtr = DllStructCreate("ptr;int;int"), $res[1]=[0], $i
    Local $uRecord = DllStructCreate("dword;ptr"), $iRecLen = DllStructGetSize($uRecord)
    Local $uString = DllStructCreate("char[16]")
    Local $uDomain = DllStructCreate("byte[32]"), $pDomain = 0
    If Not ($sDomain='' Or $sDomain='*') Then
        DllStructSetData($uDomain, 1, StringToBinary($sDomain,2))
        $pDomain = DllStructGetPtr($uDomain)
    EndIf
    Local $ret = DllCall ("netapi32.dll", "int", "NetServerEnum", _
        "ptr", 0, "int", 100, _
        "ptr", DllStructGetPtr($uBufPtr,1), "int", -1, _
        "ptr", DllStructGetPtr($uBufPtr,2), _
        "ptr", DllStructGetPtr($uBufPtr,3), _
        "int", $iSrvType, "ptr", $pDomain, "int", 0 )
    If $ret[0] Then Return SetError(1, $ret[0], '')
    Local $res[DllStructGetData($uBufPtr,3)+1]=[DllStructGetData($uBufPtr,3)]
    For $i=1 To DllStructGetData($uBufPtr,3)
        Local $uRecord = DllStructCreate("dword;ptr", DllStructGetData($uBufPtr,1)+($i-1)*$iRecLen)
        Local $sNBName = DllStructCreate("byte[32]", DllStructGetData($uRecord,2))
        DllStructSetData($uString,1,BinaryToString(DllStructGetData($sNBName,1),2))
        $res[$i] = DllStructGetData($uString,1)
    Next
    $ret = DllCall ("netapi32.dll", "int", "NetApiBufferFree", "ptr", DllStructGetData($uBufPtr,1))
    Return $res
EndFunc

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
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...