Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. NetWkstaGetInfo() Question

NetWkstaGetInfo() Question

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiondebuggingperformance
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RobJones
    wrote on last edited by
    #1

    Hello, I am using the following to pull the domain/workgroup name of a remote computer. This works just fine when I use the remote computers IP address but if I use the machine name it fails with an access is denied error. Has anyone experienced the same problem or does anyone have any ideas why this is happening?

    DWORD dwLevel = 100;
    LPWKSTA\_INFO\_100 pBuf = NULL;
    NET\_API\_STATUS nStatus;
    
    nStatus = NetWkstaGetInfo(L"\\\\\\\\192.168.1.2", dwLevel, (LPBYTE \*)&pBuf);
    
    if (nStatus == NERR\_Success)
    {
    	TRACE(L"Name:\\t\\t%s\\n",		pBuf->wki100\_computername);
    	TRACE("Platform:\\t%d\\n",	pBuf->wki100\_platform\_id);
    	TRACE(L"Domain:\\t\\t%s\\n",	pBuf->wki100\_langroup);
    }
    else
    {
    	char error\[1024\];
    	FormatMessage(FORMAT\_MESSAGE\_FROM\_SYSTEM, NULL, nStatus, NULL, error, sizeof(error), NULL);
    	TRACE("Error: %s", error);
    }
    
    // Free the allocated memory.
    if (pBuf != NULL)
    	NetApiBufferFree(pBuf);
    

    Thanks, Rob Whoever said nothing's impossible never tried slamming a revolving door!

    D 1 Reply Last reply
    0
    • R RobJones

      Hello, I am using the following to pull the domain/workgroup name of a remote computer. This works just fine when I use the remote computers IP address but if I use the machine name it fails with an access is denied error. Has anyone experienced the same problem or does anyone have any ideas why this is happening?

      DWORD dwLevel = 100;
      LPWKSTA\_INFO\_100 pBuf = NULL;
      NET\_API\_STATUS nStatus;
      
      nStatus = NetWkstaGetInfo(L"\\\\\\\\192.168.1.2", dwLevel, (LPBYTE \*)&pBuf);
      
      if (nStatus == NERR\_Success)
      {
      	TRACE(L"Name:\\t\\t%s\\n",		pBuf->wki100\_computername);
      	TRACE("Platform:\\t%d\\n",	pBuf->wki100\_platform\_id);
      	TRACE(L"Domain:\\t\\t%s\\n",	pBuf->wki100\_langroup);
      }
      else
      {
      	char error\[1024\];
      	FormatMessage(FORMAT\_MESSAGE\_FROM\_SYSTEM, NULL, nStatus, NULL, error, sizeof(error), NULL);
      	TRACE("Error: %s", error);
      }
      
      // Free the allocated memory.
      if (pBuf != NULL)
      	NetApiBufferFree(pBuf);
      

      Thanks, Rob Whoever said nothing's impossible never tried slamming a revolving door!

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      RobJones wrote:

      ...but if I use the machine name it fails with an access is denied error.

      Your code snippet works fine for me using either an IP address or a machine name. How are you specifying the machine name?


      "The largest fire starts but with the smallest spark." - David Crow

      "Judge not by the eye but by the heart." - Native American Proverb

      R 1 Reply Last reply
      0
      • D David Crow

        RobJones wrote:

        ...but if I use the machine name it fails with an access is denied error.

        Your code snippet works fine for me using either an IP address or a machine name. How are you specifying the machine name?


        "The largest fire starts but with the smallest spark." - David Crow

        "Judge not by the eye but by the heart." - Native American Proverb

        R Offline
        R Offline
        RobJones
        wrote on last edited by
        #3

        I specify it like.... L"\\\\machine". I'm going to test it at work today on a few other machines. Just thought it was weird that simply switching between IP and machine name would cause that error. Whoever said nothing's impossible never tried slamming a revolving door!

        D 1 Reply Last reply
        0
        • R RobJones

          I specify it like.... L"\\\\machine". I'm going to test it at work today on a few other machines. Just thought it was weird that simply switching between IP and machine name would cause that error. Whoever said nothing's impossible never tried slamming a revolving door!

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Makes me wonder if it's a name-resolution issue. Do you have a problem using gethostbyname()? In other words, can you use this function to resolve a host name to its IP address?


          "The largest fire starts but with the smallest spark." - David Crow

          "Judge not by the eye but by the heart." - Native American Proverb

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups