Solved

find which user is logged on

Posted on 2004-10-02
13
172 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:
Kiran Paul VJ 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
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!

 

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

Suggested Solutions

Title # Comments Views Activity
pre4 challenge 19 110
Detect file exist or not 3 198
Is there a simple front-end menu system. 9 118
x-bar in Google Sheets 2 91
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…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

679 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