Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista General Discussion > running batch files...

Reply
Thread Tools Display Modes

running batch files...

 
 
maya
Guest
Posts: n/a

 
      07-30-2007
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..
 
Reply With Quote
 
 
 
 
Jon
Guest
Posts: n/a

 
      07-30-2007
"maya" <> wrote in message news:f8l9jq$c8b$...
> 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



 
Reply With Quote
 
maya
Guest
Posts: n/a

 
      07-30-2007
Jon wrote:
> "maya" <> wrote in message
> news:f8l9jq$c8b$...
>> 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..

 
Reply With Quote
 
maya
Guest
Posts: n/a

 
      07-31-2007
Jon wrote:
> "maya" <> wrote in message
> news:f8l9jq$c8b$...
>> 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........


 
Reply With Quote
 
Jon
Guest
Posts: n/a

 
      07-31-2007

"maya" <> wrote in message news:f8nioc$60v$...
> Jon wrote:
>> "maya" <> wrote in message
>> news:f8l9jq$c8b$...
>>> 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


 
Reply With Quote
 
Joseph Morales
Guest
Posts: n/a

 
      08-22-2007
"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
 
Reply With Quote
 
Jon
Guest
Posts: n/a

 
      08-22-2007
"Joseph Morales" <> wrote in message
news:507C08F1-EB6D-418A-B961-...
> "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

 
Reply With Quote
 
Joseph Morales
Guest
Posts: n/a

 
      08-23-2007
"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
 
Reply With Quote
 
Jon
Guest
Posts: n/a

 
      08-23-2007

"Joseph Morales" <> wrote in message
news:65AACE0F-2F10-44E2-9224-...
> "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


 
Reply With Quote
 
Jon
Guest
Posts: n/a

 
      08-23-2007
"Jon" <> wrote in message
news:...
>
> "Joseph Morales" <> wrote in
> message news:65AACE0F-2F10-44E2-9224-...
>> "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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
In Vista, can .wps files be converted to .rtf files as a batch i.e.instead of one at a time? Mike Arnold Windows Vista General Discussion 4 03-20-2008 12:43 PM
Asking permission and batch files Rene Grothmann Windows Vista General Discussion 3 03-06-2008 03:05 PM
Running batch files as administrator change working directory corradolab@ngi.it Windows Vista General Discussion 1 01-07-2008 02:41 PM
UAC and batch files Wildcat Windows Vista General Discussion 3 12-12-2007 09:36 PM
Running Batch Files in VISTA Peeky Windows Vista General Discussion 8 06-24-2007 12:43 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59