Replace Registry (REG_SZ) keys at first login with current OS name?

Posted on 2007-08-11
Last Modified: 2009-07-29

I need to have a script run (at first login) after a new OS is built that does the following:

1)  Delete the following two REG_SZ keys (located here):


Keys are:

'Browser' and

^^ These two keys contain a text value for the 'old' pre-image OS name

2)  I then need to re-add these keys with the 'new' current system (OS) name (guessing by passing in %COMPUTERNAME% somehow)?

If there is a way to replace the current value of these keys instead of deleting / re-adding that works as well.

Operating Systems this will be used on:

Windows 2003 Server Standard (32-bit and 64-bit)
Windows 2003 Server Enterprise (32-bit and 64-bit)

Thank you in advance!!
Question by:EEK2
    LVL 14

    Expert Comment

    :: *** delreg.cmd
    @echo off
    set w=echo.^>^>%temp%\delreg.tmp
    if exist %temp%\delreg.tmp del %temp%\delreg.tmp
    ::registry file creation
    %w% Windows Registry Editor Version 5.00
    %w% [HKEY_LOCAL_MACHINE\Software\VERITAS\NetBackup\CurrentVersion\Config]
    %w% "Browser"=-
    %w% "Client_Name"=-
    regedit /s %temp%\delreg.tmp
    ::end delreg.cmd

    :: *** setreg.cmd
    @echo off
    set w=echo.^>^>%temp%\setreg.tmp
    if exist %temp%\setreg.tmp del %temp%\setreg.tmp
    ::registry file creation
    %w% Windows Registry Editor Version 5.00
    %w% [HKEY_LOCAL_MACHINE\Software\VERITAS\NetBackup\CurrentVersion\Config]
    %w% "Browser"="%COMPUTERNAME%"
    %w% "Client_Name"="%COMPUTERNAME%"
    regedit  /s %temp%\setreg.tmp
    ::end setreg.cmd

    LVL 14

    Accepted Solution

    reg delete HKEY_LOCAL_MACHINE\Software\VERITAS\NetBackup\CurrentVersion\Config /v Browser /f
    reg delete HKEY_LOCAL_MACHINE\Software\VERITAS\NetBackup\CurrentVersion\Config /v Client_Name /f

    reg add HKEY_LOCAL_MACHINE\Software\VERITAS\NetBackup\CurrentVersion\Config /t REG_SZ /v Browser /d %computername% /f
    reg add HKEY_LOCAL_MACHINE\Software\VERITAS\NetBackup\CurrentVersion\Config /t REG_SZ /v Client_Name /d %computername% /f

    Author Comment

    Perfect solutions, Canali -- thank you very much.

    In terms of the two different options -- would you recommend one as being more resilient than another (i.e. more portable between W2K and W2K3) or is it a wash?

    I personally liked the last one because it seemed to achieve the result with less complexity...

    Thanks, again.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
    Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
    In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    733 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

    21 Experts available now in Live!

    Get 1:1 Help Now