Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 885
  • Last Modified:

How to set registry value to batch parameter

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
doyle007
Asked:
doyle007
1 Solution
 
matrixnzCommented:
Does it have to be batch?
0
 
matrixnzCommented:
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
 
doyle007Author Commented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
matrixnzCommented:
Hi Doyle

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

Cheers
0
 
DmitriiconsultantCommented:
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
 
MSE-dwellsCommented:
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
 
doyle007Author Commented:
Baev's solution is perfect. Thanks
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now