[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2003-11-14
7
Medium Priority
?
2,060 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses

656 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