Solved

User input in registry file

Posted on 2011-03-05
4
660 Views
Last Modified: 2012-06-27
Hi,
    I have a registry file (.reg) that needs to take an input from the user and use it internally in the file before making mods to the registry..Please see below

[HKEY_LOCAL_MACHINE\SOFTWARE\MyCorporation\MySoftware]
"Port"="COM5"

Open in new window


I want the "COM5" to come from user-input instead of hard-coding it, or having the user edit the registry file.  

Any help is appreciated!

Thanks
0
Comment
Question by:arunykand
[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
  • 2
  • 2
4 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 35043695
Use a batch file instead of a registry file, for example like this:
@echo off
set /p Port=Please enter the port number: COM
if "%Port%"=="" goto :eof
reg.exe add "HKEY_LOCAL_MACHINE\SOFTWARE\MyCorporation\MySoftware" /v "Port" /t REG_SZ /d "COM%Port%"

Open in new window

That could of course be as well changed to a menu, and/or restricted to certain values.
0
 

Author Comment

by:arunykand
ID: 35043775
Ok, so you're saying put everything into a batch file and let the reg.exe add take care of it?

I was also using the .reg file to add other items & remove items, how would I implement that into the batch file along with what you have given me?

Ex:

//Modify reg value
;[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters]
;"maximumpasswordage"=dword:00000078

//Delete reg Value

;[HKEY_USERS\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce]
;"OSK.exe"=-

Thanks

0
 
LVL 85

Accepted Solution

by:
oBdA earned 500 total points
ID: 35043794
"reg.exe /?", "reg.exe add /?" and reg.exe delete /?" will give you the necessary explanations to expand the script. In the cases above:
@echo off
set /p Port=Please enter the port number: COM
if "%Port%"=="" goto :eof
reg.exe add "HKEY_LOCAL_MACHINE\SOFTWARE\MyCorporation\MySoftware" /v "Port" /t REG_SZ /d "COM%Port%" /f
reg.exe add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters" /v "maximumpasswordage" /t REG_DWORD /d "78" /f
reg delete "HKEY_USERS\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v "OSK.exe" /f

Open in new window


And in first the script above I forgot to add a "/f" at the end of the reg command to avoid asking for confirmation, sorry.
0
 

Author Comment

by:arunykand
ID: 35043806
Excellent, thank you!
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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