Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
atfon
- Posts: 178
- Joined: 06 Oct 2017 07:33
#1
Post
by atfon » 02 Mar 2022 12:26
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.
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 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
-
atfon
- Posts: 178
- Joined: 06 Oct 2017 07:33
#3
Post
by atfon » 02 Mar 2022 14:22
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.