Once again problem with a batch file.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Once again problem with a batch file.

#1 Post by Ranguna173 » 17 Mar 2013 05:55

Hello everyone.


And once again I'm having problem with a batch file, it's the same batch as before, save a log everytime it opens and lots of other things.
But as it seems it's not working again, here's the part of the code that doesn't work:

Code: Select all

set opwp=false
set didauthcheck=false
@echo off &setlocal enableDelayedExpansion
if !didauthcheck! == false (
    cd C:\Users\Admin\AppData\Roaming\WCMP\logs
    if exist "location" (
       < location set /p "locationl="
       cd %locationl%
      )
    < log.txt (
       set /p "line1="
       set /p "line2="
      )
    if exist "pwp" (
       set opwp=true
      )
    if !%line2! == "Accces Not Authorized" (
       cd c:\users\admin\desktop\
       echo "Session at %line1% was not auhorized or the password was not provided/was wrong.">log.txt
       if !opwp! == true (
          cd %locationl%
          < pwp set /p "pp="
          cd c:\users\admin\desktop
          echo The provided password was "%pp%".>>log.txt
         )
      )
   )



Every directory exists and (I think) all variables are set too.

Here's the output on the CMD window:

Code: Select all

C:\>code.bat

C:\>set opwp=false

C:\>set didauthcheck=false
C:\Users\Admin\AppData\Roaming\WCMP\logs
O sistema não conseguiu localizar o ficheiro especificado. (The system couldn't find the specific directory or file.)



The directory "C:\Users\Admin\AppData\Roaming\WCMP\logs" exist, I've tried everything I could but nothing did the trick.
If you can correct it please post the fix and what you changed to make it work (if you can).

If you need any other information about the code don't hesitate to ask.

Thanks for reading :)

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Once again problem with a batch file.

#2 Post by abc0502 » 17 Mar 2013 06:30

check this line:
if !%line2!
remove the percentage sign, i think it's an extra sign.

also, you used the cd command to change your current location, it's better to use the /D switch with it to avoid problems.
as using just CD command will just go to levels up but can't go to any other locations and you might have changed location in the rest of the code and that's why it can't find your current location.

try adding /D to this line

Code: Select all

    cd C:\Users\Admin\AppData\Roaming\WCMP\logs

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: Once again problem with a batch file.

#3 Post by Ranguna173 » 17 Mar 2013 06:40

Output after change: (!%line2! --> !line2!)

Code: Select all

