Checking if a value name for a key is present on the windows registry through batch file

0

I need help for verifying if the value for a key exist or not.

I don't know how to check if my specified value name exist or not in my specified Key path.
I have this:

reg add "HKLM\SOFTWARE\....." /v "ARCHIVELOGENABLE" /d "Y"    

So, how to check if ARCHIVELOGENABLE is one of the value names in my Key path?

I have something like this:

@echo off
reg query myKEY > nul

if %ERRORLEVEL% EQU 1 echo (
  goto INSTALL
) else (
    if (my value name not exist) (
      goto INSTALL
    ) else (
      goto SKIP_INSTALL
    )
)

--my value name not exist, what should I write here?

Lia

Posted 2018-08-27T08:25:16.640

Reputation: 3

Welcome to Super User!You have provided the work you have done before, which is useful; what problem are you running into specifically? – bertieb – 2018-08-27T10:33:27.773

I think I do not understand your question, sorry. – Lia – 2018-08-27T10:44:10.447

I have to register a specified key path with a specified Key value name. I have 3 cases:

  1. if the key path does not exist, I should register the Key ad the value
  2. if the key path dose exist, but my specified value name does not exist, I should register
  3. if the key path does exist and the key value name exist and is different from my specified value, I should not registered
  4. < – Lia – 2018-08-27T10:46:58.093

I think I need a for iteration for all the values from my Key, but, at this time I am totally confused – Lia – 2018-08-27T10:49:38.587

It is a plausible case that an user want to edit or delete the value name? and the installer should not overwrite it (in edit case) – Lia – 2018-08-27T10:54:15.437

Apologies for not being clear before. Where you have said "I need help", with what do you need help? For example, do you have error messages? Unexpected behaviour of your script? – bertieb – 2018-08-27T10:56:33.747

I don't know how to check if my specified value name exist or not in my specified Key path – Lia – 2018-08-27T11:05:17.500

I have this: reg add "HKLM\SOFTWARE....." /v "ARCHIVELOGENABLE" /d "Y" – Lia – 2018-08-27T11:06:03.673

so, how to check if ARCHIVELOGENABLE is one of the value names in my Key path? – Lia – 2018-08-27T11:07:07.890

Please edit your question and update it with the details we have discussed.

– bertieb – 2018-08-27T11:46:28.097

reg query "HKLM\SOFTWARE....." /v "ARCHIVELOGENABLE". If it doesn't exist %ERRORLEVEL% = 1 – Hardoman – 2018-08-27T11:56:23.067

Answers

0

There are some issues in your code and IF clause.

Example. Let's check ForceActiveDesktopOn value in key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer

@echo off
reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer /v ForceActiveDesktopOn > nul

if %ERRORLEVEL% EQU 1 (
echo Key not found 
goto INSTALL) else (
echo Key is found, skipping
goto SKIP_INSTALL
)

:INSTALL

:SKIP_INSTALL

You need also to insert your key name and value in reg query line

Hardoman

Posted 2018-08-27T08:25:16.640

Reputation: 751