Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retreive Use Logged in Session

Status
Not open for further replies.

jbsys

Programmer
May 6, 2005
51
CA
Hi;
Using VC++, and assuming we are talking about Win32 based windows network servers, is there a way in C++ to retrieve the currently logged on user's session id? It can be done in UNIX on the HP-UX, I'm wondering if it can be done on a windows network server. If so, how? Please provide example code if possible.

P.S. This question is in no way associated with an internet website IIS login session. Strictly deals with a user being logged onto a network server.

Thanks
 
Try the environment variable USERNAME. Works for 2000 and XP.
 
Thanks.
yes that works for the user's username, I'm trying find out if there is a way to retrieve the internal session id.
 
Just wondering...

> Strictly deals with a user being logged onto a network server.

What do you mean "network server"? Telnet, SSH? Windows usually are file servers. What do you use that "session ID" for in your project? Are you shure, there are such things in Windows like "sessions" and "session ID's" at all?

 
mingis;
The logged user's session Id in a Win32 environment is actually part of a process's token. If you have the process ID, you should be able to get the process's session id. On the HP-UX, you have getpid() and getsid(). getpid() returns the process id and getsid() returns the user's session id. There is a similar getpid() function for the Win32 environment by including the process.h header into a c++ program. However, there is no easy equivalent for the getsid(). Apparently, the session id of the process's token is attainable, I'm looking for an easy way to obtain, and place the values into an environment variable, the PID and SID of the currently running process. These ID's will be used to create unique file names.

Thanks

jbsys
 
GetTempFileName() could be used to create unique file names.
 
mingis;
I'll check that out and let you know.

Thanks
jbsys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top