Link to home
Start Free TrialLog in
Avatar of fosters
fosters

asked on

Get Domain Name

Hi

I wish to get the name of the Domain,  the workstation the programme is running, is on.

My Program is written in Visual C++ 5, using the MFC AppWizard.

I have tried using GetUserName() to get user ID for the LookUpAccountName()function.
Which according to MSDN returns the domain name.

When run on NT Dr. Watson kicks in...

Current code below...


CString PCInformation::GetDomainName()
{
      LPTSTR lpAccountName= " ";       
      DWORD cbAccountName = 20;
      PSID Sid;
        LPDWORD cbSid;        
      LPTSTR ReferencedDomainName = " ";
        LPDWORD cbReferencedDomainName;
             PSID_NAME_USE peUse;

      GetUserName(lpAccountName, &cbAccountName);
      
LookupAccountName(NULL, lpAccountName, Sid, cbSid, ReferencedDomainName, cbReferencedDomainName, peUse);

      return (LPSTR)ReferencedDomainName;

}

Any help would be much appreciated..

Cheers
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
HOWTO: Retrieve Current User and Domain Names on Windows 95 and Windows 98
http://support.microsoft.com/support/kb/articles/Q155/6/98.ASP
Avatar of fosters
fosters

ASKER

I have enetered the code and got it to complile. But I keep getting the following link error.

PCInformation.obj : error LNK2001: unresolved external symbol "public: int __thiscall PCInformation::GetUserAndDomainName(char *,unsigned long *,char *,unsigned long *)" (?GetUserAndDomainName@PCInformation@@QAEHPADPAK01@Z)


Any ideas....
It looks like that you declare GetUserAndDomainName as a public member function of your PCInformation class. But how do you define it? Do you forget to put PCInformation:: right before GetUserAndDomainName?
Avatar of fosters

ASKER

I did indeed forget to stick PCInformation:: in.

Cheers for your help