Tom's Hardware > Forum > Windows XP > Windows XP General Discussion > Need help with batch file...

Need help with batch file...

Forum Windows XP : Windows XP General Discussion - Need help with batch file...

Tom's Hardware: Over 1.4 million members in 6 different countries available to answer all your high-tech questions. Sign up now! Its free!
Word :    Username :           
 

Archived from groups: microsoft.public.windowsxp.security_admin (More info?)

 

I am attempting to write a batch file (to be executed at startup) to enable
or disable a given user account based on the current time. My efforts thus
far have resulted in this:

if %time% geq 15:30 if %time% lss 10:00 net user username /active:yes
if %time% geq 10:00 if %time% lss 11:55 net user username /active:no
if %time% geq 11:55 if %time lss 12:35 net user username /active:yes
if %time% geq 12:35 if %time% lss 15:30 net user username /active:no

If the time is from 3:30 PM to before 10:00 AM, or from 11:55 AM to before
12:35 PM, the account should be enabled. If the time is from 9:55 AM to
before 11:55 AM, or from 12:35 PM to before 3:30 PM, the account should be
disabled. In conjunction with a few sheduled tasks, this batch file would
enable the given account to be unavailable to users except at the desired
times, without the restrictions of the '/times' option for the 'net users'
command.
The only problem, naturally, is that the batch file doesn't work. The second
line returns 'net was unexpected at this time', and the last line doesn't
seem to run at all. What am I doing incorrectly?

Sponsored Links
Register or log in to remove.

Archived from groups: microsoft.public.windowsxp.security_admin (More info?)

 

try
%username%

more info can be retrieved at command line:
net help user
help if

Better yet, use the "Logon Hours" option to restrict access if you are in an
AD environment (account properties > Account > Logon Hours).

Do let us know if this helps. Thanks!


"radar64" wrote:

> I am attempting to write a batch file (to be executed at startup) to enable
> or disable a given user account based on the current time. My efforts thus
> far have resulted in this:
>
> if %time% geq 15:30 if %time% lss 10:00 net user username /active:yes
> if %time% geq 10:00 if %time% lss 11:55 net user username /active:no
> if %time% geq 11:55 if %time lss 12:35 net user username /active:yes
> if %time% geq 12:35 if %time% lss 15:30 net user username /active:no
>
> If the time is from 3:30 PM to before 10:00 AM, or from 11:55 AM to before
> 12:35 PM, the account should be enabled. If the time is from 9:55 AM to
> before 11:55 AM, or from 12:35 PM to before 3:30 PM, the account should be
> disabled. In conjunction with a few sheduled tasks, this batch file would
> enable the given account to be unavailable to users except at the desired
> times, without the restrictions of the '/times' option for the 'net users'
> command.
> The only problem, naturally, is that the batch file doesn't work. The second
> line returns 'net was unexpected at this time', and the last line doesn't
> seem to run at all. What am I doing incorrectly?

Reply to Anonymous

Archived from groups: microsoft.public.windowsxp.security_admin (More info?)

 

I simply put 'username' as an example. I was not intending to put a variable
there... I think.
I am something of a novice at writing batch files with conditional
processing. Though I have used the help command for both if and net, the
voluminous information the documentation for the if command contains gives no
indication or what I must be doing wrong.
And, unfortunately, we do not have Active Directory.

Reply to Anonymous

Archived from groups: microsoft.public.windowsxp.security_admin (More info?)

 

radar64 wrote:

> I simply put 'username' as an example. I was not intending to put a variable
> there... I think.
> I am something of a novice at writing batch files with conditional
> processing. Though I have used the help command for both if and net, the
> voluminous information the documentation for the if command contains gives no
> indication or what I must be doing wrong.
> And, unfortunately, we do not have Active Directory.
Hi

You might want to post your question to the newsgroup
microsoft.public.win2000.cmdprompt.admin



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/s [...] fault.mspx

Reply to Anonymous
Tom's Hardware > Forum > Windows XP > Windows XP General Discussion > Need help with batch file...
Go to:

There are 1191 identified and unidentified users. To see the list of identified users, Click here.

Please mind

You are about to answer a thread that has been inactive for more than 6 months.
If you still wish to proceed, please ensure that your posting is original and does not duplicate or overlap any prior responses to this thread.

Add a reply Cancel
Sponsored links
  • Ask the community now
  • Publish
Ad
They won a badge
Join us in greeting them