Results 1 to 5 of 5

Thread: Detecting Computer Names on a Lan

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 1999
    Location
    Louisville, KY
    Posts
    48

    Question

    Does anyone have a sample of how to detect all workstations currently logged into a LAN?

    Seth

  2. #2
    Lively Member
    Join Date
    Apr 2000
    Location
    Hell
    Posts
    89
    Okay, to me a LAN is a group of computers that can talk to each other. Your question and the subject of the post are somewhat contradictive... do you want:

    (a) To find out what computers are connected to a LAN?
    (b) To find out what users are using said computers?
    (c) To find out what users are logged into an NT domain?
    - Steve

    Real programmers use COPY CON PROGRAM.EXE

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 1999
    Location
    Louisville, KY
    Posts
    48
    Lets go with option A). To find out what computers are connected to a LAN?

    Seth

  4. #4
    Lively Member
    Join Date
    Jan 1999
    Location
    Rochester NY, USA
    Posts
    93
    Do you want just Windows machines or UNIX machines also?

  5. #5
    Lively Member
    Join Date
    Apr 2000
    Location
    Hell
    Posts
    89

    Thumbs up

    All right! After wasting a good deal of time (which is okay, cuz it would have been wasted by something else otherwise), I did some research and got what you want.

    You need to do some dirty VB stuff, though. If you're afraid of modifying raw object references, don't do anything.

    If' you're NOT afraid, then go here:

    http://www.mvps.org/btmtz/ishellex

    And download the IShellEx example.

    With some changes, it can be made to connect to Network Neighborhood and enumerate everything in there.

    Heres the key piece of code I used for the sub main:

    Code:
       Dim pidlNetHood As Long, pidlNetComputers As IEnumIDList
       Dim pFolder As Long
       Dim isfFolder As IShellFolder
       Dim IID_IShellFolder As GUID
       
       ' Fill IShellFolder Interface ID, {000214E6-0000-0000-C000-000000046}
       DEFINE_OLEGUID IID_IShellFolder, &H214E6, 0, 0
       
       ' Get the shell's allocator.
       If Not (SUCCEEDED(SHGetMalloc(pMalloc))) Then
         main1 = 1: Exit Function
       End If
       MoveMemory g_IMalloc, pMalloc, 4   ' Set g_IMalloc = pMalloc
      
       ' Get the PIDL for the Network Neighborhood folder.
       If Not (SUCCEEDED(SHGetSpecialFolderLocation(0, CSIDL_NETWORK, pidlNetHood))) Then
          Exit Function
       End If
       
       ' get an instance of IShellFolder
       Call SHGetDesktopFolder(pFolder)
       MoveMemory isfFolder, pFolder, 4&
     
       ' Bind to the folder
       Call isfFolder.BindToObject(pidlNetHood, 0, IID_IShellFolder, pFolder)
       Set isfFolder = Nothing ' remove our current instance
       MoveMemory isfFolder, pFolder, 4&
       Call isfFolder.EnumObjects(0&, SHCONTF_FOLDERS Or SHCONTF_NONFOLDERS Or SHCONTF_INCLUDEHIDDEN, pidlNetComputers)
         
       ' Process each item identifier in the list.
       Dim netHoodListPtr As Long, aSHITEMID As SHITEMID, pidl As Long
       netHoodListPtr = g_IMalloc.Alloc(LenB(aSHITEMID))
       pidlNetComputers.Next 1, netHoodListPtr, pidl
       Do While (pidl > 0)
         Dim sName As STRRET
         Dim pSubFolder As Long
         Dim pidlCopy As Long, curItem As ITEMIDLIST
         ' nethoodlistptr POINTS to an array of item ID lists
         MoveMemory curItem, ByVal netHoodListPtr, 4
         Call isfFolder.GetDisplayNameOf(netHoodListPtr, SHGDN_INFOLDER, sName)
         PrintStrRet netHoodListPtr, sName
         ' next!
         pidlNetComputers.Next 1, netHoodListPtr, pidl
       Loop
       ' free
       g_IMalloc.Free netHoodListPtr
       
       ' Release the shell's allocator.
       MoveMemory g_IMalloc, 0&, 4   ' Set g_IMalloc = Nothing, but without decreasing the refcount

    You'll also need to go to http://www.vbaccelerator.com/ into the TLB section (it's under Resources in the contents) and download the ISHF_Ex.tlb file, and add it to the References section in VB.

    - Steve

    Real programmers use COPY CON PROGRAM.EXE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width