Solved

find which user is logged on

Posted on 2004-10-02
13
168 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 98
repeatEnd java challenge 42 83
Tab names are off by one 5 49
Use of condition with 'serial' in ansible 2 37
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 (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

14 Experts available now in Live!

Get 1:1 Help Now