0

I have asked other questions about Concatenated commands in DOS, but am obviously not yet that confident with the full bredth of things to take into account.

Can someone take a look at the below code and output on my system and see if they can advise what syntax is wrong (Note, I have broken the lines manually):

%comspec% /v:on /k "(for /f "tokens=2*" %a in ('reg query hkcu\software\microsoft
\windows\currentversion\policies\system /v DisableTaskMgr') do @set DisableTaskMg
r=%b) 2>nul & set DisableTaskMgr& pause & (if defined programfiles^(x86^) (set
"ProgramFiles(x32)=%programfiles(x86)%") else (set "ProgramFiles(x32)=%programfil
es%")) & !ProgramFiles(x32)!\Mozilla\Firefox\Firefox.exe -chrome chrome://browser
/content & echo. & if defined DisableTaskMgr (echo DisableTaskMgr reg key existed
prior to running, and... & (set DisableTaskMgr=%DisableTaskMgr:~2,3% & echo !
DisableTaskMgr! & reg add hkcu\software\microsoft\windows\currentversion\policies
\system /v DisableTaskMgr /t REG_DWORD /d %DisableTaskMgr% & if %DisableTaskMgr%
eql 0 (echo Previous state was Task Manager enabled) else (echo Previous state
was Task Manager DISabled))) else (echo DisableTaskMgr reg key DID NOT exist pri
or to running & reg delete hkcu\software\microsoft\windows\currentversion\polici
es\system /v DisableTaskMgr /f)"

.
enter image description here

I have tried cutting out parts of the code to fix individual parts, but my attempts at trial and error prove that I don't have much of an idea of what is wrong, and that I am not going to get this solved on my own very fast :(

enter image description here

user66001
  • 774
  • 1
  • 13
  • 36

2 Answers2

1

Your IF comparison operator is wrong. You have eql - it should be equ.

I have no idea if that is your only problem - you have a horrific maintenance issue with that beast of a statement.

You might be better off creating a batch file with the same logic but formatted nicely. You can then simply call the batch file instead of trying to embed the entire complex process as one single complex command.

dbenham
  • 127,446
  • 28
  • 251
  • 390
  • Ah, thanks! I am sure there are other errors, that I hope someone can see. Yep, know it is hard to maintain, but the client ended up creating a shortcut to the batch file I created with this logic, so am trying to circumvent this thinking. Besides, I like a challenge! :) – user66001 Sep 13 '12 at 22:17
0

I can see your problem right here! It's your code! *grin*

Seriously though, even if you intend to maintain that mess, I recommend that split it up into it's constituent components for debugging purposes. You can even avoid the sometimes mysterious block errors by putting what is inside () blocks into separate subroutines. By turning this sort of thing...

if statement (
  code block 1
  code block 1
  code block 1
  code block 1
) else if (
  code block 2
  code block 2
  code block 2
  code block 2
)

...into this sort of thing:

if statement (
  call :CodeBlock1
) else if (
  call :CodeBlock2
)
goto :eof

:CodeBlock1
  code
  code
  code
  code
goto :eof

:CodeBlock2
  code
  code
  code
  code
goto :eof

Trying to debug that as a single line means keeping the whole thing, and how it interacts, constantly in mind. And basically having to guess at which similar looking bit of code actually created the error you're trying to fix.

I've personally wasted a good bit of time trying to fix perfectly good code, while not realizing that the error that I was looking at was actually further down in the code block.

After you've found and fixed your errors you can jam it all back into a single line again if you like. Overcoming a challenge does not necessarily mean doing it the hardest way possible. Overcoming a challenge the easiest way is also, by definition, overcoming a challenge.

James K
  • 4,005
  • 4
  • 20
  • 28
  • Thanks for your answer @JamesK - It is a good suggestion for debugging, but have already done something similar and came to the conclusion that it is my continuing lack of knowledge on delayed expansion that is the reason the code is not producing the desired output. – user66001 Sep 17 '12 at 18:29
  • @user66001 - Well, keep in mind that using delayed expansion does not need to be limited to use inside code blocks. Anytime after a `setlocal enabledelayesexpansion` will work fine, sometimes better. ^_^ – James K Sep 17 '12 at 18:46