CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #2
    Join Date
    Jan 2005
    Posts
    3

    Exclamation Re: Help to get/set workgroup in Win2K/NT

    Hi Chris!

    How to get my workgroup?
    The following code get workgroup from local computer using the NetWkstaGetInfo() function.


    1. Import file (Netapi32.lib).
    2. include file (lm.h).

    Code:
    BOOL GetWorkgroup(LPTSTR pszName)
    {
    	DWORD dwLevel = 102;
    	LPWKSTA_INFO_102 pBuf = NULL;
    	NET_API_STATUS nStatus;
    	LPTSTR	pszServerName = NULL;
    	BOOL	bRes=FALSE;
    
    	nStatus = NetWkstaGetInfo(NULL, dwLevel, (LPBYTE *)&pBuf);
    	if (nStatus == NERR_Success)
    	{
    		TCHAR szTemp[MAX_PATH]={'\0',};
    		int BufSize=sizeof(szTemp)/sizeof(TCHAR);
    	#ifdef UNICODE
    		_tcscpy(szTemp, pBuf->wki102_langroup);
    	#else
    		::WideCharToMultiByte(CP_ACP, 0, pBuf->wki102_langroup, -1, szTemp, BufSize, 0, 0);
    	#endif
    		 lstrcpy(pszName, szTemp);
    		 bRes=TRUE;
    	}
    
    	if (pBuf != NULL)
          NetApiBufferFree(pBuf);
    
    	return bRes;
    }
    Last edited by PeejAvery; April 30th, 2008 at 01:48 PM. Reason: Fixed code tags.

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

Featured