Jump to content

Net view results


 Share

Recommended Posts

I need some help with a script

I want to make a script that get's the computer names from the cmd command "net view" en puts them in a dropdown list

but i have realy no clue how to do it

here some info:

you wil get a scheme like this from the command "net view"

Servername          Comment

-------------------------------------------------------------------------------
\\LOEK-BOVEN           Loekus.nl
\\COMPUTER2
\\COMPUTER3

now the thing I need it this,

i need all the names behinde the "\\" in a drop down list, but if you look at \\LOEK-BOVEN there is a comment, i DON'T need that in the drop down....

i hope it's a little bid clear

cheers, adored :P

Link to comment
Share on other sites

I need some help with a script

I want to make a script that get's the computer names from the cmd command "net view" en puts them in a dropdown list

but i have realy no clue how to do it

here some info:

you wil get a scheme like this from the command "net view"

Servername          Comment

-------------------------------------------------------------------------------
\\LOEK-BOVEN           Loekus.nl
\\COMPUTER2
\\COMPUTER3

now the thing I need it this,

i need all the names behinde the "\\" in a drop down list, but if you look at \\LOEK-BOVEN there is a comment, i DON'T need that in the drop down....

i hope it's a little bid clear

cheers, adored :P

Old school DOS batch file technique:

@echo off
for /f "tokens=1"  %%i in ('net view') do (
    call :CheckName %%i
    )

:CheckName
Set TestVal=%1
If Not {%TestVal:~0,2%}=={\\} goto :EOF
Set TestVal=%TestVal:~2,15%
Set TestVal=%TestVal: =%
echo %TestVal%
goto :eof

Just for nostalgia's sake... :nuke:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Old school DOS batch file technique:

@echo off
for /f "tokens=1"  %%i in ('net view') do (
    call :CheckName %%i
    )

:CheckName
Set TestVal=%1
If Not {%TestVal:~0,2%}=={\\} goto :EOF
Set TestVal=%TestVal:~2,15%
Set TestVal=%TestVal: =%
echo %TestVal%
goto :eof

Just for nostalgia's sake... :P

hmm if i use this script it pops op the screen for a sec, and disapears
Link to comment
Share on other sites

HI,

#include<File.au3>
#include<Array.au3>

RunWait(@ComSpec & ' /c net view > ' & @TempDir & "\netview.txt", '', @SW_HIDE)

Global $count = _FileCountLines(@TempDir & "\netview.txt")
Global $NetView[$count]

$file = FileOpen(@TempDir & "\netview.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

For $i = 0 To $count
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    If StringInStr($line, "\\") <> 0 Then
        $NetView[$i] = _StringBetween1($line, "\\", " ")
    EndIf
Next

FileClose($file)
FileDelete(@TempDir & "\netview.txt")

_ArrayDisplay($NetView, "Servernames")

Func _StringBetween1($s_String, $s_Start = 0, $s_End = 0)
    $s_Start = StringInStr($s_String, $s_Start) + StringLen($s_Start)
    Return StringMid($s_String, $s_Start, StringInStr($s_String, $s_End) - $s_Start)
EndFunc   ;==>_StringBetween1

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

#include<Array.au3>


$Servernames = Net_View()

_ArrayDisplay($Servernames, "Servernames")

Func Net_View()
    Local $s_Buf = '', $a_Buf, $i_Pid = Run(@ComSpec & ' /c net view', '', @SW_HIDE, 2 + 4)
    While Not @error
        $s_Buf &= StdoutRead($i_Pid)
    WEnd
    $a_Buf = StringRegExp ($s_Buf, "\\\\([0-9a-zA-Z-]*)", 3)
    ProcessClose($i_Pid)
    Return $a_Buf
EndFunc   ;==>Net_View

Using a regex to get the names.

Link to comment
Share on other sites

hmm if i use this script it pops op the screen for a sec, and disapears

Well, it just outputs the list to STDOUT and ends. The shiny new hotness in AutoIT is being able to intercept the STDOUT and pipe it into your script. So you can run it like this:

#include <Constants.au3>

$Batch = "C:\Temp\NetView.bat" ; Edit to where you saved the batch file
$sOutput = ""
$hPID = Run(@ComSpec & " /c " & $Batch, @TempDir, @SW_MINIMIZE, $STDOUT_CHILD)
While 1
    $sOutput &= StdoutRead($hPID)
    If @error Then ExitLoop
WEnd
MsgBox(64, "Results", "NetView.bat Results: " & @CRLF & $sOutput)

:nuke:

It's still maddening that I can't find the COM object provider that will let us read NetBIOS\Network Neighborhood schtuff straight out... :P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Well, it just outputs the list to STDOUT and ends. The shiny new hotness in AutoIT is being able to intercept the STDOUT and pipe it into your script. So you can run it like this:

#include <Constants.au3>

$Batch = "C:\Temp\NetView.bat" ; Edit to where you saved the batch file
$sOutput = ""
$hPID = Run(@ComSpec & " /c " & $Batch, @TempDir, @SW_MINIMIZE, $STDOUT_CHILD)
While 1
    $sOutput &= StdoutRead($hPID)
    If @error Then ExitLoop
WEnd
MsgBox(64, "Results", "NetView.bat Results: " & @CRLF & $sOutput)

:)

It's still maddening that I can't find the COM object provider that will let us read NetBIOS\Network Neighborhood schtuff straight out... :nuke:

yeah i knew how i needed to Stdoutread.. but i copy'd the script wrong :P

great thnx for the help

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...