Task Scheduler truncates PATH variable?!

A

Angel Tsankov

Hello,
I have a simple batch file that prints the PATH environment
variable: @echo off
echo %PATH% [ ]
None. Sorry, I use neither XP nor the Task Scheduler (W2K
here). That is certainly odd. Perhaps your very-long-PATH can
and should be shortened considerably? Not that this is an
explanation of course. Did you try echo/redirect %PATH% to a
file?

Same result - only the first 1024 characters are echoed.
Besides, I cannot shorten my PATH as I access my programs via
the run menu, from the command prompt and batch files. Putting
the respective paths in the PATH variable seems to suits these
needs very well.

1510 characters in a PATH is (pardon me) ridiculous. I can't even
imagine how in practice that can be. There are many methods to
reduce the number of FQ directoy paths needing to be in PATH. Even
if one works from CMD a lot. For one, place all your batch or
other CLI script files in one or two directories "not too deep"
(eg c:\util C:\batch c:\scripts or similar). If an application has
need of very long or multiple paths in PATH, then start it from a
batch file instead and include the setting of those locations into
a more restricted and focus PATH variable also set inside the batch
file. It seems you may be misusing the PATH on your system
especially when you consider that every PATH search needs to
"walk" through all of them until a "hit" occurs.

Example: (not start in col 2, it wrapped)
@echo off
SETLOCAL
SET PATH=%SYSTEMROOT%\SYSTEM32;%SYSTEMROOT%;Q:\someapplication
\deepdir1\deepdir2\bin
START "" "Q:\someapplication\deepdir1\deepdir2\bin\someapp.exe"
EXIT

Line 2 is optional
A
CD /d Q:\someapplication\deepdir1\deepdir2\bin
START "" someapp.exe"
may also be suffient.

Also, Shortcuts that specify the Working Directory ("Start In") can
be used in many cases.

Not bashing you or your system and there is much I do not know, but
you should IMHO consider the points and try to shorten your PATH
even above and beyond the TaskScheduler issue.

Hmm, good point and I'll definitely give a good deal of thought.
Thanks a lot!

OK, first question: what if I need to pass arguments to the executable
and I do not know their number in advance?
 
P

Phil Robyn

Angel said:
Hello,

I have a simple batch file that prints the PATH environment
variable: @echo off
echo %PATH%

[ ]

None. Sorry, I use neither XP nor the Task Scheduler (W2K
here). That is certainly odd. Perhaps your very-long-PATH can
and should be shortened considerably? Not that this is an
explanation of course. Did you try echo/redirect %PATH% to a
file?


Same result - only the first 1024 characters are echoed.
Besides, I cannot shorten my PATH as I access my programs via
the run menu, from the command prompt and batch files. Putting
the respective paths in the PATH variable seems to suits these
needs very well.


1510 characters in a PATH is (pardon me) ridiculous. I can't even
imagine how in practice that can be. There are many methods to
reduce the number of FQ directoy paths needing to be in PATH. Even
if one works from CMD a lot. For one, place all your batch or
other CLI script files in one or two directories "not too deep"
(eg c:\util C:\batch c:\scripts or similar). If an application has
need of very long or multiple paths in PATH, then start it from a
batch file instead and include the setting of those locations into
a more restricted and focus PATH variable also set inside the batch
file. It seems you may be misusing the PATH on your system
especially when you consider that every PATH search needs to
"walk" through all of them until a "hit" occurs.

Example: (not start in col 2, it wrapped)
@echo off
SETLOCAL
SET PATH=%SYSTEMROOT%\SYSTEM32;%SYSTEMROOT%;Q:\someapplication
\deepdir1\deepdir2\bin
START "" "Q:\someapplication\deepdir1\deepdir2\bin\someapp.exe"
EXIT

Line 2 is optional
A
CD /d Q:\someapplication\deepdir1\deepdir2\bin
START "" someapp.exe"
may also be suffient.

Also, Shortcuts that specify the Working Directory ("Start In") can
be used in many cases.

Not bashing you or your system and there is much I do not know, but
you should IMHO consider the points and try to shorten your PATH
even above and beyond the TaskScheduler issue.


Hmm, good point and I'll definitely give a good deal of thought.
Thanks a lot!


OK, first question: what if I need to pass arguments to the executable
and I do not know their number in advance?

use '%*' (without the apostrophes) to pass all arguments.
 
M

Mark [exmsft]

1510 characters in a PATH is (pardon me) ridiculous. I can't even
imagine how in practice that can be. There are many methods to reduce
the number of FQ directoy paths needing to be in PATH. Even if one
works from CMD a lot. For one, place all your batch or other CLI
script files in one or two directories "not too deep" (eg c:\util
C:\batch c:\scripts or similar). If an application has need of very
long or multiple paths in PATH, then start it from a batch file
instead and include the setting of those locations into a more
restricted and focus PATH variable also set inside the batch file. It
seems you may be misusing the PATH on your system especially when you
consider that every PATH search needs to "walk" through all of them
until a "hit" occurs.

