running batch files...

M

maya

in previous systems I would put shortcuts to batch files on my desktop
and they would run fine if I just open the shortcuts.. in Vista batch
files don't run if you open shortcuts to them.. you have to navigate
your way to where they are in DOS shell and run them from there... is
there a way around this??

thank you..
 
J

Jon

maya said:
in previous systems I would put shortcuts to batch files on my desktop and
they would run fine if I just open the shortcuts.. in Vista batch files
don't run if you open shortcuts to them.. you have to navigate your way to
where they are in DOS shell and run them from there... is there a way
around this??

thank you..


Works fine here.

It may depend more on the particular code that you have in your batch files.
If you can post examples of code that fails then people may be able to
advise further.
 
M

maya

Jon said:
Works fine here.

It may depend more on the particular code that you have in your batch
files. If you can post examples of code that fails then people may be
able to advise further.


ok, thank you very much.. will further check this @ home tonight..
 
M

maya

Jon said:
Works fine here.

It may depend more on the particular code that you have in your batch
files. If you can post examples of code that fails then people may be
able to advise further.

ok, this is what I had to do... had to do a new batch file that calls
other batch file, put shortcut to it on desktop.. THAT worked.. don't
know why can't directly run batch file I orig wanted to run from
shortcut.. (code in said batch file:

@echo off
if "%OS%" == "Windows_NT" setlocal
rem
---------------------------------------------------------------------------
rem Start script for the CATALINA Server
rem
rem $Id: startup.bat 302918 2004-05-27 18:25:11Z yoavs $
rem
---------------------------------------------------------------------------

rem Guess CATALINA_HOME if not defined
set CURRENT_DIR=%cd%
if not "%CATALINA_HOME%" == "" goto gotHome
set CATALINA_HOME=%CURRENT_DIR%
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
cd ..

etc.....)

thank you........
 
J

Jon

maya said:
ok, this is what I had to do... had to do a new batch file that calls
other batch file, put shortcut to it on desktop.. THAT worked.. don't know
why can't directly run batch file I orig wanted to run from shortcut..
(code in said batch file:

@echo off
if "%OS%" == "Windows_NT" setlocal
rem ---------------------------------------------------------------------------
rem Start script for the CATALINA Server
rem
rem $Id: startup.bat 302918 2004-05-27 18:25:11Z yoavs $
rem ---------------------------------------------------------------------------

rem Guess CATALINA_HOME if not defined
set CURRENT_DIR=%cd%
if not "%CATALINA_HOME%" == "" goto gotHome
set CATALINA_HOME=%CURRENT_DIR%
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
cd ..

etc.....)

thank you........




Possibly what's happening is that you're running these batch files with the
'Run as administrator' option set.
This sets the starting directory to the system32 directory, rather than to
the location of the batch file (as it is if you run it non-elevated). Your
batch file seems to rely on the starting directory being set correctly.

So you could either put some code at the start of your batch file to change
to the directory in which it is located (if that is what you want)

[For a batch file named 'somename.bat', something like this might do it at
the start of the batch file.....

Set WD=%0
Set WD=%WD:somename.bat=%
cd /d %WD%

]


or set up a global environment variable 'CATALINA_HOME' to point to the
directory in which the 'bin' directory is situated, as your snippet of code
suggests, if that 'bin' directory is always in the same place.


You can do that via
Right-click Computer > Properties > Advanced System Settings > Environment
Variables
Click 'New' under 'System Variables'......
 
G

Guest

Jon said:
So you could either put some code at the start of your batch file to change
to the directory in which it is located (if that is what you want)
[For a batch file named 'somename.bat', something like this might do it at
the start of the batch file.....
Set WD=%0
Set WD=%WD:somename.bat=%
cd /d %WD%

I'm dealing with a similar problem. I have one bat file that calls another
bat file in the same directory, but I'm not sure which directory they'll both
be installed in. I just know they'll be in the same directory. When I run the
first bat file as an Administrator, the current directory changes to
Windows\System32, and it can't locate the second bat file to run it. Your
code example above returns the complete path to the bat file from the %0
parameter, including the bat file name itself. E.g.
C:\users\moralejf\documents\master.bat.
How can my bat file truncate this path to remove the bat file name, so as to
get only the directory path, e.g. C:\users\moralejf\documents? The
Set WD=%WD:somename.bat=%
line in your example is very mysterious to me, but if it is intended to
truncate the bat file name, it doesn't succeed in doing so (even if I change
somename.bat to the actual bat file name). Thanks in advance, Joseph
 
