Solved

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

Posted on 2003-11-14
7
1,925 Views
Last Modified: 2013-12-20
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
0
Comment
Question by:rocket24
  • 3
  • 3
7 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9751312
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
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9751366
Here's an API example that gets MAC Address:

http://www.mvps.org/vbnet/index.html?code/network/macaddress.htm
0
 

Author Comment

by:rocket24
ID: 9753485
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
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 9

Expert Comment

by:TooKoolKris
ID: 9759369
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.
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 100 total points
ID: 9761031
Have you tried using ShellExecute API:

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

Private Sub Command1_Click()
Call ShellExecute(hwnd, "Open", ("\\127.0.0.1"), "", "", 1)
End Sub
0
 

Author Comment

by:rocket24
ID: 9771874
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
0
 

Author Comment

by:rocket24
ID: 9772799
I do realise that that is the same code as vinnyd79 but i kept getting syntax errors before the code was neatly formatted.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now