title: Get Registry Value into a variable in a batch file and use it in an if case
body: <p>I would like to get a Registry Value (in my case true or false) and depending on the state (true or false) I would like to execute some commands.</p>
  
  <p>I have found a few answers that might be working, but i was unable to get them to work (I'm not experienced with batch files at all)</p>
  
  <p>Now to the more case specific question. I am changing a registry value depending on if my PC is in Sleep or Active. I now want to read the registry value and if the value is true (which means the PC is active) I want the script to do nothing, but if the value is false (which means the PC is in Sleep) I want to execute a few commands that will wake the PC from Sleep, wait 30 minutes and put the PC back to sleep.</p>
  
  <p>I really would appreciate examples if I'm not asking for too much.</p>
  
  <p>In my case I change the value with the following commands:</p>
  
  <pre><code>reg add HKCU\Software\Current_State /t REG_SZ /v Status_Active /d true /f
  </code></pre>
  
  <p>or</p>
  
  <pre><code>reg add HKCU\Software\Current_State /t REG_SZ /v Status_Active /d false /f
  </code></pre>
  
  <p>My idea was to check the value inside an if case and do actions depending on the value, but I have no idea how I should do that.</p>
  
  <p>Additional info from the command section to better express what I'm looking for:</p>
  
  <p>Yeah that's right, my PC is already waking itself from sleep at 1am and goes back into sleep 30 minutes later (or whatever i use in the script, its 1800 seconds atm). I am also changing a registry entry from true to false depending one the state I'm in, "true" if I am using it and "false" if the PC is already in sleep. I now only need to check which value the registry entry has and depending on that use a few commands(if the value is false) or not (if the value is true)</p>
  
  <p>And here is a picture where the registry entry is located if that helps: <a href="http://i.imgur.com/tHTbgOy.png" rel="nofollow">http://i.imgur.com/tHTbgOy.png</a> it is the "Status_Active" one which changes from true to false and  vice versa</p>
  
  <p>My solution (quote from the comment section):</p>
  
  <p>I have found a workaround to that, I'm now using a one liner after the reg query command: </p>
  
  <pre><code>if %errorlevel% equ 0 
     (echo PC is Active &amp; Echo Aborting Operations) 
  else 
     (echo PC was Sleeping &amp; echo Continue Operation &amp; timeout /t 3600 /nobreak &amp; rundll32.exe powrprof.dll,SetSuspendState 0,1,0)
  </code></pre>