Jump to content

Update Registry Key On First Boot


Recommended Posts

I have a need to update a specific registry key with the current date on the first boot of the machine after it is imaged.

Additionally, one issue is that the slashes have to be reversed. For example, if the date is 08/16/2009, the registry key needs to be updated to 08\16\2009.

What I'm visualizing is this:

A bat file of some sort that is set to run once on the first boot.

The bat file would somehow query for the current date, then create a reg file replacing the "/"s with "\"s.

Then execute the merging of the created reg file by invoking REGEDIT.EXE /S importfile.REG

This is just what I'm envisioning. If there's a better way, I'm definitely open to suggestions.

If it matters, this is what the created reg file with the current date would need to look like:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\PGP-IGA]

[HKEY_LOCAL_MACHINE\SOFTWARE\PGP-IGA\PREP]
"INSTALLDATE"="08\16\2009"

Thanks in advance for any help, assistance or advice!

Link to comment
Share on other sites


You'll need to create the value string in your batch file first then.

Try either:

@ECHO OFF
FOR /F "TOKENS=2-4 DELIMS=/ " %%A IN ('DATE /T') DO (
REG ADD HKLM\SOFTWARE\PGA-IGA\PREP /V INSTALLDATE /D "%%A\%%B\%%C" /F>NUL)

Or:

@ECHO OFF
FOR /F "TOKENS=2-4 DELIMS=/ " %%A IN ("%DATE%") DO (
REG ADD HKLM\SOFTWARE\PGA-IGA\PREP /V INSTALLDATE /D "%%A\%%B\%%C" /F>NUL)

Link to comment
Share on other sites

Just to update in case anyone ever comes across the post while searching, I added the "del %0" command to the end to have the bat file self delete after running.

Works just as it should. Bat file runs, then deletes itself.

@ECHO OFF
FOR /F "TOKENS=2-4 DELIMS=/ " %%A IN ('DATE /T') DO (
REG ADD HKLM\SOFTWARE\PGA-IGA\PREP /V INSTALLDATE /D "%%A\%%B\%%C" /F>NUL)
del %0

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...