Registry Query Batch

Author Message
john3j04

  • Total Posts : 7
  • Scores: 0
  • Reward points : 750
  • Joined: 7/11/2012
  • Status: offline
Registry Query Batch Wednesday, July 11, 2012 2:39 PM (permalink)
0
Hello,
I am new to the forum and  I was hoping that someone could help me figure this out.  I am not sure whether a for statement or an if/then/else statement should be used, but I am trying to write a batch file that I could reuse the code on when evaluating several areas of the registry through a batch file.  I would really only need one variable that was just set to something new each time it is come across in my batch file, but I was trying to take the value "MinimumPasswordAge" from "HKLM??\System\CurrentControlSet\Services\Netlogon\Parameters", assign it to a variable, and if the value was greater than or equal to 30, then it should echo Pass.  If it does not meet that criteria, then it should echo Fail and continue through the rest of the batch file.
 
I would appreciate any advice and help on this!
Thanks,
John
 
#1
    ndaniels

    • Total Posts : 132
    • Scores: 45
    • Reward points : 21680
    • Joined: 2/24/2006
    • Location: The Republic of Elbonia
    • Status: offline
    Re:Registry Query Batch Wednesday, July 11, 2012 3:39 PM (permalink)
    0
    The problem is not pulling the value out of the registry--you can do that with a FOR statement...
     
    for /f "tokens=3" %%a in ('reg query hklm\System\CurrentControlSet\Services\Netlogon\Parameters /v MinimumPasswordAge ^| find /i "MinimumPasswordAge"') do set MinimumPasswordAge=%%a
     
    The problem is, the value is stored as hex in the registry and the IF does a decimal based comparison.  I'm not sure how to determine if the value of %MinimumPasswordAge% is greater than or equal to 1E.  Sorry if that's not much help.
     
     
    #2
      john3j04

      • Total Posts : 7
      • Scores: 0
      • Reward points : 750
      • Joined: 7/11/2012
      • Status: offline
      Re:Registry Query Batch Thursday, July 12, 2012 3:43 PM (permalink)
      0
      I think I have it figured out because the IF statements allow me to test if the variable is less than or equal to hexadecimal.  I tried it several times without issue.  Now I ask, how would I write an if statement that says if a variable is less than or equal to 2 AND greater than or equal to 1?  Here is what I am trying to do, even though this syntax does not work...
       
      IF %testvalue% LEQ 2 AND %testvalue% GEQ 1 (ECHO Pass) Else (ECHO Fail)
       
      Any help would be greatly appreciated!
       
      #3
        ndaniels

        • Total Posts : 132
        • Scores: 45
        • Reward points : 21680
        • Joined: 2/24/2006
        • Location: The Republic of Elbonia
        • Status: offline
        Re:Registry Query Batch Friday, July 13, 2012 10:25 AM (permalink)
        0
        I don't believe that IF supports AND.  You may need to break it down...
         
        if %testvalue% leq 2 (goto eval2) else (goto fail)
        :eval2
        if %testvalue% geq 1 (goto pass) else (goto fail)
        :fail
        echo fail
        goto end
        :pass
        echo pass
        :end
         
        #4
          john3j04

          • Total Posts : 7
          • Scores: 0
          • Reward points : 750
          • Joined: 7/11/2012
          • Status: offline
          Re:Registry Query Batch Friday, July 13, 2012 11:01 AM (permalink)
          0
          Thank you for responding, but I just figured it out.  I basically have this where I am checking to see if a registry value is set to 1 or 2, but nothing else.
           
          for /f "tokens=3" %%a in ('reg query "HKLM\blah" /v RegValue" ^| find /i "RegValue"') do set leq2test=%%a
          If %leq2test% LEQ 2 (set test1="Pass") ELSE (set test1="Fail")
          ?for /f "tokens=3" %%b in ('reg query "HKLM\blah" /v RegValue" ^| find /i "RegValue"') do set geq1test=%%b
          If %geq1test% GEQ 1 (set test2="Pass") ELSE (set test2="Fail")
          If test1 == test2 (Echo Pass) ELSE (Echo Fail)
           
          It might not be the best way to do it, but it works!
          Now I just need to figure out how to check to see if the Lockout Threshold is not 0, but less that 3.  I know that I can view it with the net accounts command, but dont know how to use it for this case.
           
          Thanks!
           
          #5
            ndaniels

            • Total Posts : 132
            • Scores: 45
            • Reward points : 21680
            • Joined: 2/24/2006
            • Location: The Republic of Elbonia
            • Status: offline
            Re:Registry Query Batch Friday, July 13, 2012 12:23 PM (permalink)
            0
            Using variables as switches works too.  However, if "Fail"=="Fail", you'll still echo "Pass".  I realize that you can never have a scenario where X is not <= 2 and X is not >=1 but, if you use this logic with different test criteria, you may not receive the results you expect.  Also, since you are querying the registry twice for the same value, it may speed the batch file up a bit if you set a single variable for the lone registry value.  How about something like?...
             
            for /l %%a in (1,1,2) do set test%%a=fail
            for /f "tokens=3" %%a in ('reg query "hklm\blah" /v regvalue" ^| find /i "regvalue"') do set regvalue=%%a
            if %regvalue% leq 2 set test1=pass
            if %regvalue% geq 1 set test2=pass
            if /i "%test1%%test2%"=="passpass" (echo pass) else (echo fail)
             
            #6
              Online Bookmarks Sharing: Share/Bookmark

              Jump to:

              Current active users

              There are 0 members and 1 guests.

              Icon Legend and Permission

              • New Messages
              • No New Messages
              • Hot Topic w/ New Messages
              • Hot Topic w/o New Messages
              • Locked w/ New Messages
              • Locked w/o New Messages
              • Read Message
              • Post New Thread
              • Reply to message
              • Post New Poll
              • Submit Vote
              • Post reward post
              • Delete my own posts
              • Delete my own threads
              • Rate post

              2000-2013 ASPPlayground.NET Forum Version 3.9