Windows – Updating Specific Elements in the Computer Description

email me

This is a script I created to run in SCCM during a Windows 7 to Windows 10 upgrade. In this scenario, WIN7 was a part of the computer description on the local machine. I wanted to update only the part that said WIN7—as there was other text in the description I wanted to keep.

To do this, I used a simple batch file with reg query to get the current key info. Then I scanned it as a string. If WIN7 existed, replace it with WIN10. Once it was replaced in that string, I used reg add to just import the updated OS into the computer description (easy). I added some extra output, just to make sure everything was working. This eventually was compiled into an EXE and added to a SCCM task sequence.

The reason I like using batch scripting sometimes?

Run time: 2 seconds
Memory used: 680 KB
Compiled file size: 158 KB

 

Script

@echo off
title Update Computer description
setlocal enabledelayedexpansion

cls

:: original description ABC WIN7 BITLOCKER 10-26-17
:: new description ABC WIN10 BITLOCKER 10-26-17

set rKey1=
set rKey2=
set RegData=
set RegPath=
set RegValue=
set model=
set bValue=FALSE

 
:: REG PATH TO SCAN
set RegPath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters
set RegValue=srvcomment

:: returns model
call :pcmodel

:: CHECK REG FOR W7
call :scan
call :rKey1
set bValue=FALSE

:: SCAN AND UPDATE OS IN STRING
SET _tmp=%RegData%
SET _newData=%_tmp:WIN7=WIN10%
::SET _newData=%_tmp:WIN7=WIN10% %model%

:: APPLY REG UPDATE
Echo Update Reg Key…
reg add “%RegPath%” /v “%RegValue%” /t REG_SZ /d “%_newData%” /f /reg:64
echo.

:: CHECK REG FOR W10
call :scan
call :rKey2
set bValue=FALSE

:: CLEAR SESSION
set rKey1=
set rKey2=
set RegData=
set bValue=
set RegPath=
pause

exit

:: ————————————

:rKey1
echo %RegData% | FIND “WIN7” && set bValue=FOUND_WIN7
if %bValue%==FALSE exit
echo.
goto :EOF

:rKey2
echo %RegData% | FIND “WIN10” && set bValue=FOUND_WIN10
echo %bValue%
echo.
goto :done
:scan
FOR /F “tokens=2*” %%a IN (‘REG.EXE QUERY “%RegPath%” /V “%RegValue%”‘) DO SET RegData=%%b
goto :EOF

:pcmodel
:: a little something extra I’ve thrown in
FOR /F “tokens=2 delims==” %%m IN (‘WMIC csproduct GET Name /VALUE ^| FIND /I “Name=”‘) do set model=%%m
goto :EOF

:done
exit /b 0