Symantec Version Reg Query

0

I'd be really grateful for some assistance with this, as it's blowing my mind.

All I want to do is pull the Version Number of Symantec, using the below code, which works in part, all except the gathering of the last part of the string, which I know is correct as I have something similar working in other batch files.

Can anyone see where I have gone wrong?

--

@echo off 

@setlocal enabledelayedexpansion

set VersionReg = (
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Symantec\Symantec Endpoint Protection\currentversion\public-opstate" /v "DeployRunningVersion"
)

echo %VersionReg%

SET Version=%VersionReg:~134,14%

echo %version%

--

Many thanks in advance...

Toby MacDonnell

Posted 2016-11-03T15:22:29.620

Reputation: 43

1Is your version string really more than 134 characters long? – DavidPostill – 2016-11-03T17:01:45.257

1Run your batch file without the @echo off and [edit] to include the output ... – DavidPostill – 2016-11-03T17:02:44.470

Answers

1

Next .bat code snippet shows how-to grab reg query output to a variable using for /F loop. Mostly explained using rem comments.

@ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion

set "_regKey=HKLM\SOFTWARE\Symantec\Symantec Endpoint Protection\currentversion\public-opstate"
set "_regVal=DeployRunningVersion"

    rem my testing values in next 2 lines (remove them)
set "_regKey=HKCU\Control Panel\PowerCfg\PowerPolicies\3"  delete this 2 lines
set "_regVal=Description"                my testing values delete this 2 lines

for /F "tokens=1,2,*" %%G in ('
            reg query "%_regKey%" /v "%_regVal%" ^| findstr /I "%_regVal%"
    ') do (
            rem next 3 lines: debugging output could be removed
        echo value name "%%~G"
        echo value type "%%~H"
        echo value data "%%~I"
        set "_VersionReg=%%~I"
    )

SET "_Version=%_VersionReg:~12,26%"      delete this line and uncomment next one
rem SET "_Version=%_VersionReg:~134,14%"                      uncomment this line

    rem an empty line for output better readability 
echo(

    rem show result:   instead, you can use         ECHO "%_Version%" 
    rem or enable delayed expansion and use         ECHO  !_Version!
set _

Output:

==> D:\bat\SU\1142022.bat
value name "Description"
value type "REG_SZ"
value data "This scheme keeps the computer running so that it can be accessed from the netwo
rk.  Use this scheme if you do not have network wakeup hardware."

_regKey=HKCU\Control Panel\PowerCfg\PowerPolicies\3
_regVal=Description
_Version=keeps the computer running
_VersionReg=This scheme keeps the computer running so that it can be accessed from the netwo
rk.  Use this scheme if you do not have network wakeup hardware.

Resources (required reading, incomplete):

JosefZ

Posted 2016-11-03T15:22:29.620

Reputation: 9 121