Solved

How to set registry value to batch parameter

Posted on 2007-11-13
7
875 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is a little timesaver I have been using for setting up Microsoft Small Business Server (SBS) in the simplest possible way. It may not be appropriate for every customer. However, when you get a situation where the person who owns the server is i…
The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
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…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now