Solved

find which user is logged on

Posted on 2004-10-02
13
170 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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: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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

777 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