Computing.Net > Forums > Programming > Setting variables from a txt file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Setting variables from a txt file

Reply to Message Icon

Name: Archo
Date: August 9, 2007 at 07:53:29 Pacific
OS: Windows XP / DOS
CPU/Ram: Xeon/1GB
Product: Dell
Comment:

Here's an overview of what I'm trying to do: We have a number of employees that are running Office XP, Office 2003, Office 2007, plus Visio and Project, and they some are different versions. I am trying to make a batch file script will pull the encoded serial number and the product name from the registry.

Well, Office stores all the keys with somewhat random names. I have the following line of code that will find the names of these random keys.

FOR /F "tokens=6* delims=\" %%A IN ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Registration"') DO @echo %%B >> c:\test.txt

That will export all the folder names to the test.txt file. Now I need to be able to set each folder as a seperate variable so I can run this code to find the product name:

FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Registration\{%RegKey1%" /v ProductName') DO SET Name1=%%B

All I need to do is find a way to set the lines in the text.txt file to a variable.



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: August 9, 2007 at 13:18:13 Pacific
Reply:

@Echo Off> C:\test.txt
SetLocal EnableDelayedExpansion

For /F "tokens=6* delims=\" %%A in ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Registration"') Do (
Echo %%B>> C:\test.txt)

Set Counter=1
For /F "tokens=* delims=" %%Z in (C:\test.txt) Do (
Set RegKey!Counter!=%%Z
Call :PRODNAME
Set /A Counter+=1
)
GoTo :DONE

:PRODNAME
For /F "tokens=2* delims= " %%A in ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Registration\{!RegKey%Counter%!" /v ProductName') Do (
Set Name!Counter!=%%B)
GoTo :EOF

:DONE



0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Setting variables from a txt file

Creating a variable from a txt file www.computing.net/answers/programming/creating-a-variable-from-a-txt-file/16486.html

Ping list of computers from a txt file www.computing.net/answers/programming/ping-list-of-computers-from-a-txt-file/19843.html

%var% from a txt file vbs www.computing.net/answers/programming/var-from-a-txt-file-vbs-/14365.html