?
Solved

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

Posted on 2003-11-14
7
Medium Priority
?
2,084 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

840 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