Solved

Multiple Task Batch File to Read/Write to Registry

Posted on 2006-10-30
17
2,510 Views
Last Modified: 2012-06-27
Hi,

Thanks for reading and for Your help.

I'm looking to create a batch file that has a few purposes:
1.  To read the Current DST (Daylight Saving Time) setting in the Registry,
2.  To Change it to the NEW Changes with the Federal Law just implemented recently,
3.  View the Changed date from #2 above.

There is a schedule listed on the right hand side here:
http://www.infoplease.com/spot/daylight1.html

If You notice, there is a pattern to the dates...
I would like to make sure that #2 above works with the pattern of the dates automatically.

Also, here is an article that shows where in the registry to edit:
http://en.wikipedia.org/wiki/Daylight_saving_time#Microsoft_Windows

I know how to go into the registry and edit things (regedit,) but this is something that I'd like to be able to do
in order to just run the batch file to "Set It and Forget It."

Again, Thank You for Your help!

Respectfully,

FirstBorn

PS.  This is kind of URGENT.
0
Comment
Question by:FirstBorn
  • 7
  • 5
  • 5
17 Comments
 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
So what makes you think Microsoft isn't going to issue a patch that covers this change making this whole question somewhat on the pointless side...?  There's 4+ months to go before it happens...
0
 
LVL 1

Author Comment

by:FirstBorn
Comment Utility
Hi leew,

Thanks for the Question.

Because Not ALL people want to use a patch right away...
That's ONE Reason...
Second, some people won't know HOW to patch it and if
they're ASKed to, they will just want the date changed and wait to patch it...

So, on with the Q...

Are You willing to Help?

Thanks.

FirstBorn
0
 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
I just think it's silly to reinvent the wheel - which is what I expect you're doing.  And potentially problematic (more on that later).

Only a fool would install a patch on important systems or to a large network without testing the patch first.

To answer your question (which I really think will cause you more problems in the long run), export the key to a file, then use:
regedit.exe /s myfile.reg

Why will this cause you problems?  Because if you "Set It and Forget It", then what happens for those users who DO patch right away?  How are you going to tell... this is why companies set standards and patch all systems to the same level, not leaving it up to the end user.  And what happens when you set it and the patch sets it and now you're 2 hours ahead instead of one?  If there's no patch, then fine... but I find it difficult to believe microsoft will ignore this issue on 50 million computers, give or take.
0
 
LVL 1

Author Comment

by:FirstBorn
Comment Utility
Hi leew,

Thanks for Your comment.

Believe it or not, I know some people STILL using Win '98, and some people that JUST installed Win XP.
I would assume that these people are a part of Your "50 Million" Theory?
These people RARELY Update their PCs, Even if You talk to them 'til You're Blue in the Face to get it done...

In regards to the "2 hours ahead" suggestion, How do You propose M$ will update the registry?
(ex. The Patch to correct the DST...)
1.  +/- 1 on the actual date/time, OR
2.  Set the CORRECT Date/Time whereby, it will automatically overwrite the settings in the registry
NO MATTER if the user had already made the change manually?
(hence, not making the PC Date/Time change if it has already been changed because the Date/Time will
have ALREADY been corrected.)

I would think that the Most LOGICAL thing to do would be #2, but, yes, We ARE Talking about Microsoft here...

Either way, IF it was #1, then I can provide an alternative to re-adjust, such as, instructions on how to change the
time Manually... voi-la! it'll be fixed.

So... What would the code in the Batch File actually contain?

Thanks.

FirstBorn
0
 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
It would be helpful if you posted ALL the details first.  For example, WHAT ARE YOU TALKING ABOUT?  A business?  A home user?  Are you planning on doing this for clients or the company you work for... Do you want the best answer to ensure the time is updated appropriately on all platforms or do you want us to give you something that doesn't work everywhere because you didn't provide details?

Problem is, Windows 9x technologies are not as robust as NT/2000/XP - the batch file you use for NT/2000/XP is not likely going to be compatible with 9x.

I expect Microsoft will release an update to change the DaylightStart and StandardStart values to different values, using a small update available through Windows update.

As for my 50 million theory - there are over 300 million people in the United States.  Then how many computers are used in offices?  What do YOU think the number is?  

Now for an NT/2000/XP system, I GAVE you the answer you wanted:
export the key to a file, then use:
regedit.exe /s myfile.reg

It's a ONE LINE batch file.
0
 
LVL 1

Author Comment

by:FirstBorn
Comment Utility
Hi leew,