You can also create an entry for the application in question under the App
Paths key in the registry. This was created to provide applications a way
to ensure certain directories where in their PATH without having to use the
system PATH. However, enough applications make use of it (IMH).

go to 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths'
and create a key with the name of the application in question. Under that
new key, create a new String named Path and put in the directories that this
application needs to see. Whenever this application is launched, the system
will pre-pend these values on to the system path before passing it to the
new program's environment.

to see is in action, create a key named cmd.exe and a string named Path under
it. put the value c:\newvalue in the new string. Now, start a new instance
of cmd.exe and echo %path%. you will see 'c:\newvalue' at the beginning
of the path.

this, in conjunction with Mark V's suggestion of using a small batch file
to set the working directory for the application should allow you to remove
several entries from your system path.

You can also set the Default string value to the full path to the executable
which allows Start->Run or the start command from cmd.exe to find executables
that aren't in the system path.

thanks,
mark
 
M

Mark V

[ ]
You can also create an entry for the application in question
under the App Paths key in the registry. This was created to
provide applications a way to ensure certain directories where
in their PATH without having to use the system PATH. However,
enough applications make use of it (IMH).

Excellent addition. I always forget about that one! :)
[ ]
 
D

David Candy

Help Windows Find Programs and Documents
Programs and documents can be added to the registry so typing their name without their path in the Start - Run dialog box or shortcut enables Windows to find them.

This is a generic reg file. Copy the lines below to a new Text Document and save it as anyname.reg. Edit it with your programs or documents.


In paths use \\ to seperate folder names in key paths as regedit uses a single \ to seperate it's key names. All reg files start with REGEDIT4. A semicolon turns a line into a comment. The @ symbol means to assign the value to the key rather than a named value.

The file doesn't have to exist. This can be used to set Word.exe to open Winword.exe.

This sample add IE.Txt (from IE5) to the registry so typing IE.Txt will open it. I think the file is called IE4.txt in IE4.

REGEDIT4
;The bolded name below is the name of the document or program, <filename>.<file extension>

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\IE.txt]

;The @ means the path to the file is assigned to the default value for the key.
;The whole path in enclosed in a quotation mark ".

@="\"C:\\Program Files\\Internet Explorer\\IE.txt\""

;Optional Parameters. The semicolon means don't process the line. Remove it if you want to put it in the registry

;Informs the shell that the program accepts URLs.

;"useURL"="1"

;Sets a path that is prepended to the process's path. This is commented out.

;"Path"="C:\\Program Files\\Microsoft Office\\Office\\"
There is also save url and some Terminal Server specific settings. Also some programs store stuff here.

Registering things as an exe (even if they aren't) allows the name to be typed in Start Run without an extension.
--
--------------------------------------------------------------------------------------------------
Goodbye Web Diary
http://margokingston.typepad.com/harry_version_2/2005/12/thank_you_and_g.html#comments
=================================================
Mark V said:
[ ]
You can also create an entry for the application in question
under the App Paths key in the registry. This was created to
provide applications a way to ensure certain directories where
in their PATH without having to use the system PATH. However,
enough applications make use of it (IMH).

Excellent addition. I always forget about that one! :)
[ ]
 
M

Mark [exmsft]

After looking into this a bit more, I checked the PATH length on my system
at work, where we have plenty of applications installed that apparently have
no idea how to use the "App Paths" portion of the registry. By the time
I log in, my PATH variable is 1239 chars long. I did some more digging around
in the MS KB and found that beginning with Windows XP SP2, the PATH is allowed
to be 2048 chars long[1]. I guess this is an indication that 1000+ char
PATHs are not that uncommon....

thanks,
mark

[1] See the "MORE INFORMATION" section of http://support.microsoft.com/kb/832978/
 
A

Angel Tsankov

1510 characters in a PATH is (pardon me) ridiculous. I can't even
After looking into this a bit more, I checked the PATH length on my system
at work, where we have plenty of applications installed that apparently have
no idea how to use the "App Paths" portion of the registry. By the time
I log in, my PATH variable is 1239 chars long. I did some more digging around
in the MS KB and found that beginning with Windows XP SP2, the PATH is allowed
to be 2048 chars long[1]. I guess this is an indication that 1000+ char
PATHs are not that uncommon....

[1] See the "MORE INFORMATION" section of http://support.microsoft.com/kb/832978/

This is very interesting, Mark. Thanks a lot for the efforts!

Angel Tsankov
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top