Solved

find which user is logged on

Posted on 2004-10-02
13
169 Views
Last Modified: 2013-11-20
i am trying to make a dialog app that will clean up my hard drive automatically. the question is uxing winxp, the temporary internet files and cookies, are under c:\\documents and settings\'user'. how can i find out the username for that folder of the user presently logged on?
0
Comment
Question by:cheapstr
  • 4
  • 4
  • 3
  • +1
13 Comments
 
LVL 1

Assisted Solution

by:ch0c
ch0c earned 100 total points
ID: 12210415
BOOL GetUserName(LPTSTR lpBuffer,  LPDWORD nSize) does the job. lpBuffer is the user's name and nSize is the size of the string, including the null terminator.

Good luck.
0
 
LVL 86

Expert Comment

by:jkr
ID: 12212408
If you are looking for the profile path, just use

char* pszUserProfile = getenv ( "USERPROFILE");

which will return "c:\documents and settings\'user'" correctly for all localized versions of Windows (on a german Windows, that would e.g. be "c:\Dokumente und Einstellungen\'user'")
0
 
LVL 16

Accepted Solution

by:
kiranvj earned 150 total points
ID: 12215963
hi...
the api ch0c said can be used to find the current user name.

heres the code
//////////////////////

      char username[255];
      DWORD buf = 255;                              
      ::GetUserName(username,&buf);
      AfxMessageBox(username);

/////////////////////

kiranvj
0
 

Author Comment

by:cheapstr
ID: 12285645
to kiranvj:
worked like a charm, and i will accept your answer, but i'll add an extra 200 points if you can show me how to get into that folder. (I dont know how to use a varialbe when specifying the path c:\documents and settings\"username")?
0
 
LVL 86

Expert Comment

by:jkr
ID: 12290200
>>but i'll add an extra 200 points if you can show me how to get into that folder

You won't need to - as I wrote: just call

char* pszUserProfile = getenv ( "USERPROFILE");

and you'll get the *full* path anyway. Any reason you have chosen to ignore my comment?
0
 
LVL 1

Expert Comment

by:ch0c
ID: 12294428
Sorry if this sounds a bit offensive, but why wouldn't I get the points, since I answered the question first?
Thanks.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Expert Comment

by:jkr
ID: 12302346
That's true, also...
0
 
LVL 16

Expert Comment

by:kiranvj
ID: 12541473

>>I dont know how to use a varialbe when specifying the path c:\documents and settings\"username")?

plz try some think like this

////////////////////////

CString path;
path.Format("c:\\documents and settings\\%s", username);
AfxMessageBox(path);
///////////////////////

hope this helps
kiranvj

0
 
LVL 1

Expert Comment

by:ch0c
ID: 12815538
I posted the first correct answer to this problem, so I believe that my answer should be accepted.

Of course, I'd be willing to split the points since other people have also given good advice. :)
0
 
LVL 16

Expert Comment

by:kiranvj
ID: 12820484
hi..

i think i deserve some points,  i would recommend a split of points.

>>ch0c
i know u posted an answer first, but i think the questioner did not understand it, and my post contains the full code. He used my code and he liked it , its clear from his feedback.

kiranvj
0
 
LVL 1

Expert Comment

by:ch0c
ID: 12826323
Ok, you're right. Splitting the points would probably be fairest.
0
 
LVL 86

Expert Comment

by:jkr
ID: 13229576
*plonk*
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASCII Non-Printable characters/codes and their HTML equivalents 6 104
viewing source code from eclipse 13 88
modThree challenge 4 77
pre4 challenge 19 93
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: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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 …

914 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

16 Experts available now in Live!

Get 1:1 Help Now