1.

Solve : If Exist 'something' in CONFIG.NT?

Answer»

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
Quote from: JACOB on November 05, 2008, 09:43:17 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.
And how would I do that?Quote from: Jacob on November 05, 2008, 10:47:56 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

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
Hmmm... I get the same result. I will investigate.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
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.


Discussion

No Comment Found