Computer Hope

Microsoft => Microsoft DOS => Topic started by: Lemonilla on June 10, 2012, 07:38:50 PM

Title: string inside a sting
Post by: Lemonilla on June 10, 2012, 07:38:50 PM
So I need to loop a 'choice /c ...' %b% amount of times, setting a new veriable each time it loops named p%b%.  I got the pulling thing, but %p%b%% doesnt work, and neither does %%p%b%%%. I believe you have to do this with a for loop, but when I typed for /?, I had no clue what they were talking about.  If anyone could walk me through one of these that would be great! A workaround would be great too :D code below.


Code: [Select]
@echo off
if exist stop.txt del /f stop.txt
title extraSecurity
set /p p#=<p.exs
set a=0
:ploop
set /a a+=1
set /p p%a%=<p%a%.exs
if %a% EQU %p#% goto exit.ploop
goto ploop
:exit.ploop
set b=0
:cloop
set b+=1
choice /c 1234567890qwertyuiopasdfghjklzxcvbnmABCDEFGHIJKLMNOPQRSTUVWXYZ /n /cs /m "Password?"\
set de=%p%%b%%
IF %errorlevel%==%p%b%% goto end
goto exit

:end
echo OK >>stop.txt
if not exist stop.txt goto end
exit

:exit
if exist stop.txt shutdown -s -f -t 1 & if exist stop.txt exit
goto exit
Title: Re: string inside a sting
Post by: Sidewinder on June 11, 2012, 06:35:04 AM
Could not test your code beyond the ploop. Need more info about the exs files and their contents. Not sure why you want/need a choice statement in a for loop. Perhaps if you told us what you're trying to accomplish, we might better find a solution.

In general, I have found using a variable value as part of another variable name, it works to call a set statement and double up on the percent symbols.

 8)
Title: Re: string inside a sting
Post by: Squashman on June 11, 2012, 10:02:30 AM
I think what you are trying to do is access an array variable.  In which case you would need to use delayed expansion.
Title: Re: string inside a sting
Post by: Lemonilla on June 11, 2012, 10:08:48 AM
Could not test your code beyond the ploop. Need more info about the exs files and their contents. Not sure why you want/need a choice statement in a for loop. Perhaps if you told us what you're trying to accomplish, we might better find a solution.

In general, I have found using a variable value as part of another variable name, it works to call a set statement and double up on the percent symbols.

 8)
I am attempting to create a password that does not show up on the screen, thus it would clear out all input as soon as you enter it, that was why I was using choice /c.

The p#.exs are just renamed text files that corrospond with the errorlevel of choice /c for the correct password.

Would you mind expanding on the 'call a set' thing you were talking about? I have never heard of it before.

I think what you are trying to do is access an array variable.  In which case you would need to use delayed expansion.

Not sure what this is, but will look into it when I get home.
Title: Re: string inside a sting
Post by: Sidewinder on June 11, 2012, 12:23:33 PM
I am attempting to create a password that does not show up on the screen, thus it would clear out all input as soon as you enter it, that was why I was using choice /c.

Check out this (http://www.computerhope.com/forum/index.php/topic,96062.0/all.html#bot) post for information on passwords and batch processing.

The posted code will not run on a 64 bit OS. Have you considered VBScript or Powershell? More verbose to be sure but you'll have more secure results.

 8)
Title: Re: string inside a sting
Post by: BC_Programmer on June 11, 2012, 12:36:23 PM
Control-Break can circumvent any 'protections' made by way of a batch file....
Title: Re: string inside a sting
Post by: Lemonilla on June 11, 2012, 04:46:14 PM
Control-Break can circumvent any 'protections' made by way of a batch file....
Check out this (http://www.computerhope.com/forum/index.php/topic,96062.0/all.html#bot) post for information on passwords and batch processing.

The posted code will not run on a 64 bit OS. Have you considered VBScript or Powershell? More verbose to be sure but you'll have more secure results.

 8)
Sorry to be the pessimist, but I believe you guys are totally missing the point of the program. It isn't for the sake of security, I could really just ask him not to use my computer and problem solved. It's more for the practice programming and for learning new commands.

Anyway, problem was fixed with a reorganization of code.
Code: [Select]
@echo off
if exist stop.txt del /f stop.txt
title extraSecurity
set /p p#=<p.exs
set b=0

:cloop

title Letter Number:%b%
set /a b+=1
choice /c 1234567890qwertyuiopasdfghjklzxcvbnmABCDEFGHIJKLMNOPQRSTUVWXYZ /n /cs /m "Password?"
cls
set /p p=<p%b%.exs
IF %errorlevel% NEQ %p% goto exit
if %b% EQU %p#% goto end
goto cloop


:end
echo OK >>stop.txt
if not exist stop.txt goto end
exit

:exit
if exist stop.txt shutdown -s -f -t 1
if exist stop.txt exit
goto exit