I made a bat file, it says echo sss ttt and runs at the start, and i'd like it running at the start
this key refers to it
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
But that FOR command is executing it in some way! and executing echo sss
Why does it say echo sss and not echo sss ttt?
How can I suppress the running of cmd or that initialization bat file with the FOR?
The FOR statement should really just display "echo g", not "echo sss" or "echo sss ttt".
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
sss ttt
C:\Documents and Settings\Administrator>cd\
C:\>type \blah\startfile.bat <ENTER>
@echo sss ttt
C:\>
C:\>for /f %f in ('echo g ^| findstr "g"') do echo %f <ENTER>
C:\>echo sss
sss
C:\>echo g
g
C:\>
For command initiates autorun bat file
Moderator: DosItHelp
Re: For command initiates autorun bat file
Your FOR /F statement is executing your AUTORUN script because FOR /F must instantiate another CMD.EXE in order to execute the command in the IN ('command') clause.
Your AUTORUN script outputs sss ttt, and your FOR /F only preserves the 1st token which is sss. BUT it doesn't make sense that sss passes your FINDSTR portion of the command. I'm wondering if perhaps your example is not precisely what is happening on your machine, and in attempt to paraphrase the situation you've got the scenario slightly wrong.
I'm not aware of a way to disable AUTORUN when using FOR /F %A IN ('COMMAND').
Perhaps you could modify your AUTORUN script so that the main body only executes once within a session:
When your FOR statement instantiates a new CMD.EXE, it inherits the existing environment, so the AUTORUN script should exit prior to doing any harm. I haven't tested this, but it seems like it should work.
Dave Benham
Your AUTORUN script outputs sss ttt, and your FOR /F only preserves the 1st token which is sss. BUT it doesn't make sense that sss passes your FINDSTR portion of the command. I'm wondering if perhaps your example is not precisely what is happening on your machine, and in attempt to paraphrase the situation you've got the scenario slightly wrong.
I'm not aware of a way to disable AUTORUN when using FOR /F %A IN ('COMMAND').
Perhaps you could modify your AUTORUN script so that the main body only executes once within a session:
Code: Select all
@echo off
if defined AUTORUN_HAS_ALREADY_BEEN_RUN exit /b
echo sss ttt
set AUTORUN_HAS_ALREADY_BEEN_RUN=1
Dave Benham
Re: For command initiates autorun bat file
what is "if defined"?
I don't see it listed in "help if"
is it recorded anywhere in documentation?
I don't see it listed in "help if"
is it recorded anywhere in documentation?
Re: For command initiates autorun bat file
It is a standard command extension that should be available to you in XP. Normally command extensions are enabled by default.
Here is the relavent documentation:
If Command Extensions are enabled IF changes as follows:
IF [/I] string1 compare-op string2 command
IF CMDEXTVERSION number command
IF DEFINED variable command
...
The DEFINED conditional works just like EXISTS except it takes an
environment variable name and returns true if the environment variable
is defined.
If your "DOS" session is using COMMAND.COM instead of CMD.EXE then I guess the command extensions are not available, but I'm not sure. I don't have access to XP at the moment.
You can simply change the test as follows:
Dave Benham
Here is the relavent documentation:
If Command Extensions are enabled IF changes as follows:
IF [/I] string1 compare-op string2 command
IF CMDEXTVERSION number command
IF DEFINED variable command
...
The DEFINED conditional works just like EXISTS except it takes an
environment variable name and returns true if the environment variable
is defined.
If your "DOS" session is using COMMAND.COM instead of CMD.EXE then I guess the command extensions are not available, but I'm not sure. I don't have access to XP at the moment.
You can simply change the test as follows:
Code: Select all
if not "%AUTORUN_HAS_ALREADY_BEEN_RUN%"=="" exit /b
Dave Benham
Re: For command initiates autorun bat file
I checked my XP @home
COMMAND.COM on XP supports IF DEFINED, and there doesn't appear to be a way to disable command extensions with COMMAND.COM.
Based on the header display when you start your command shell, you are running CMD.EXE anyway.
Your HELP IF results should include the description of IF DEFINED.
Dave Benham
COMMAND.COM on XP supports IF DEFINED, and there doesn't appear to be a way to disable command extensions with COMMAND.COM.
Based on the header display when you start your command shell, you are running CMD.EXE anyway.
Your HELP IF results should include the description of IF DEFINED.
Dave Benham