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

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

User input in registry file

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
arunykand
Asked:
arunykand
  • 2
  • 2
1 Solution
 
oBdACommented:
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
 
arunykandAuthor Commented:
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
 
oBdACommented:
"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
 
arunykandAuthor Commented:
Excellent, thank you!
0

Featured Post

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!

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