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

Author Topic: string inside a sting  (Read 4720 times)

0 Members and 1 Guest are viewing this topic.

Lemonilla

    Topic Starter


    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
string inside a sting
« 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
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: string inside a sting
« Reply #1 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)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: string inside a sting
« Reply #2 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.

Lemonilla

    Topic Starter


    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: string inside a sting
« Reply #3 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.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: string inside a sting
« Reply #4 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 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)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: string inside a sting
« Reply #5 on: June 11, 2012, 12:36:23 PM »
Control-Break can circumvent any 'protections' made by way of a batch file....
I was trying to dereference Null Pointers before it was cool.

Lemonilla

    Topic Starter


    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: string inside a sting
« Reply #6 on: June 11, 2012, 04:46:14 PM »
Control-Break can circumvent any 'protections' made by way of a batch file....
Check out this 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
« Last Edit: June 11, 2012, 05:24:52 PM by Lemonilla »
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.