How to change Windows Variable records

1

It is a fact that by programming for Windows, it is possible to store local variables, or in the environment, which in case they are saved in the windows registry.

How do I change windows registry variables using the command line, if I want to manually clean them to test my application without these already defined variables?

>     
asked by anonymous 10.02.2014 / 13:50

3 answers

2

It is possible to use the native application for windows called reg.exe via the command line. Reg.exe official documentation .

Examples of use:

Consulting:

REG QUERY HKLM\Software\Microsoft\ResKit /v Version
// Mostra o valor do registro Version

REG QUERY HKLM\Software\Microsoft\ResKit\Nt\Setup /s
// Mostra todas sub-chaves do valor abaixo do registro Setup

Adding

REG ADD \ABC\HKLM\Software\MyCo
// Adiciona uma chave HKLM\Software\MyCo na máquina remota ABC

Deleting

REG DELETE HKLM\Software\MyCo\MyApp\Timeout
// Apaga o registro Timeout e todas suas sub-chaves e valores

REG DELETE \ZODIAC\HKLM\Software\MyCo /v MTU
// Apaga o valor de registro do MTU em MyCo na máquina ZODIAC
    
10.02.2014 / 14:06
2

You can:

  • Use regedit.exe to make changes
  • If you want to access via code, you can use Windows API for this feature ;
  • Alternatively, export the desired excerpt from the Windows registry to a file, edit it , and apply it using regedit.exe /s [NomeArquivoComChavesDoRegistroEditadas].reg ;
  • Complement:

    Looking at your comment, I think the third alternative is the most recommended in this case. You can do the following:

  • Open regedit.exe by navigating to the registry key you want to "clean";
  • Export the desired registry key to a file;
  • Edit the file in notepad, excluding the lines of values below the key. Also, include a "-" (minus sign) before the key name. This will indicate that when applying the registry, the key should be deleted. It will look like this:

      

    Windows Registry Editor Version 5.00

         

    [- HKEY_LOCAL_MACHINE \ SOFTWARE \ MyCompany \ MyProduct]

         

    "Parameters1"="Value1"

         

    "Parameter2"="Value2"

  • Apply the record (double-click on the file you edited) whenever you want to delete the referenced key.

  • 10.02.2014 / 13:59
    0

    You can mount a .reg file too, and run it. For example:

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\SeuREG\CHAVE]
    "valor1"="conteudoValor1"
    "valor2"="conteudoValor2"
    

    Save this file teste.reg and just run it.

        
    10.02.2014 / 14:16