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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to know Computer Name

Status
Not open for further replies.

lavomar1

Programmer
May 13, 2002
17
0
0
CA
Hi...

Here's a simple question.

I want to know on wich computer (computer name) a specific user is logged.

I'm currently trying to perfrom this action with the function NetSessionEnum from the "Network Management SDK", but it doesn't work correctly. So I'm now wordering if there's another way of finding what I'm looking for.

thanx for your help!
 
When you say NetSessionEnum "doesn't work correctly" what exactly do you mean by this?

William
Software Engineer
ICQ No. 56047340
 
I used NetFileEnum to know all the files open on a server. This function return me a file handle, the path of the file, the user who has the file open ans somes others things not very interesting to me.

But I also want to know on wich CPU the user returned by the previous function is logged.

So I use NetSessionEnum on the same server with the user receive from NetFileEnum. But NetSessionEnum return me an error (2221 *). If I use NetSessionEnum alone (only specify the server) the user is present and then return the correct workstation.

I'll post my code... in the next reply.

* Error 2221 : The user name could not be found.
 
Code:
FILE_INFO_3*     FileBuffer = NULL;
SESSION_INFO_10* tmpBuf     = NULL;
NET_API_STATUS   FileStatus;
NET_API_STATUS   StationStatus;

...

do
   {
   FileStatus = NetFileEnum(ServerName,
                            NULL,
                            NULL,
                            3,
                            (LPBYTE*)&FileBuffer,
                            FileBufSize,
                            &FileRead,
                            &FileTotal,
                            &FileResume);
   if (FileStatus != NERR_Success 
   AND FileStatus != ERROR_MORE_DATA)
      {
      wprintf(L"System Error : %d\n\n", FileStatus);
      break;
      } 

   // For each opened file...
   for (DWORD E = 0; E < FileRead; E++)
      {
      StationStatus = NetSessionEnum(
                          ServerName,
                          NULL,
                          FileBuffer->fi3_username,
                          10,
                          (LPBYTE*)&StationBuffer,
                          MAX_PREFERRED_LENGTH,
                          &StationRead,
                          &StationTotal,
                          NULL);
      
      // If function work
      if (StationStatus == NERR_Success)
         wprintf(L&quot;%-12s%-16s%-50s\n&quot;, 
                 FileBuffer->fi3_username,
                 tmpBuf->sesi10_cname,
                 FileBuffer->fi3_pathname);
      // Elsewhere... HERE RETURN ERROR 2221
      else
         wprintf(L&quot;%-12s%N\\A (%d)%-50s\n&quot;, 
                 FileBuffer->fi3_username,
                 StationStatus,
                 FileBuffer->fi3_pathname);

      FileBuffer++;
      } 
   } 
while (FileStatus == ERROR_MORE_DATA);

...
 
all that code....
in perl its just like this
Code:
print $ENV{COMPUTERNAME};
based on the environement var
[/code]%computername%[/code]
so why not capture the output of this [wink] ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
I seem simple, but I don't want to know the computer name on wich my program run.

What I want to know is the computer name of user who has a session open on a server.

That's more complicated...
 
if u have perl installed run this from dos
perl -e &quot;foreach (%ENV) {print \&quot;$ENV{$_}\n\&quot;;}&quot;
this will show all environement variable on this machine

this might help or not its up to u to see that ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
I belive, but I am not 100%, that the API calls

GetUserName and GetComputerName will be run on the users system. Just log to a file or pop up a message box with the data.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top