If statements in batch file

more then one condition

Page 1 of 1

2 Replies - 2752 Views - Last Post: 21 November 2008 - 06:49 AM Rate Topic: -----

#1 Noldona  Icon User is offline

  • Addicted to DIC

Reputation: 5
  • View blog
  • Posts: 1,051
  • Joined: 02-July 02

If statements in batch file

Posted 14 November 2008 - 07:09 AM

So here is the deal. The computer I have here at work is a piece of junk. It doesn't like to reboot. When ever it is given the restart command, it will shutdown and attempt to reboot. It will get as far as the Windows logo on the screen before shutting off and one of the LEDs on the from starts blinking red. Now, if this happens, I have to unplug the power cable, hold the power button for like 10 seconds and then plug the power cable back in to get it to actually boot up. Since I know about this issue, it isn't to much trouble if I am the one rebooting it. However, there has been more then 1 morning when I have walked in and my computer is in this state because they have clearly rebooted my machine locally. This is also annoying as I will be in the middle of coding and have certain programs up and running at the time I leave work for the day.

Anyway, I have determined the best solution is to write a little batch script I can click to run right before I leave and let it run over night to abort any shutdown commands they may send it. However, I am having an issue with the looping part. I need the code to run from when I click (usually some time between 1430 and 1600) it till around 0700 the next day. My problem is, it doesn't seem to be looping. For testing purposes, I did try setting currentdate to yesterday and changed the time in the second if statement to 1 minute after system time since it is past 0700 here.

set currentdate=%DATE%
:loop
shutdown -a
if %DATE% == %currentdate% && %TIME% geq 14:00:00.00 (
   goto loop
) else (
   if not %DATE% == %currentdate% && %TIME% leq 07:00:00.00 (
	  goto loop
   )
)



Is This A Good Question/Topic? 0
  • +

Replies To: If statements in batch file

#2 brds  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 76
  • View blog
  • Posts: 515
  • Joined: 22-October 08

Re: If statements in batch file

Posted 14 November 2008 - 01:51 PM

Dear Noldona,

We don't like filthy && or || syntax, in our shell. You will nest your ifs thusly

@ECHO OFF
set currentdate=%DATE%
:loop
shutdown -a
if "%DATE%" == "%currentdate%" (
	if /i "%TIME%" geq "14:00:00.00" (
   		goto loop
	)
) else (
	if /i "%TIME%" leq "07:00:00.00" (
			  goto loop
   	)
)



Sincerely,
The Microsoft Corporation.

-----------------------------------------------------------------------------

:P

You need to supply a /i if you want to use GEQ and LEQ. The second check of %date% was redundant. You can ditch the @echo off if you want to see the/more garbage.

Speaking as a sys/network admin, please close all applications and logout before you go home. We do stuff in the off hours, so that we won't interfere with your working hours.

View PostNoldona, on 14 Nov, 2008 - 08:09 AM, said:

So here is the deal. The computer I have here at work is a piece of junk. It doesn't like to reboot. When ever it is given the restart command, it will shutdown and attempt to reboot. It will get as far as the Windows logo on the screen before shutting off and one of the LEDs on the from starts blinking red. Now, if this happens, I have to unplug the power cable, hold the power button for like 10 seconds and then plug the power cable back in to get it to actually boot up.

Feel free to yell at whomever is responsible for fixing your computer, sounds like it should have been reimaged/replaced some time ago.
Was This Post Helpful? 0
  • +
  • -

#3 Noldona  Icon User is offline

  • Addicted to DIC

Reputation: 5
  • View blog
  • Posts: 1,051
  • Joined: 02-July 02

Re: If statements in batch file

Posted 21 November 2008 - 06:49 AM

Thanks, I will give that a try.

The CSAs who are the ones who are suppose to "fix" the machine cause the problem when they reimaged it. And honestly, I probably know more about computers then some of them. It's just rights on the machine that is an issue. As for doing stuff in off hours, they should wait till a weekend. I actually have code changes and such I am working on throughout the week.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1