Page 1 of 1

Capture registry value of variable number of words

Posted: 02 Mar 2022 12:26
by atfon
I would like to know how to capture a value from the registry as a variable when that value may be multiple words or not. Here is a quick example that would work if the value was one word:

Code: Select all

for /f "tokens=3*" %%a in ('%__APPDIR__%reg.exe query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "RegisteredOrganization"') do set "regOrg=%%a"
So, if the value was just "Company" this would return the proper value. If the value was "The Company" I know that I could use "regOrg=%%a %%b" instead. But, what if I don't know how many words are in that value?

I know how this can be done using the powershell Get-ItemProperty option, but I'm curious if this is possible in pure batch.

Thank you.

Re: Capture registry value of variable number of words

Posted: 02 Mar 2022 14:05
by aGerman
You want to get the rest (token *) after token 2, right? So, what about

Code: Select all

for /f "tokens=2*" %%a in ('...') do set "var=%%b"
Steffen

Re: Capture registry value of variable number of words

Posted: 02 Mar 2022 14:22
by atfon
aGerman wrote:
02 Mar 2022 14:05
You want to get the rest (token *) after token 2, right? So, what about

Code: Select all

for /f "tokens=2*" %%a in ('...') do set "var=%%b"
Steffen
Well, that was a silly mistake. I was thinking I had to grab the third token and later. That's exactly what I needed. Thanks again, Steffen.