Thanks for the additional comments.

k... This will be for clients, not on a Huge Biz Network... Geared more for the Home User.
I'm looking for compatability for Win '95 up to Win XP...

Re: Your 50 Million Theory,
The answer really doesn't matter at this point.
I'm not looking to adjust MILLIONS of PCs...

Re:  regedit.exe /s myfile.reg
Thanks.

FirstBorn
0
 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
I'll also throw in there, that from what I've seen in my home user clients, they don't care much about the time... at least in half the computers I see, they are off by several minutes - or more and/or are not set to the correct time zone... so again, I think your reinventing the wheel.
0
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 250 total points
Comment Utility
FYI (and anyone else happening across this page:

Preparing for Daylight Saving Time changes in 2007
http://www.microsoft.com/windows/timezone/dst2007.mspx

How to configure daylight saving time for the United States in 2007
http://support.microsoft.com/?kbid=914387

0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 30

Assisted Solution

by:SteveGTR
SteveGTR earned 250 total points
Comment Utility
Looks to me that DST is changing to the 2nd week in March and the 1st week in November. This registry file should do the trick:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]
"StandardStart"=hex:00,00,0b,00,01,00,02,00,00,00,00,00,00,00,00,00
"DaylightStart"=hex:00,00,03,00,02,00,02,00,00,00,00,00,00,00,00,00

Good Luck,
Steve
0
 
LVL 1

Author Comment

by:FirstBorn
Comment Utility
Hi leew,

Those Articles were what I needed (Almost...)

Thanks!

FirstBorn

Hi Steve,

That is Part II of Exactly what I needed to complete leew's answer.

That's Why YOU'RE #1 on the top 15 list!

(even though I needed a way to check the setting without doing 'regedit,'
that's no problem.)

The Both Of You's get an 'A'...

FirstBorn
0
 
LVL 30

Expert Comment

by:SteveGTR
Comment Utility
Sorry about the ommission. Try this out:

@echo off

setlocal

set daylightStart=
set standardStart=

for /f "tokens=1,2*" %%a in ('reg query HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation 2^>NUL') do call :PROCESS "%%a" "%%c"

if "%daylightStart%"=="" echo Could not find timezone information&goto :EOF

echo StandardStart = %standardStart%
echo DaylightStart = %daylightStart%

goto :EOF

:PROCESS

if "%~1"=="StandardStart" set standardStart=%~2
if "%~1"=="DaylightStart" set daylightStart=%~2
0
 
LVL 1

Author Comment

by:FirstBorn
Comment Utility
Wow!
Thanks, Steve!

Would You be willing to show the code to do the actual change
in the registry with Your Hex Code in Your Response Above?
(shown here)
***********
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]
"StandardStart"=hex:00,00,0b,00,01,00,02,00,00,00,00,00,00,00,00,00
"DaylightStart"=hex:00,00,03,00,02,00,02,00,00,00,00,00,00,00,00,00
***********
Thanks.

Firstborn
0
 
LVL 30

Expert Comment

by:SteveGTR
Comment Utility
Create a file named timezone.reg that looks like this:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]
"StandardStart"=hex:00,00,0b,00,01,00,02,00,00,00,00,00,00,00,00,00
"DaylightStart"=hex:00,00,03,00,02,00,02,00,00,00,00,00,00,00,00,00

Two things to watch out for; first you must include the "Windows Registry Editor..." line. Also, you should make sure to add a carriage return to the last line. In this case its the DaylightStart entry.

This batch file does the import. You might want to backup your registry before running the process. I've tested it out on another registry key that I made up and it appears to work.

@echo off

reg import timezone.reg
0
 
LVL 1

Author Comment

by:FirstBorn
Comment Utility
Thanks, Steve!

I REALLY Appreciate it!

One More Q, if You don't mind:
What Operating Systems will this work on?
Is it across the board as in:
Win:   '95, '98, ME, 2k, XP?

Thanks.

FirstBorn
0
 
LVL 30

Expert Comment

by:SteveGTR
Comment Utility
That I don't know.
0
 
LVL 1

Author Comment

by:FirstBorn
Comment Utility
Thanks, Steve.

No problem... I've got a few 'boxes' around the house that I can test with.

You've been EXTREMELY Helpful!
... It explains another reason why You're #1 on the Top 15 in this section.

:)

FirstBorn
0
 
LVL 30

Expert Comment

by:SteveGTR
Comment Utility
Thanks :)

Let us know what you find out regarding OS compatibility.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now