C:\>set didauthcheck=false
C:\Users\Admin\AppData\Roaming\WCMP\logs
O sistema não conseguiu localizar o ficheiro especificado.(The system couldn't find the specificfile.)


Thanks for replying but that wasn't the problem, and I still don't know what's going on.

After several time reading and rewriting I still get nothing, maybe it's my command line that's acting up ?
Last edited by Ranguna173 on 17 Mar 2013 06:42, edited 1 time in total.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Once again problem with a batch file.

#4 Post by abc0502 » 17 Mar 2013 06:41

sorry i updated my last post

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: Once again problem with a batch file.

#5 Post by Ranguna173 » 17 Mar 2013 06:46

abc0502 wrote:sorry i updated my last post


Output after change: (cd --> cd /D)

Code: Select all

C:\>set didauthcheck=false
C:\Users\Admin\AppData\Roaming\WCMP\logs
O sistema não conseguiu localizar o ficheiro especificado.(The system couldn't find the specificfile.)


Same error, I tried puting "/D" after every "cd" but it didn't work either.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Once again problem with a batch file.

#6 Post by abc0502 » 17 Mar 2013 06:49

ok, try this,
add

Code: Select all

echo %locationl%
pause
after this:

Code: Select all

 cd %locationl%

to see if your previous set /p command has set the location or not

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: Once again problem with a batch file.

#7 Post by Ranguna173 » 17 Mar 2013 06:59

abc0502 wrote:ok, try this,
add

Code: Select all

echo %locationl%
pause
after this:

Code: Select all

 cd %locationl%

to see if your previous set /p command has set the location or not


Output code:

Code: Select all

C:\>set didauthcheck=false
C:\Users\Admin\AppData\Roaming\WCMP\logs
O comando ECHO está desactivado. (Command ECHO is deactivated.)
Prima qualquer tecla para continuar . . . (Press any key to continue ...)
O sistema não conseguiu localizar o ficheiro especificado.(The system couldn't find the specific file.)


Alright, we are making progress, but it's wierd, the first line of the file isn't empty, why isn't it setting the variable ?
Awesome, let's keep going.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Once again problem with a batch file.

#8 Post by abc0502 » 17 Mar 2013 07:03

i'm not familiar with this command, what it supposed to do ?

Code: Select all

< location set /p "locationl="


if it will set the location of the location folder then just use:

Code: Select all

set "locationl=%~dp0location"
or

Code: Select all

set "locationl=C:\Users\Admin\AppData\Roaming\WCMP\logs\location"
it's better and more readable

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: Once again problem with a batch file.

#9 Post by Ranguna173 » 17 Mar 2013 07:10

abc0502 wrote:i'm not familiar with this command, what it supposed to do ?

Code: Select all

< location set /p "locationl="


if it will set the location of the location folder then just use:

Code: Select all

set "locationl=%~dp0location"
or

Code: Select all

set "locationl=C:\Users\Admin\AppData\Roaming\WCMP\logs\location"
it's better and more readable


The first line of "location" is a dynamic directory that changes once in a while, I use that file to save the directory so the batch can know it and read it with that code.

Here's what is inside the file: (location)

Code: Select all

"C:\Users\Admin\AppData\Roaming\WCMP\Logs\17-03-2013 (2)"



Also, here are others exemples of the code: (< location set /p "locationl=")

Code: Select all

set /p locationl=<location

Code: Select all

< location set /p "locationl="

Code: Select all

< location (
  set /p locationl=
)

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Once again problem with a batch file.

#10 Post by abc0502 » 17 Mar 2013 07:15

i thought location is a folder not a file :oops:
This "17-03-2013 (2)" i has parentheses, and it could be the problem.
try changing it in the location file from "17-03-2013 (2)" to "17-03-2013" and create a folder with the same name ( just for testing ) and see if it will work.

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: Once again problem with a batch file.

#11 Post by Ranguna173 » 17 Mar 2013 07:26

abc0502 wrote:i thought location is a folder not a file :oops:
This "17-03-2013 (2)" i has parentheses, and it could be the problem.
try changing it in the location file from "17-03-2013 (2)" to "17-03-2013" and create a folder with the same name ( just for testing ) and see if it will work.


Yeah it can be confusing since it doesn't has any file extentions.

So I've set echo to on so we can have more accurate outputs

Here's the output: (17-03-2013 (2) --> 17-03-2013, folder 17-03-2013 (2) --> folder 17-03-2013, echo off --> on)

Code: Select all

C:\>code.bat

C:\>set opwp=false

C:\>set didauthcheck=false

C:\>if !didauthcheck! == false (
cd /D C:\Users\Admin\AppData\Roaming\WCMP\logs
 if exist "location" (
(set /p locationl= ) 0<C:\Users\Admin\AppData\Roaming\WCMP\logs\location
 cd
 echo
 pause
)
 (
set /p "line1="
 set /p "line2="
) 0<log.txt
 if exist "pwp" (set opwp=true )
 if !line2! == "Accces Not Authorized" (
cd c:\users\admin\desktop\
 echo "Session at  was not auhorized or the password was not provided/was wrong.
" 1>log.txt
 if !opwp! == true (
cd
 set /p "pp=" 0<pwp
 cd c:\users\admin\desktop
 echo The provided password was "". 1>>log.txt
)
)
)
C:\Users\Admin\AppData\Roaming\WCMP\logs
O comando ECHO está desactivado. (Command ECHO is deactivated.)
Prima qualquer tecla para continuar . . . (Press any key to continue ...)
O sistema não conseguiu localizar o ficheiro especificado.(The system couldn't find the specific file.)


Here's the output: (17-03-2013 (2) --> 17-03-2013, folder 17-03-2013 (2) --> folder 17-03-2013, echo on --> off)

Code: Select all

C:\>code.bat

C:\>set opwp=false

C:\>set didauthcheck=false
C:\Users\Admin\AppData\Roaming\WCMP\logs
O comando ECHO está desactivado. (Command ECHO is deactivated.)
Prima qualquer tecla para continuar . . . (Press any key to continue ...)
O sistema não conseguiu localizar o ficheiro especificado.(The system couldn't find the specific file.)


Again the same error, but let's see if we can spot anything in the "echo on" output.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Once again problem with a batch file.

#12 Post by abc0502 » 17 Mar 2013 07:39

try this part of the code only and post the output:

Code: Select all

set opwp=false
set didauthcheck=false
@echo off &setlocal enableDelayedExpansion
if !didauthcheck! == false (
    cd C:\Users\Admin\AppData\Roaming\WCMP\logs
    if exist "location" (
       < location set /p "locationl="
       echo %locationl%
      )
pause

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: Once again problem with a batch file.

#13 Post by Ranguna173 » 17 Mar 2013 07:54

abc0502 wrote:try this part of the code only and post the output:

Code: Select all

set opwp=false
set didauthcheck=false
@echo off &setlocal enableDelayedExpansion
if !didauthcheck! == false (
    cd C:\Users\Admin\AppData\Roaming\WCMP\logs
    if exist "location" (
       < location set /p "locationl="
       echo %locationl%
      )
pause


Output: (with your code)

Code: Select all

C:\>code.bat

C:\>set opwp=false

C:\>set didauthcheck=false


Hmmm.. it didn't pause nor did it echo anything.
Well no error either.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Once again problem with a batch file.

#14 Post by abc0502 » 17 Mar 2013 07:56

it's missing a final close parentheses ), add it. and check your code too

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: Once again problem with a batch file.

#15 Post by Ranguna173 » 17 Mar 2013 08:00

abc0502 wrote:it's missing a final close parentheses ), add it. and check your code too


The parentheses in my code are all right, they are all closed.

In you code do you want me to put the parentheses before or after the pause ?

Post Reply