1.

Solve : Using variables inside variables?

Answer»
i'm trying to make a simple way to block websites if i lock my machine, the problem is i have a bunch of variables with . . . . . in them and they are set to v.0 v.1 v.2 ect and i need to seperate the variable and have a variable that can increase , this is what i have so far

@echo off
set c=0
set d=0
for /f "tokens=1* skip=1" %%a in ('ipconfig /displaydns') do echo %%b>>%temp%\v.t
for /f "tokens=1* skip=1" %%a in ('findstr .COM %temp%\v.t') do (
call set /a c=%%c%%+1
call set c.%%c%%=%%b
call set d=%c%
)


i need a way to use a variable inside another variable because i dont know how many there is going to be for example, %c.%d%:~11,100% instead of %c.1:~11,100%well you realy need use a Code: [Select]setlocal enabledelayedexpansion for seting variable in loopthanks, so i've been reading more about how this makes it so the variable expansion takes place before the execution of the for command, i understand how it works just not the syntax

@echo off
setlocal enabledelayedexpansion
set c=0
set d=0
for /f "tokens=1* skip=1" %%a in ('ipconfig /displaydns') do echo %%b>>%temp%\v.t
for /f "tokens=1* skip=1" %%a in ('findstr .com %temp%\v.t') do (
call set /a c=%%c%%+1
call set c.%%c%%=%%b
setlocal d=%c%
)


what am i doing wrong?diablo, could you explain in a bit more detail just what it is you are trying to do? In words, I mean?



I'm creating a lock similar to winkey + L only without the password it disables .exe programs and webpages, i noticed recently active connections are viewable using ipconfig /displaydns, the part i dident bother typing was adding them to the host file
when i use FOR to get the tokens , the closest i can get it down too is . . . . . : www.weburl.com , as an example i'm not sure why there is . . . . . : infront of it anyways, to solve this problem i decided to set it into variables and split up the variable to ignore the . . . . . : because i didnt think there was ANYWAY to set delims for charachters, without it ignoring the entire line.. , so i already know splitting the variable to ignore the first 11 charachters is what i want, so %c.1:~11,100% my problem is , there could be well over 100 of them.. and i need to add an ADDITIONAL variable, since all the variables set are c.1,c.2,c.3 , and since i will never know how many there are, and want to avoid lots of lines of code .. i need to use the variable already being set as D , witch is the number of Times LOOPED or in this case would be used as the number of the variable set , and total number set when its finished' i need to use it as a way to increase itself without adding lots of lines.. like for example


for /f "tokens=1* skip=1" %%a in ('findstr .com %temp%\v.t') do (
call set /a c=%%c%%+1
call set c.%%c%%=%%b
setlocal d=%c%
call echo 127.0.0.1 %C.%d%:~11,145%>>hostfiledir\hostfile
)
You want to process the output of ipconfig /displaydns? and grab something? What?

Code: [Select]www.kuching.co.uk
----------------------------------------
Record NAME . . . . . : www.kuching.co.uk
Record Type . . . . . : 5
Time To Live . . . . : 11313
Data Length . . . . . : 4
Section . . . . . . . : Answer
CNAME Record . . . . : homepages.plus.net


pop3.blueyonder.co.uk
----------------------------------------
Record Name . . . . . : pop3.blueyonder.co.uk
Record Type . . . . . : 1
Time To Live . . . . : 14192
Data Length . . . . . : 4
Section . . . . . . . : Answer
A (Host) Record . . . : 195.188.53.61


www.onvon.com
----------------------------------------
Record Name . . . . . : www.onvon.com
Record Type . . . . . : 5
Time To Live . . . . : 8243
Data Length . . . . . : 4
Section . . . . . . . : Answer
CNAME Record . . . . : onvon.com


news-text.blueyonder.co.uk
----------------------------------------
Record Name . . . . . : news-text.blueyonder.co.uk
Record Type . . . . . : 1
Time To Live . . . . : 3879
Data Length . . . . . : 4
Section . . . . . . . : Answer
A (Host) Record . . . : 195.188.240.200
here is example of using setlocal

with

Code: [Select]setlocal enabledelayedexpansion

if 1 equ 1 (
set var=END
goto !var!
)
exit
:END
pause
without

Code: [Select]if 1 equ 1 (
set var=END
goto %var%
)
exit
:END
pausein the second example, in the third line, %var% will be blank.thanks, but i still dont understand..

setlocal enabledelayedexpansion
set h.0=3985u90289g28gj2
set var=0
echo %h.!var!:~0,1%

and yes im trying to process the output of ipconfig /displaydns, except i cant seem to get just the host name, like www.google.com when i use for i get . . . . : www.google.com and since i need to echo more then one of these variables into the host file, i need it to count automatically.. like echo %c.%d%:~11,100% instead of having to type

echo %c.0:~11,100%
echo %c.1:~11,100%
echo %c.2:~11,100%
echo %c.3:~11,100%
echo %c.4:~11,100%
echo %c.5:~11,100%

because i wont know how many variables it sets to begin with..Is this going in the right direction?

Code: [Select]@echo off
setlocal enabledelayedexpansion

REM for each section, isolate the Record Name line
REM use the colon symbol as delimiter
REM so that there are 2 tokens
REM grab the 2nd token
REM and remove the leading space it will contain
for /f "tokens=1,2 delims=:" %%A in ('ipconfig /displaydns ^| find "Record Name"') do (
set recname=%%B
set recname=!recname: =!
echo !recname!
)

thanks dias and devcom i understand now.
This wont work at all will it? lol , i just realized ipconfig /displaydns is whats already in my hostfileNo it isn't only what is in your hosts file. It shows the contents of the Domain Name System (DNS) client resolver cache, which includes entries that are preloaded from the local Hosts file, as well as any recently obtained resource records for name queries that were resolved by the system.


Discussion

No Comment Found