Welcome to the Microsoft Windows Vista Community Forums - Vistaheads, YOUR Largest Resource for Windows Vista related information.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so , join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|
|
running batch files...
microsoft.public.windows.vista.general
|
Click On Your Flag for Translation
|

07-30-2007
|
|
|
|
running batch files...
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..
|
|

07-30-2007
|
|
|
|
Re: running batch files...
"maya" <maya778899@yahoo.com> wrote in message news:f8l9jq$c8b$1@aioe.org...
> 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.
--
Jon
|
|

07-30-2007
|
|
|
|
Re: running batch files...
Jon wrote:
> "maya" <maya778899@yahoo.com> wrote in message
> news:f8l9jq$c8b$1@aioe.org...
>> 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.
ok, thank you very much.. will further check this @ home tonight..
|
|

07-31-2007
|
|
|
|
Re: running batch files...
Jon wrote:
> "maya" <maya778899@yahoo.com> wrote in message
> news:f8l9jq$c8b$1@aioe.org...
>> 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.
>
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........
|
|

07-31-2007
|
|
|
|
Re: running batch files...
"maya" <maya778899@yahoo.com> wrote in message news:f8nioc$60v$1@aioe.org...
> Jon wrote:
>> "maya" <maya778899@yahoo.com> wrote in message
>> news:f8l9jq$c8b$1@aioe.org...
>>> 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.
>>
>
> 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'......
--
Jon
|
|

08-23-2007
|
|
|
|
Re: running batch files...
"Jon" wrote:
> 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
|
|

08-23-2007
|
|
|
|
Re: running batch files...
"Joseph Morales" <JosephMorales@discussions.microsoft.com> wrote in message
news:507C08F1-EB6D-418A-B961-4F4736CE754B@microsoft.com...
> "Jon" wrote:
>> 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
--
Jon
|
|

08-23-2007
|
|
|
|
Re: running batch files...
"Jon" wrote:
> 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.
--
Joseph Morales
|
|

08-23-2007
|
|
|
|
Re: running batch files...
"Joseph Morales" <JosephMorales@discussions.microsoft.com> wrote in message
news:65AACE0F-2F10-44E2-9224-D8FE9D2CDA4A@microsoft.com...
> "Jon" wrote:
>> 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.
> --
> Joseph Morales
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/micro...df42c859cb0ba0
--
Jon
|
|

08-23-2007
|
|
|
|
Re: running batch files...
"Jon" <Email_Address@SomewhereOrOther.com> wrote in message
news:Oy9Wj2R5HHA.4436@TK2MSFTNGP03.phx.gbl...
>
> "Joseph Morales" <JosephMorales@discussions.microsoft.com> wrote in
> message news:65AACE0F-2F10-44E2-9224-D8FE9D2CDA4A@microsoft.com...
>> "Jon" wrote:
>>> 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.
>> --
>> Joseph Morales
>
>
>
> 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/micro...df42c859cb0ba0
>
> --
> Jon
>
>
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
--
Jon
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +1. The time now is 16:22.
|
|