Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: [Bat]Find path in registry and copy files to this path.  (Read 11641 times)

0 Members and 1 Guest are viewing this topic.

Bzik

    Topic Starter


    Greenhorn

    • Experience: Beginner
    • OS: Other
    [Bat]Find path in registry and copy files to this path.
    « on: July 16, 2013, 11:36:57 AM »
    Hello,
     Need a batch script. The task is:   find in registry path to the program, copy files (with other extensions) from folder where i have batch file and paste copied files to folder from path .

    Possible ?
    I hope that was understood. Sorry for my english ;)

    Salmon Trout

    • Guest
    Re: [Bat]Find path in registry and copy files to this path.
    « Reply #1 on: July 16, 2013, 11:44:11 AM »
    What is the registry key?

    Bzik

      Topic Starter


      Greenhorn

      • Experience: Beginner
      • OS: Other
      Re: [Bat]Find path in registry and copy files to this path.
      « Reply #2 on: July 16, 2013, 11:53:59 AM »
      Thanks for reply. I'm not sure I understand the question correctly....(translator)

      Quote
      What is the registry key?
      In example :
      HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip

      Salmon Trout

      • Guest
      Re: [Bat]Find path in registry and copy files to this path.
      « Reply #3 on: July 16, 2013, 11:57:21 AM »
      On my machine it's

      HKEY_CURRENT_USER\Software\7-Zip


      Bzik

        Topic Starter


        Greenhorn

        • Experience: Beginner
        • OS: Other
        Re: [Bat]Find path in registry and copy files to this path.
        « Reply #4 on: July 16, 2013, 11:58:17 AM »
        Ok, in example can be. (on mine is in this two places )

        =====

        I try to do this on my own in that way :

        Quote
        for /f "tokens=3" %a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip" /v Path ^| find /i "REG_SZ"') do CD /D %a

        or

        Quote
        for /f "tokens=3" %a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip" /v Path ^| find /i "REG_SZ"') do set Path=%a

        but i dont know how to copy files, or how to refer to correct paths. I find something like that :

        Quote
        set OLDDIR=%CD%
        copy file.1 file.2
        chdir /d %OLDDIR% &rem restore current directory
        (cmd=%,batch=%%)
        But dont know how to, and I'm probably wrong ...:D
        « Last Edit: July 16, 2013, 12:38:22 PM by Bzik »

        Salmon Trout

        • Guest
        Re: [Bat]Find path in registry and copy files to this path.
        « Reply #5 on: July 16, 2013, 12:47:45 PM »
        1. Do not use Path as a variable name. This name is already used for a system variable and you will cause lots of problems!

        2. Why do you need to copy additional files into a program directory? This is bad security practice.

        Bzik

          Topic Starter


          Greenhorn

          • Experience: Beginner
          • OS: Other
          Re: [Bat]Find path in registry and copy files to this path.
          « Reply #6 on: July 16, 2013, 12:56:48 PM »
          1. Path in this command this is string value - REG_SZ > Path > C:\Program Files\7-Zip
          2. Program directory is only example.

          Salmon Trout

          • Guest
          Re: [Bat]Find path in registry and copy files to this path.
          « Reply #7 on: July 16, 2013, 01:04:25 PM »
          Quote
          for /f "tokens=3" %a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip" /v Path ^| find /i "REG_SZ"') do set Path=%a

          Your code uses Path as a variable name. Use something else e.g. Mypath

          Now %Mypath% contains a path

          copy some files into that folder

          copy *.txt "%Mypath%"

          « Last Edit: July 16, 2013, 01:14:54 PM by Salmon Trout »

          Bzik

            Topic Starter


            Greenhorn

            • Experience: Beginner
            • OS: Other
            Re: [Bat]Find path in registry and copy files to this path.
            « Reply #8 on: July 16, 2013, 01:14:19 PM »
            I cant use Mypath in this example, becouse name of string value is "Path" :D. In other cases it can be InstallPath or InstallLocation etc.
            Is not a problem ;) I check this in cmd with command: SET , and everything is fine with system "Path"

            7-Zip is only example, because there was a high probability that someone who try to help will have this program ;)

            Quote
            The task is:   find in registry path to the program, copy files (with other extensions) from folder where i have batch file and paste copied files to folder from path .

            Possible ?

            Possible ?

            Bzik

              Topic Starter


              Greenhorn

              • Experience: Beginner
              • OS: Other
              Re: [Bat]Find path in registry and copy files to this path.
              « Reply #9 on: July 16, 2013, 01:22:06 PM »
              Quote
              Your code uses Path as a variable name. Use something else e.g. Mypath

              Now %Mypath% contains a path

              copy some files into that folder

              copy *.txt "%Mypath%"

              Thats it  ! Working like a charm. Thank You very much ;)

              Salmon Trout

              • Guest
              Re: [Bat]Find path in registry and copy files to this path.
              « Reply #10 on: July 16, 2013, 01:23:31 PM »
              I cant use Mypath in this example, becouse name of string value is "Path" :D

              You can use anything you like. You are not understanding that Path is the name (in the registry) of the registry key. In your batch you can use any variable name you like to hold the string value of the registry key.

              Code: [Select]
              @echo off
              for /f "tokens=1-2*" %%A in ('reg query HKEY_CURRENT_USER\Software\7-Zip /v path ^| find "REG_SZ"') do set MyPath=%%C
              echo The path string value is "%MyPath%"


              If you did set Path=%%C you would find that all external commands would stop working in that command session.

              Bzik

                Topic Starter


                Greenhorn

                • Experience: Beginner
                • OS: Other
                Re: [Bat]Find path in registry and copy files to this path.
                « Reply #11 on: July 16, 2013, 01:26:44 PM »
                Yes, You right. Mypath is working.

                Thanks again.