We help IT Professionals succeed at work.

Multiple Task Batch File to Read/Write to Registry

FirstBorn
FirstBorn asked
on
Medium Priority
2,556 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.
Comment
Watch Question

Lee W, MVPTechnology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013

Commented:
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...

Author

Commented:
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
Lee W, MVPTechnology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013

Commented:
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.

Author

Commented:
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
Lee W, MVPTechnology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013

Commented:
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.

Author

Commented:
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
Lee W, MVPTechnology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013

Commented:
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.
Technology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Top Expert 2007
Commented:
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

Author

Commented:
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
Top Expert 2007

Commented:
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

Author

Commented:
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
Top Expert 2007

Commented:
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

Author

Commented:
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
Top Expert 2007

Commented:
That I don't know.

Author

Commented:
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
Top Expert 2007

Commented:
Thanks :)

Let us know what you find out regarding OS compatibility.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.