CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2001
    Posts
    8

    Help to get/set workgroup in Win2K/NT

    Can you help me? How to get workgroup name on the Windows2000/NT by VC++ system calls? Due to the security of 2000/NT operating system, the workgroup(not domain) name was saved inside local Sam database, I want to know how to extract the data from the System..

    Any help will be great appreciated...


  2. #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.

  3. #3
    Join Date
    May 2002
    Posts
    10,943

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

    Hi ezway. Welcome to the forums. One thing to note before posting is how old a thread is. You posted on a 5 year old thread.

    Please remember to post on more recent and relevant topics.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  4. #4
    Join Date
    Apr 2008
    Posts
    1

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

    Awesome thank you, solved my problem!

  5. #5
    Join Date
    Aug 2007
    Location
    Tokyo Japan
    Posts
    10

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

    I think ezway did the right thing.

  6. #6
    Join Date
    Jun 2008
    Posts
    37

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

    Quote Originally Posted by BitNinja View Post
    I think ezway did the right thing.
    Yeah, this is the landmark to move on

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