Solved

How to set registry value to batch parameter

Posted on 2007-11-13
7
881 Views
Last Modified: 2008-02-01
I need to read the registry key and retrieve the last 7 characters of that string.  

How do I set a batch file variable to equal the registry key value and then retrieve the last 7 characters of that string?
0
Comment
Question by:doyle007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 29

Expert Comment

by:matrixnz
ID: 20276884
Does it have to be batch?
0
 
LVL 29

Expert Comment

by:matrixnz
ID: 20277074
The reason I asked if you required batch is, you could use something like AutoIT to grab this quite easily.  You could also call the executable from the batch with the information for example.

Download and Install AutoIT - http://www.autoitscript.com/autoit3/

Copy the following into Notepad

#NoTrayIcon
if ProcessExists("cmd.exe") Then
      WinActivate("Command Prompt")
Else
      Exit
EndIf
$AutoIT = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIT v3\AutoIT", "InstallDir")
$InstallDir = StringRight($AutoIT, 7)
Send($InstallDir)

Save the file as something.au3 then right click something.au3 and select compile script this will create an executable in the same directory as the script called something.exe.  If you double click the file and cmd isn't opened then nothing will happen however if you open cmd and call it your should see AutoIT3 being sent to the window.

Hope that helps.

Cheers
0
 

Author Comment

by:doyle007
ID: 20277390
The reason I need it in batch is because I need to write this value out (or part of it) into a text file, based on what the value is, i.e. IF statement based on the value. Unless there is a way to pass this string back to the batch file and store it into a variable, I don't think this will work.
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 29

Expert Comment

by:matrixnz
ID: 20279168
Hi Doyle

You can call the file from the script, or you could write the entire script with AutoIT.

Cheers
0
 
LVL 7

Accepted Solution

by:
Dmitrii earned 400 total points
ID: 20280030
For command line:

SET _my_registry_path=HKLM\Software\Microsoft\DirectX
SET _my_registry_par=Version
SET _my_command='REG QUERY %_my_registry_path% /v %_my_registry_par%'
FOR /F "tokens=*" %G IN (%_my_command%) DO SET _my_res=%G
SET _last_seven=%_par:~-7%
ECHO %_last_seven%
0
 
LVL 9

Expert Comment

by:MSE-dwells
ID: 20280483
baev's solution will probably work out for you or if you'd prefer to do it with only built-in tools, ten provide a little more detail as to what the reg. key is you're trying to read (if it's binary, for example, this may not be doable period in batch.)
0
 

Author Comment

by:doyle007
ID: 20284944
Baev's solution is perfect. Thanks
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had a hard drive that you can't boot into, but need to change the registry? Here is the solution! This article guides you through accessing and editing a registry of a non-primary drive. To read registry information on a non-prim…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question