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

Author Topic: .INI with .BAT  (Read 13698 times)

0 Members and 1 Guest are viewing this topic.

HypercamJ

    Topic Starter


    Beginner

  • Oops =0
    .INI with .BAT
    « on: June 17, 2008, 09:12:16 AM »
    Is there a way to import settings from an .ini file to use in a batch file? I looked it up on Google but I didn't see anything I was looking for.
    ╔░░░░░░░░╗
    _Hypercam⌡_
    ╚░░░░░░░░╝

    Carbon Dudeoxide

    • Global Moderator

    • Mastermind
    • Thanked: 169
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Experience: Guru
    • OS: Mac OS
    Re: .INI with .BAT
    « Reply #1 on: June 17, 2008, 09:19:39 AM »
    Import settings to a batch file? What do you mean?

    Do you have anything you can show us now? (or at least a step by step of what you are planning to do)

    HypercamJ

      Topic Starter


      Beginner

    • Oops =0
      Re: .INI with .BAT
      « Reply #2 on: June 17, 2008, 09:22:25 AM »
      Since some .exe programs I've seen come with .ini files to load settings I was wondering if you could do the same with .bat files. Example: This uses an .ini file to change load settings when it is executed.
      ╔░░░░░░░░╗
      _Hypercam⌡_
      ╚░░░░░░░░╝

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: .INI with .BAT
      « Reply #3 on: June 17, 2008, 12:23:16 PM »
      Quote
      This uses an .ini file to change load settings when it is executed

      Couldn't figure out where an ini file came into play with this web page. Could you show us some data from your ini file? Most ini files contain equivalent values for  keywords. By getting creative with the set command, you might be able to set variables to be used by your batch file.

      Let us know. 8)
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      HypercamJ

        Topic Starter


        Beginner

      • Oops =0
        Re: .INI with .BAT
        « Reply #4 on: June 17, 2008, 01:54:38 PM »
        This is what the .ini would look like:
        Code: [Select]
        [Settings]
        %PrNm%=Program name*
        %Auth%=Author's Name
        %PrLc%=Program location

        *(Assuming what it would look like.)

        I'm trying to find away to have the batch file read this to get the information needed.
        ╔░░░░░░░░╗
        _Hypercam⌡_
        ╚░░░░░░░░╝

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: .INI with .BAT
        « Reply #5 on: June 17, 2008, 02:49:57 PM »
        Still not certain in what context you want this information. This little snippet will produce environment variables.

        Code: [Select]
        @echo off
        for /f "tokens=1-2 delims==%%" %%v in (test.ini) do (
         if not .%%w equ . set %%v=%%w
         )

        This will produce three variables (PrNm, Auth, and PrLc) that you can use in your batch code as %PrNm%, %Auth%, and %PrLc%

        Is this where you're going with this?

         8)
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        HypercamJ

          Topic Starter


          Beginner

        • Oops =0
          Re: .INI with .BAT
          « Reply #6 on: June 17, 2008, 02:51:29 PM »
          Kind of, but would they load the information about them from the .ini file?
          ╔░░░░░░░░╗
          _Hypercam⌡_
          ╚░░░░░░░░╝

          Sidewinder



            Guru

            Thanked: 139
          • Experience: Familiar
          • OS: Windows 10
          Re: .INI with .BAT
          « Reply #7 on: June 17, 2008, 03:03:50 PM »
          Quote
          Kind of, but would they load the information about them from the .ini file?

          I'm lost. ??? You can extract the data from an ini file and make that data available to a batch file. One way is through the environment (previous post).

          What does your batch file look like and why does it need an ini file? What are you trying to do?

           8)

          The true sign of intelligence is not knowledge but imagination.

          -- Albert Einstein

          HypercamJ

            Topic Starter


            Beginner

          • Oops =0
            Re: .INI with .BAT
            « Reply #8 on: June 17, 2008, 03:12:27 PM »
            I tested it and it works how I would like it. Thanks so much! What I was trying to do was have the batch memorize things. Two other questions:

            1. Does this take all the variables out of test.ini or just three?
            Code: [Select]
            @echo off
            for /f "tokens=1-2 delims==%%" %%v in (test.ini) do (
             if not .%%w equ . set %%v=%%w
             )


            2. And are there any other ways to call information (Like from a regular .txt file.) into the batch?



            ╔░░░░░░░░╗
            _Hypercam⌡_
            ╚░░░░░░░░╝

            Sidewinder



              Guru

              Thanked: 139
            • Experience: Familiar
            • OS: Windows 10
            Re: .INI with .BAT
            « Reply #9 on: June 17, 2008, 03:23:45 PM »
            Quote
            1. Does this take all the variables out of test.ini or just three?

            It takes all the variables except the heading lines (ie. [Settings]). Note: the delims= clause is specific to your data layout and the if statement eliminates the heading lines.

            Quote
            2. And are there any other ways to call information (Like from a regular .txt file.) into the batch?

            The for command with the /f switch will read a file line by line. You can apply any logic within the do loop. The file label of the input file is in parenthesis. This can be any text file, but not proprietary file types like databases or  spreadsheets.

            You can also use the set /p var=<filename command to bring one line from a file into your batch code.

             8)
            The true sign of intelligence is not knowledge but imagination.

            -- Albert Einstein

            HypercamJ

              Topic Starter


              Beginner

            • Oops =0
              Re: .INI with .BAT
              « Reply #10 on: June 17, 2008, 03:32:49 PM »
              Quote
              You can also use the set /p var=<filename command to bring one line from a file into your batch code.
              So does set /p var=<filename just bring the first line in as %VAR% or does it ask you to select a line?
              ╔░░░░░░░░╗
              _Hypercam⌡_
              ╚░░░░░░░░╝

              Sidewinder



                Guru

                Thanked: 139
              • Experience: Familiar
              • OS: Windows 10
              Re: .INI with .BAT
              « Reply #11 on: June 17, 2008, 03:50:21 PM »
              Quote
              So does set /p var=<filename just bring the first line in as %VAR% or does it ask you to select a line?

              Only the first line and there is no prompt. Don't see this much, but for low-volume input  it can be practical and eliminates prompts at the console.

              Using that form of the set statement within a loop retrieves the same first line repetitively. Sort of like Ground Hog Day ;D
              The true sign of intelligence is not knowledge but imagination.

              -- Albert Einstein

              HypercamJ

                Topic Starter


                Beginner

              • Oops =0
                Re: .INI with .BAT
                « Reply #12 on: June 17, 2008, 03:56:23 PM »
                So about the other command with the token you were talking about, is there a way to make it retrieve only one variable (with an added command) or no?
                ╔░░░░░░░░╗
                _Hypercam⌡_
                ╚░░░░░░░░╝

                Sidewinder



                  Guru

                  Thanked: 139
                • Experience: Familiar
                • OS: Windows 10
                Re: .INI with .BAT
                « Reply #13 on: June 17, 2008, 04:58:47 PM »
                If you know which parameter you want, something like this would work:

                Code: [Select]
                @echo on
                set line=0
                for /f "tokens=1-2 delims==%%" %%v in (test.ini) do (
                 if %%v==Auth set %%v=%%w
                )

                You have other tools installed with Windows, specifically VBScript and JScript. This may be the time to drag them out. 8)
                The true sign of intelligence is not knowledge but imagination.

                -- Albert Einstein

                HypercamJ

                  Topic Starter


                  Beginner

                • Oops =0
                  Re: .INI with .BAT
                  « Reply #14 on: June 17, 2008, 05:33:40 PM »
                  Quote
                  You have other tools installed with Windows, specifically VBScript and JScript. This may be the time to drag them out. 8)
                  Drag the out? As in learning how to import from/to them or what?
                  ╔░░░░░░░░╗
                  _Hypercam⌡_
                  ╚░░░░░░░░╝

                  Sidewinder



                    Guru

                    Thanked: 139
                  • Experience: Familiar
                  • OS: Windows 10
                  Re: .INI with .BAT
                  « Reply #15 on: June 17, 2008, 06:05:15 PM »
                  Figure of speech. Both are already installed with the operating system. This is a good place to learn about VBScript. Everything from tools, examples and articles.

                  You can also find a file on your system named script56.chm. This is a compiled help file which serves as a reference for both VBScript and JScript.

                  You can also post here should you have any problems. 8)
                  The true sign of intelligence is not knowledge but imagination.

                  -- Albert Einstein

                  HypercamJ

                    Topic Starter


                    Beginner

                  • Oops =0
                    Re: .INI with .BAT
                    « Reply #16 on: June 17, 2008, 11:07:00 PM »
                    Could you upload script56? I don't have it on my computer.  :( (Searched everywhere!)
                    ╔░░░░░░░░╗
                    _Hypercam⌡_
                    ╚░░░░░░░░╝

                    Sidewinder



                      Guru

                      Thanked: 139
                    • Experience: Familiar
                    • OS: Windows 10
                    Re: .INI with .BAT
                    « Reply #17 on: June 18, 2008, 03:11:49 AM »
                    Quote
                    I don't have it on my computer.

                    That's odd. What OS are you running?

                    You can download it here

                    Good luck.  8)
                    The true sign of intelligence is not knowledge but imagination.

                    -- Albert Einstein

                    HypercamJ

                      Topic Starter


                      Beginner

                    • Oops =0
                      Re: .INI with .BAT
                      « Reply #18 on: June 18, 2008, 10:13:47 AM »
                      Windows XP Home edition. Probably outdated or it only comes with XP Professional. idk...Thanks for the link anyways! Now I might be able to become a vb noob.  :P
                      ╔░░░░░░░░╗
                      _Hypercam⌡_
                      ╚░░░░░░░░╝

                      Dias de verano

                      • Guest
                      Re: .INI with .BAT
                      « Reply #19 on: June 20, 2008, 12:29:46 AM »
                      hypercam, you need to stop asking question after question, and start doing some independent study.

                      michaewlewis



                        Intermediate
                      • Thanked: 26
                        • Yes
                        • Yes
                      • Experience: Expert
                      • OS: Unknown
                      Re: .INI with .BAT
                      « Reply #20 on: June 20, 2008, 01:41:11 PM »
                      You'd probably be better off trying visual basic with some of the ideas you have. You can download visual basic express for free here. http://www.microsoft.com/express/vb/default.aspx
                      And a good book about it: http://www.microsoft.com/MSPress/books/12202.aspx

                      ghostdog74



                        Specialist

                        Thanked: 27
                        Re: .INI with .BAT
                        « Reply #21 on: June 20, 2008, 09:49:26 PM »
                        Is there a way to import settings from an .ini file to use in a batch file? I looked it up on Google but I didn't see anything I was looking for.
                        use  a programming language. eg Python. Sample ini file
                        Code: [Select]
                        [Settings]
                        %PrNm%=Program name
                        %Auth%=Author's Name
                        %PrLc%=Program location

                        [Drivers]
                        a = abc.dll
                        b = efg.ocx
                        code
                        Code: [Select]
                        import ConfigParser
                        config = ConfigParser.ConfigParser()
                        config.read("file")

                        print "Program Name ", config.get("Settings", "%PrNm%")
                        print "Program Location", config.get("Settings", "%PrLc%"),

                        # dump entire config file
                        for section in config.sections():
                            print section
                            for option in config.options(section):
                                print " ", option, "=", config.get(section, option)

                        output:
                        Code: [Select]
                        c:\test> test.py

                        Program Name  Program name
                        Program Location Program location Drivers
                          a = abc.dll
                          b = efg.ocx
                        Settings
                          %auth% = Author's Name
                          %prlc% = Program location
                          %prnm% = Program name