in Education by
I am trying to understand why the first line of my batch file fails to execute. My code is as follows: if exist reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion" goto OptionOne exit :OptionOne some code goto:eof It never goes to the OptionOne subroutine. Instead, it just exits. I do have a solution to this problem written differently (so I don't want examples to make it work) but I want to understand why this one line fails to execute. Is the syntax improper? Google says it is correct. Poorly designed code? I know this registry key exists so this is not the case. Is it something with the return value and its correct syntax, but needs to be further written out on the else statements? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The code you have doesn't work because if exist is used only to check if folders or files exist. Its syntax is: if exist "C:\foldername\" (do something) else (optionally do something else) for folders and: if exist "C:\filename" (do something) else (optionally do something else) for files. My suggested solution (as mentioned in comments) is the following: reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion" >nul 2>&1 if %errorlevel% EQU 0 (goto :OptionOne) else (echo Registry key not found. & pause>nul & exit /b 1) :OptionOne some code goto :eof which checks if the command returned errorlevel different than equal to 1 or bigger (the registry key exists) or 1 or bigger (it doesn't exist).

Related questions

0 votes
    I am trying to understand why the first line of my batch file fails to execute. My code is as ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 8, 2022 in Education by JackTerrance
0 votes
    I am trying to understand why the first line of my batch file fails to execute. My code is as ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I am trying to understand why the first line of my batch file fails to execute. My code is as ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I have a task coming up where I have to manually enter an HKEY_USER key value and string value for ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    My script launches a MS Edge window and then tries to log into Netflix with my credentials. The problem ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    Suppose you have designed a Big Data batch using the MapReduce framework. Now you want to execute it on a cluster ... Run view? Name Node Data Node Resource Manager Job Tracker...
asked Mar 23, 2021 in Technology by JackTerrance
0 votes
    I've created a python3 script that runs fine on command line but when I try to run as a daemon ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I know when Cygwin installs there is a batch file that is used to launch it in Windows. But if I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I am trying to retrieve a particular file from multiple FTP servers. those server details are stored in ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I want to execute a certain batch file and redirect its console output to a text control in visual c ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I want to execute a certain batch file and redirect its console output to a text control in visual c ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I'm currently looking at ways to allow people to select multiple files at once to batch upload images. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I'm running a FOR loop to retrieve the (absolute) path name for ALL *.properties file in the root ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 13, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Saving path in String (4 answers) Closed 5 years ago. I'm ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 30, 2022 in Education by JackTerrance
...