Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to make this batch file to remain aware of it sorce

2 views
Skip to first unread message

arun

unread,
Mar 12, 2004, 3:37:38 PM3/12/04
to
I am trying to run this batch file from a network share.
the purpose is to let the user run a batch file and depending on the
OS type to execute a command relevant to os.
I can not hard code the server name as this would be put on domain
controllers and there are quite a few of those.
The problem i have is the batch file even though running from the
network share makes local windows dir as current and thus fails to get
the path for remaining commands and fails with incorrect command,
pasted below is a portion of the script
-----------
%comspec% /c ver|find "XP" && echo os is xp && goto :Advancedclient

%comspec% /c ver|find "Microsoft Windows [" && echo os is 2003 && goto
:Advancedclient

:Advancedclient
capinst.exe /blablah *
goto :EOF
* script looks for this exe locally on the workstation where as
i want it to stay in the netowork share from where it is
executed

Please help
thx in advance
Ap

Todd Vargo

unread,
Mar 12, 2004, 6:48:31 PM3/12/04
to

"arun" <sum...@yahoo.com> wrote in message
news:e19b5834.04031...@posting.google.com...

This thread would be better answered in a group for NT related batch
discussions. But since you asked here...

What are all of the OSes that will be used on this network? Also, your
version testing does not actually use the errorlevel generated by "FIND".
And the syntax that is does use is incompatible with DOS based OSes. Try
this test to separate the platforms.

@echo off
rem Test for NT based OSes & goto :NTrelated
for %%? in (/) do goto Win9xME
echo OS is DOS.
goto :eof

:Win9xME
echo OS is Win9xME
goto :eof

:NTrelated
echo OS is NT based. alt.msdos.batch.nt
echo Batch is "%~nx0" and located at "%~dp0"
goto :eof

:eof
::(end of file)


For your other question, why not just hard code the UNC path to the
executable? You could map the network drive to a drive letter if you really
needed to, but ISTM, just providing the UNC path should usually be enough in
most cases.

--
Todd Vargo (remove hyphen to reply by email)

Matthias Tacke

unread,
Mar 13, 2004, 5:37:27 AM3/13/04
to
arun wrote:

Todd is right in that these ng's are more appropriate:
news:alt.msdos.batch.nt
news:microsoft.public.win2000.cmdprompt.admin

In the os w2k +newer you could use pushd popd to temporarily change
your current directory and return afterwards.
To show, how you can find out the elements of the running batch name,
see this batch and the output once invoked through a share once with
assigned drive letter.

::Origin.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
set /A Count=0
echo %%0 =%0
echo Full %%~f0=%~f0 &set oFull=%~f0
echo Drive %%~d0=%~d0 &set oDriv=%~d0
echo Path %%~p0=%~p0 &set oPath=%~p0
echo Name %%~n0=%~n0 &set oName=%~n0
echo Ext %%~x0=%~x0 &set oExte=%~x0
for /F "tokens=1-10 delims=\" %%A in ("%oPath%") do (
call :Extract "%%A" "%%B" "%%C" "%%D" "%%E" "%%F" "%%G" "%%H" "%%I" "%%J" )
goto :eof
:Extract
if [%oDriv:~0,2%]==[\\] echo/Servername: %~1 & shift
if [%oDriv:~0,2%]==[\\] echo/Sharename: %~1 & shift
:loop
set /A Count+=1
if [%~1]==[] goto :eof
echo/%Count%.Level dir :[%~1]
shift
goto :loop
::Origin.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

=====screen copy======================================================
C:\Test>\\mars\c\test\origin
%0 =\\mars\c\test\origin
Full %~f0=\\mars\c\test\origin.cmd
Drive %~d0=\\
Path %~p0=mars\c\test\
Name %~n0=origin
Ext %~x0=.cmd
Servername: mars
Sharename: c
1.Level dir :[test]

C:\Test>m:\test\origin
%0 =m:\test\origin
Full %~f0=m:\test\origin.cmd
Drive %~d0=m:
Path %~p0=\test\
Name %~n0=origin
Ext %~x0=.cmd
1.Level dir :[test]

C:\Test>
=====screen copy======================================================

--
Greetings
Matthias

0 new messages