Solved

Get Domain Name

Posted on 2000-03-31
5
252 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Importing Special Characters in Dynamics GP Through Integration Manager 3 75
sum28 challenge 31 112
Detect file exist or not 3 157
Way to decrease size of apk file 9 67
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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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