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

Author Topic: If Exist 'something' in CONFIG.NT  (Read 3890 times)

0 Members and 1 Guest are viewing this topic.

Jacob

    Topic Starter


    Hopeful

    Thanked: 1
    • Experience: Expert
    • OS: Windows XP
    If Exist 'something' in CONFIG.NT
    « on: November 05, 2008, 09:43:17 AM »
    I have this so far.
    Code: [Select]
    @echo off
    echo Get CONFIG.NT & COPY %SystemRoot%\system32\CONFIG.NT
    if exist ("%SystemRoot%\system32\ansi.sys") in ('type CONFIG.NT') do (
    echo ansi.sys is active.
    ) else (
    echo ansi.sys is not active.
    )
    pause >nul
    Basically if it finds "%SystemRoot%\system32\ansi.sys" in CONFIG.NT it should echo ansi.sys is active.
    if it doesn't it should echo it is not.

    Thanks ;)

    Dias de verano

    • Guest
    Re: If Exist 'something' in CONFIG.NT
    « Reply #1 on: November 05, 2008, 10:31:05 AM »
    if exist ("%SystemRoot%\system32\ansi.sys") in ('type CONFIG.NT') do (

    IF EXIST only finds files, it does not find lines in files.

    You can use FIND and the && operator to test if certain text is present in a file.

    Jacob

      Topic Starter


      Hopeful

      Thanked: 1
      • Experience: Expert
      • OS: Windows XP
      Re: If Exist 'something' in CONFIG.NT
      « Reply #2 on: November 05, 2008, 10:47:56 AM »
      And how would I do that?

      Dias de verano

      • Guest
      Re: If Exist 'something' in CONFIG.NT
      « Reply #3 on: November 05, 2008, 10:57:22 AM »
      And how would I do that?

      set cat=0
      type animals.txt | find "cat" && set /a cat=1
      if %cat% GTR 0 echo I found a cat


      Jacob

        Topic Starter


        Hopeful

        Thanked: 1
        • Experience: Expert
        • OS: Windows XP
        Re: If Exist 'something' in CONFIG.NT
        « Reply #4 on: November 05, 2008, 11:10:56 AM »
        For some reason this will not work, it keeps bringing back that it is not there when it is.
        Code: [Select]
        @echo off
        set ansi=false
        type %SystemRoot%\system32\CONFIG.NT | find "device=%SystemRoot%\system32\ansi.sys" && set ansi=true
        If %ansi%=="true" (
        echo ansi.sys is active.
        ) else (
        echo ansi.sys is not active.
        )
        pause >nul

        Dias de verano

        • Guest
        Re: If Exist 'something' in CONFIG.NT
        « Reply #5 on: November 05, 2008, 11:37:47 AM »
        Hmmm... I get the same result. I will investigate.

        Dias de verano

        • Guest
        Re: If Exist 'something' in CONFIG.NT
        « Reply #6 on: November 05, 2008, 11:44:03 AM »
        This works on my system, I tried it with config.nt containing the line

        device=%SystemRoot%\system32\ansi.sys

        and again with it deleted and it showed the correct results.

        NOTE the double percent signs around SystemRoot (because in a batch to achieve 1 percent sign in a string you need to use 2)

        Or -- of course --  you could just replace %SystemRoot% with C:\WINDOWS in both Config.nt and also your batch file and avoid all that (presuming your SystemRoot variable does expand to that)

        Code: [Select]
        @echo off
        find "device=%%SystemRoot%%\system32\ansi.sys" "%SystemRoot%\system32\CONFIG.NT">nul
        If %errorlevel% EQU 0 (
        echo ansi.sys is active.
        ) else (
        echo ansi.sys is not active.
        )
        pause >nul

        Jacob

          Topic Starter


          Hopeful

          Thanked: 1
          • Experience: Expert
          • OS: Windows XP
          Re: If Exist 'something' in CONFIG.NT
          « Reply #7 on: November 05, 2008, 12:33:58 PM »
          Thank very much, once again.
          Code: [Select]
          @echo off
          find "device=C:\WINDOWS\system32\ansi.sys" "C:\WINDOWS\system32\CONFIG.NT">nul
          If %errorlevel% EQU 0 (
          echo ansi.sys is active.
          ) else (
          echo ansi.sys is not active.
          echo device=C:\WINDOWS\system32\ansi.sys>>C:\WINDOWS\system32\CONFIG.NT
          )
          pause >nul
          works perfectly.