J

Jon

Joseph Morales said:
Jon said:
So you could either put some code at the start of your batch file to
change
to the directory in which it is located (if that is what you want)
[For a batch file named 'somename.bat', something like this might do it
at
the start of the batch file.....
Set WD=%0
Set WD=%WD:somename.bat=%
cd /d %WD%

I'm dealing with a similar problem. I have one bat file that calls another
bat file in the same directory, but I'm not sure which directory they'll
both
be installed in. I just know they'll be in the same directory. When I run
the
first bat file as an Administrator, the current directory changes to
Windows\System32, and it can't locate the second bat file to run it. Your
code example above returns the complete path to the bat file from the %0
parameter, including the bat file name itself. E.g.
C:\users\moralejf\documents\master.bat.
How can my bat file truncate this path to remove the bat file name, so as
to
get only the directory path, e.g. C:\users\moralejf\documents? The
Set WD=%WD:somename.bat=%
line in your example is very mysterious to me, but if it is intended to
truncate the bat file name, it doesn't succeed in doing so (even if I
change
somename.bat to the actual bat file name). Thanks in advance, Joseph


The first line retrieves the full path to the running batch file into WD ,
and the second line

Set WD=%WD:somename.bat=%

removes the string 'somename.bat' from it - but it's the name of the batch
file in which it appears rather than the one it is calling. So it would be
'a.bat' in the batch file 'a.bat', 'b.bat' in the batch file b.bat etc

This is lifted from the help documentation for 'set'. ie from 'set /?' at a
prompt......


"Environment variable substitution has been enhanced as follows:

%PATH:str1=str2%

would expand the PATH environment variable, substituting each occurrence
of "str1" in the expanded result with "str2". "str2" can be the empty
string to effectively delete all occurrences of "str1" from the expanded
output....... "

Hope this helps
 
G

Guest

Jon said:
and the second line
Set WD=%WD:somename.bat=%
removes the string 'somename.bat' from it ...

Thanks for the explanation! It turns out that I had a typo that was keeping
this from working -- I typed a 0 instead of an O in my filename. (I hate it
when that happens!)
Now your example works, and I also understand why it works.

Now, just to push my luck... Is there any way to not have to hard code the
bat file name? That way if I retitle the bat file later, it won't break the
code.
 
J

Jon

Joseph Morales said:
Thanks for the explanation! It turns out that I had a typo that was
keeping
this from working -- I typed a 0 instead of an O in my filename. (I hate
it
when that happens!)
Now your example works, and I also understand why it works.

Now, just to push my luck... Is there any way to not have to hard code the
bat file name? That way if I retitle the bat file later, it won't break
the
code.



Good question. It would be a laborious to have to hard code that into every
batch file, and would also cause problems if a batch file were renamed.

Looks like there's a similar discussion in this thread, with some code
samples in it. Looks like there is a more generic solution in there.......

"run as administrator" changes default directory
http://groups.google.com/group/micr...h+file"+administrator&rnum=1#70df42c859cb0ba0
 
J

Jon

Jon said:
Good question. It would be a laborious to have to hard code that into
every batch file, and would also cause problems if a batch file were
renamed.

Looks like there's a similar discussion in this thread, with some code
samples in it. Looks like there is a more generic solution in there.......

"run as administrator" changes default directory
http://groups.google.com/group/micr...h+file"+administrator&rnum=1#70df42c859cb0ba0


NB There's an elegant solution from 'cquirke' at the end of that thread ie
these 2 lines at the start of the batch file...

%~d0
CD %~dp0
 
J

Jon

Jon said:
NB There's an elegant solution from 'cquirke' at the end of that thread ie
these 2 lines at the start of the batch file...

%~d0
CD %~dp0

Oops, my bad, just the one line required....

CD %~dp0
 

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