Link to home
Start Free TrialLog in
Avatar of rocket24
rocket24

asked on

Using Netbios (nbtstat -A or -a) through Visual Basic

Hello Experts

Is it possible to run the Netbios command thorugh VB instead of using nbtstat in DOS or typing //whatever in explorer

Thanks in advance

rocket24
Avatar of vinnyd79
vinnyd79

You could shell the command in a hidden window and redirect output to a text file,then open the textfile to get the data.

here is an example using a command button and a listbox:


Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)

Private Sub ShellWait(ByVal JobToDo As String)
Dim hProcess As Long, RetVal As Long
    hProcess = OpenProcess(&H400, False, Shell(JobToDo, vbHide))
    Do
        GetExitCodeProcess hProcess, RetVal
        DoEvents: Sleep 100
    Loop While RetVal = &H103
End Sub

Private Sub Command1_Click()
Dim Ln As String, IpAddress As String
Dim ff As Integer
' change ip address to the ip or machine name to check
IpAddress = "192.168.1.100"
' shell and wait for command to complete.
ShellWait Environ("Comspec") & " /c nbtstat -A " & IpAddress & " > TmpUsr.tmp"
List1.Clear
ff = FreeFile
Open "TmpUsr.tmp" For Input As #ff
Do Until EOF(ff)
Line Input #ff, Ln
If Trim$(Ln) <> "" Then
    List1.AddItem Ln
End If
Loop
Close #ff
Kill "TmpUsr.tmp"
End Sub
Avatar of rocket24

ASKER

Thanks thats intresting code but what I meant is that my program would have a text box and a command button.

The text box would be where the IP address is entered and the command button would connect to it (if the shares were active) and open it in explorer like on a network when you open explorer and type "\\127.0.0.1" or something in the address bar and then the shares are displayed.

Thanks again

rocket24
nbtstat is for checking NetBios session information not for veiwing what shares are present on a computer. Why re-invent the wheel here. If you want to see what shares are available just right click on my computer choose manage and then connect to the other computer and expand the shared folders and look at shares.
ASKER CERTIFIED SOLUTION
Avatar of vinnyd79
vinnyd79

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks vinnyd79 although your code didn't work until I replaced the API with this one.

Private Declare Function ShellExecute _
    Lib "shell32.dll" Alias "ShellExecuteA" ( _
    ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

Thanks everyone
I do realise that that is the same code as vinnyd79 but i kept getting syntax errors before the code was neatly formatted.