Solved

Get Domain Name

Posted on 2000-03-31
5
245 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:fosters
  • 3
  • 2
5 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 2675100
HOWTO: Retrieve Current User and Domain Names on Windows NT
http://support.microsoft.com/support/kb/articles/Q111/5/44.ASP
0
 
LVL 23

Expert Comment

by:chensu
ID: 2675102
HOWTO: Retrieve Current User and Domain Names on Windows 95 and Windows 98
http://support.microsoft.com/support/kb/articles/Q155/6/98.ASP
0
 

Author Comment

by:fosters
ID: 2676043
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....
0
 
LVL 23

Expert Comment

by:chensu
ID: 2676397
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?
0
 

Author Comment

by:fosters
ID: 2676435
I did indeed forget to stick PCInformation:: in.

Cheers for your help
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now