Solved

How to set registry value to batch parameter

Posted on 2007-11-13
7
878 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
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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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 6

Accepted Solution

by:
baev 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

This article covers how to install the Microsoft Windows Operating System (OS). What is covered in this article:  > Different Versions and Editions of the Windows OS  > Upgrading versus Fresh Installation of the OS           - Steps to take pr…
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…
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…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

773 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