Windows NT Username Environment variable

  • Thread starter Thread starter Perumal
  • Start date Start date
P

Perumal

I need to schedule a batch process to check if any user
is logged on and if not then delete certain files.

This I am able to accomplish by using %USERNAME% and
running the batch file in command prompt.

But the problem is when I schedule this process
%USERNAME% is displayed as "" even if administrator is
logged on.

Help will be appreciated.

Thanks & Regards,
Perumal
 
Your batch file will be running in the context of the scheduler you use to start it, not in the
context of the logged on user, so %Username% is not much use to you.

If you want to clear the files on a workstation, why not use a LogOff script? Otherwise, there
are a couple of approaches I can think of: logged on users are registered in the WINS database
so you may be able to query that - it's a normal Jet database although I've never actually tried
connecting to it. That will give the users logged onto the domain.

Alternatively, write a small program using NetWkstaGetInfo, which can return the number of
logged on users to the local machine. There's an example doing that in MSDN - search for "logged
 
Back
Top