Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

User input in registry file

Posted on 2011-03-05
4
Medium Priority
?
664 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 2000 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

Plug and play, no additional software required!

The ATEN UE3310 USB3.1 Gen1 Extender Cable allows users to extend the distance between the computer and USB devices up to 10 m (33 ft). The UE3310 is a high-quality, cost-effective solution for professional environments such as hospitals, factories and business facilities.

Question has a verified solution.

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

This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
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). …
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

721 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