Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

find which user is logged on

Posted on 2004-10-02
13
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +1
13 Comments
 
LVL 1

Assisted Solution

by:ch0c
ch0c earned 300 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:
Kiran Paul VJ earned 450 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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
 
LVL 86

Expert Comment

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

Expert Comment

by:Kiran Paul VJ
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:Kiran Paul VJ
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

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