Announcement

Collapse
No announcement yet.

Batchfile that reads registry key Value

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Batchfile that reads registry key Value

    hello guys .

    I did somme search, but didn't find good explanation (well, something that I would understand, because sometimes people gives code, but no explanation :P).

    I want to make a batchfile that will take a registry key value, and set it into a variable.
    example:

    Variable: outlooktemp

    Registry key: HKCU\software\microsoft\office\12.0\outlook\securi ty and the key Outlooksecuretempfolder

    I want to take the value of that key, which should be something like: C:\Documents and Settings\cbriere\Local Settings\Temporary Internet Files\Content.Outlook\5AI023XP\ (Folder 5AI023XP is not the same on other computer)

    Then after I can use a command like:
    cd %variable%
    del *.* /q


    Why I want to do that? because sometimes when you open alot of files that has the same name, you may encounter problem with outlook that gives the erreor: Cannot open file, verify the security on the folder (something like that).

    If anyone can help me, I would greatly appreciate.


    Thanks
    Last edited by ChristTheGreat; 8th July 2010, 20:37.

  • #2
    Re: Batchfile that reads registry key Value

    I think the command you need to use is reg. Run reg /? to see its usage. You'd then use for to get the appropriate data from the command's output. Have a crack at it and let us know if you get stuck.
    Gareth Howells

    BSc (Hons), MBCS, MCP, MCDST, ICCE

    Any advice is given in good faith and without warranty.

    Please give reputation points if somebody has helped you.

    "For by now I could have stretched out my hand and struck you and your people with a plague that would have wiped you off the Earth." (Exodus 9:15) - I could kill you with my thumb.

    "Everything that lives and moves will be food for you." (Genesis 9:3) - For every animal you don't eat, I'm going to eat three.

    Comment


    • #3
      Re: Batchfile that reads registry key Value

      Originally posted by gforceindustries View Post
      I think the command you need to use is reg. Run reg /? to see its usage. You'd then use for to get the appropriate data from the command's output. Have a crack at it and let us know if you get stuck.

      Thanks. I'll see what I can do with that. batchfile are way far in my head

      Comment


      • #4
        Re: Batchfile that reads registry key Value

        Reg.exe QUERY
        The command:
        Code:
        Reg.exe QUERY "HKCU\Software\Microsoft\Office\12.0\Outlook\Security" /v "OutlookSecureTempFolder"
        will return all:
        Code:
        ! REG.EXE VERSION 3.0
        
        HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Security
            OutlookSecureTempFolder	REG_SZ	C:\Documents and Settings\Rems\Local Settings\Temporary Internet Files\Content.Outlook\CWCNP4FA\
        Reg.exe QUERY & Findstr.exe
        The command,
        Code:
        Reg.exe QUERY "HKCU\Software\Microsoft\Office\12.0\Outlook\Security" /v "OutlookSecureTempFolder" |Findstr.exe /ri "\<OutlookSecureTempFolder\>"
        will return one line,
        Code:
            OutlookSecureTempFolder	REG_SZ	C:\Documents and Settings\Rems\Local Settings\Temporary Internet Files\Content.Outlook\CWCNP4FA\

        tokenize results from Reg.exe QUERY & Findstr.exe
        This command breaks the line in to parts at TABs (where delims=<TAB>)
        and then output only the third+ part(s) (tokens=3*)
        Code:
        For /f "tokens=3* delims=	" %%! in ('Reg.exe QUERY "HKCU\Software\Microsoft\Office\12.0\Outlook\Security" /v "OutlookSecureTempFolder" ^|Findstr.exe /ri "\<OutlookSecureTempFolder\>"') do echo %%!
        this will return just the value you are after,
        Code:
        C:\Documents and Settings\Rems\Local Settings\Temporary Internet Files\Content.Outlook\CWCNP4FA\

        Putting it in a subroutine for keeping the main part of the batch clear,
        Code:
        @echo off
        
        Call:OutlookTemp
        
        echo."%OutlookTemp%"
        
        pause
        
        
        Goto:EOF   - Subroutine -
        :OutlookTemp
        Set "OutlookTemp=" & setlocal & Set "$V="
        Set "RegKey=HKCU\Software\Microsoft\Office\12.0\Outlook\Security"
        Set "RegItem=OutlookSecureTempFolder"
        For /f "tokens=3* delims=	" %%! in (
           '2^>nul Reg.exe QUERY "%RegKey%" /v "%RegItem%" ^|(
           Findstr.exe /ri "\<%RegItem%\>"^)') Do Set "$V=%%!"
        endlocal & call Set "OutlookTemp=%$V%"
        exit /b %errorlevel%
        \Rems

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: Batchfile that reads registry key Value

          I clearly understand more, now. Hehe this is working perfectly.

          Thanks For help guys, This might help on other script aswell

          Comment

          Working...
          X