Computing.Net > Forums > Programming > Date question for a batch

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Date question for a batch

Reply to Message Icon

Name: darthnubit
Date: August 5, 2008 at 07:50:08 Pacific
OS: XP Pro
CPU/Ram: Intel core 2 duo 3Ghz/2gb
Product: N/A
Comment:

I'm new to batch files and I hope what I'm asking is possible. What I need to do is this. I want to write a batch file for a scheduled task. I read everywhere about setting up a day of the week for a certain event to happen but but not for a longer period of time say 2 months. This is what I would like to happen. Starting from a certain date. Lets say today for example 08/05/2008. 2 months from now give the shutdown command every day after that. I already have a third party piece of software that will allow the shutdown command.



Sponsored Link
Ads by Google

Response Number 1
Name: darthnubit
Date: August 5, 2008 at 08:37:38 Pacific
Reply:

Let me rephrase. I would like to have a login script that runs everytime a user logs in. The shutdown command will be executed evertime after the user logins once the target date is reached.


0

Response Number 2
Name: tonysathre
Date: August 5, 2008 at 20:25:14 Pacific
Reply:

Sounds like a piece of nuisance-ware to me. You don't need a third party shutdown utility, as Windows has one built in; shutdown.exe.


0

Response Number 3
Name: darthnubit
Date: August 6, 2008 at 03:33:28 Pacific
Reply:

This is not nuisance-ware I assure you. I was tasked with this project at work. We have a lot of laptops that go in and out(other departments that we arent responsible for). We have no real way to make sure they come back. Until we can budget for Lojack or a better suited program I have to go with what I have. I'm aware that shutdown.exe is available. Due to a active directory environment im not sure if the users are equiped with the correct permissions to use it. As for why im using the shutdown command. I want to get the point accross that the computer needs to come back. a simple notepad popping up would do but honestly I know they would just close it and not bother reading it. With the shutdown command I can specify a delay and they cant cancel the action.


0

Response Number 4
Name: Mechanix2Go
Date: August 6, 2008 at 10:43:43 Pacific
Reply:

Seems much simpler to just expire the account.

But, to answer the question, try this:

::==========================
:: get ready for month after next

@echo off
setLocal EnableDelayedExpansion

call :YMD8
if not exist c:\tmonth call :targset
set /p expire=<c:\tmonth
if %expire% equ %month% echo this is month %month% and time to shut down
if %expire% neq %month% echo we're not there yet; this is only month %month%

goto :eof

:YMD8

::== YMD8.bat

>> d.d echo E 0100 B4 2A CD 21 B4 4C CD 21
>> d.d echo N DAY.COM
>> d.d echo RCX
>> d.d echo 8
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
>> d.d echo N MONTH.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
>> d.d echo N YEAR.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 D0 B4 4C CD 21
>> d.d echo N DAT.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo Q

debug < d.d > nul
del d.d

dat
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set dat=0%%a
for %%a in ( 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) do if errorlevel %%a set dat=%%a
echo Date %dat%

day
if errorlevel 0 set day=Sunday
if errorlevel 1 set day=Monday
if errorlevel 2 set day=Tuesday
if errorlevel 3 set day=Wednesday
if errorlevel 4 set day=Thursday
if errorlevel 5 set day=Friday
if errorlevel 6 set day=Saturday
echo Day %day%

month
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set month=0%%a
for %%a in ( 10 11 12) do if errorlevel %%a set month=%%a
echo Month %month%

year
if errorlevel 215 set Year=2007
if errorlevel 216 set Year=2008
if errorlevel 217 set Year=2009
if errorlevel 218 set Year=2010
echo Year %Year%

del day.com
del month.com
del year.com
del dat.com
::== DONE

goto :eof

:targset

if %month% equ 01 set target=03
if %month% equ 02 set target=04
if %month% equ 03 set target=05
if %month% equ 04 set target=06
if %month% equ 05 set target=07
if %month% equ 06 set target=08
if %month% equ 07 set target=09
if %month% equ 08 set target=10
if %month% equ 09 set target=11
if %month% equ 10 set target=12
if %month% equ 11 set target=01
if %month% equ 12 set target=02

> c:\tmonth echo %target%

goto :eof


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 5
Name: dtech10
Date: August 6, 2008 at 12:19:09 Pacific
Reply:

Hi Mechanix

I remember that code from somewhere.
LOL


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: August 6, 2008 at 12:42:23 Pacific
Reply:

Hi d10,

Yep, you're the one who showed use the debug COM file creation.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 7
Name: darthnubit
Date: August 6, 2008 at 14:38:11 Pacific
Reply:

Thanks you this helps a lot. It would be simpler to set the domain user account to expire you're right. However the users will be most likely using a cached domain login. I also didn't catch if they will need a local user account. So This was the simplest thing I could think of.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Date question for a batch

High Score system for a batch game www.computing.net/answers/programming/high-score-system-for-a-batch-game/19394.html

create a log for a batch file www.computing.net/answers/programming/create-a-log-for-a-batch-file/18410.html

How to make a batch file type text www.computing.net/answers/programming/how-to-make-a-batch-file-type-text-/11493.html