home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
LMUTIL.ZIP
/
USERNAME.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-03-19
|
3KB
|
132 lines
/*
** Program: USERNAME
**
** Author: Roger L Soles
**
** Description:
**
** This example C program uses the NetWkstaGetInfo call to obtain
** information to determine whether a user is logged on or not.
**
** Instructions:
**
** USERNAME [-?q] USER_NAME
**
** Errorlevel = 0, user is currently logged on on at this workstation
** Errorlevel = 1, user is not currently logged on at this workstation
**
** if '-q' is not specified, command will execute in verbose mode
** (it will provide messages on the screen).
**
*/
#define LINT_ARGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define INCL_NETGROUP
#define INCL_NETWKSTA
#define INCL_NETERRORS
#include <lan.h>
#include "getsrv.h"
void main (int argc, char * argv[])
{
char far * cptr;
int qmode = 0;
API_RET_TYPE uRetCode = 0;
char far * pszServer;
char far * pszUserName;
char far * pszName;
argv++; argc--;
cptr = argv[0];
if ( *cptr++ == '-' )
{
switch (*cptr)
{
case 'q':
case 'Q':
/*
** quite mode inhibits messages -- rather uses only
** the error level
*/
qmode = 1;
break;
case '?':
default:
printf ("\nUSAGE: USERNAME [-?q] USER_NAME\n");
exit (1);
}
argv++; argc--;
}
if (argc >= 1)
{
/*
** User Name
*/
strupr (argv[0]);
pszName = argv[0];
}
else
{
pszName = NULL;
}
/*
** Get Logon Server & User Name
*/
if ( get_logon_server (&pszServer, &pszUserName) != 0 )
{
if (qmode == 0)
{
if (pszName == NULL)
{
printf ("Workstation Not Logged In\n");
}
else
{
printf ("%Fs is not currently logged on\n", pszName);
}
}
exit (1);
}
/*
** No user name given, so report who is logged in
*/
if (pszName == NULL)
{
if (qmode == 0)
{
printf ("%Fs is currently logged onto %Fs\n", pszUserName, pszServer);
}
exit (0);
}
/*
** Check to see if current user is as expected
*/
if ( strcmp (pszName, pszUserName ) == 0 )
{
if (qmode == 0)
{
printf ("%Fs is currently logged onto %Fs\n", pszName, pszServer);
}
exit (0);
}
if (qmode == 0)
{
printf ("%Fs is not currently logged onto %Fs\n", pszName, pszServer);
}
exit (1);
}