Problem with variable Drive setup for XP/W98SE

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
penpen
Expert
Posts: 1992
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Problem with variable Drive setup for XP/W98SE

#16 Post by penpen » 17 Feb 2021 08:51

ispy wrote:
17 Feb 2021 07:11
Anyway - @ Penpen tried your script in XP it very briefly opened the command prompt then disappeared even with a pause command within it as you mentioned. Then as you stated, tried it with %temp%\ as well same result. Tried enclosing in "" quotes same result.
Then I went to 98SE and it worked with the double quotes and the %temp%\ addition with and without quotes. It reported back: Your drive is C: press any key to continue... So I then removed the %temp%\ & quotes it still works in 98SE. If you are wondering about the colon after "C" I added it just as a test within "prompt set drive=$N:$_" line. You could also add the colon after the echo Your Drive is %drive%: line but the variable would read "C" only so its a visual not actual effect.
I wonder why you get different results (something like that always makes me curious).
My result on Win98 SE, when called from within command.com:

Code: Select all

Z:\with space>test

Z:\with space>echo exit | "C:\WINDOWS\COMMAND.COM" /k prompt set drive=$N:$_ | f
ind "set" >"C:\WINDOWS\TEMP\Tempdrv.bat"

Z:\with space>echo.>>"C:\WINDOWS\TEMP\Tempdrv.bat"

Z:\with space>Call "C:\WINDOWS\TEMP\Tempdrv.bat"

Z:\with space>set drive=Z:

Z:\with space>
Z:\with space>

Z:\with space>echo Z:
Z:

Z:\with space>pause
Weiter mit beliebiger Taste . . .
My results on Win XP, when called from within command.com:

Code: Select all

Z:\WITHSP~1>test

Z:\WITHSP~1>echo exit   | "C:\WINDOWS\system32\cmd.exe" /k prompt set drive=$N:$_
  | find "set"  1>"C:\WINDOWS\TEMP\Tempdrv.bat"

Z:\WITHSP~1>echo.1>>"C:\WINDOWS\TEMP\Tempdrv.bat"

Z:\WITHSP~1>Call Tempdrv

Z:\WITHSP~1>set drive=Z:

Z:\WITHSP~1>Echo Z:
Z:

Z:\WITHSP~1>pause
Drücken Sie eine beliebige Taste . . .
My results on Win XP and Win 10, when called from within cmd.exe:

Code: Select all

Z:\with space>test

Z:\with space>echo exit   | "C:\WINDOWS\system32\cmd.exe" /k prompt set drive=$N:$
_   | find "set"  1>"C:\DOKUME~1\TEST\LOKALE~1\Temp\Tempdrv.bat"

Z:\with space>echo.1>>"C:\DOKUME~1\TEST\LOKALE~1\Temp\Tempdrv.bat"

Z:\with space>Call Tempdrv

Z:\with space>set drive=Z:

Z:\with space>Echo Z:
Z:

Z:\with space>pause
Drücken Sie eine beliebige Taste . . .
Similar results for pathes without spaces (only the pathname changes).

Then i thought about clicking on the icon and got pretty similar results, except for windows 98SE, where i got:

Code: Select all

Befehl oder Dateiname nicht gefunden.
(German for: Command or file name not found.)
That error is probably a bug in Win 98 SE and not caused by the script, even the following "test2.bat" gave the same result:

Code: Select all

echo test2
A workaround is, to create a link/shortcut to batch file and execute that link/shortcut (that works, because it replaces the name with space by a short path name that doesn't contain spaces, which in my case is "Z:\WITHSP~1\TEST.BAT")
So in Windows 98 you probably use links/shortcuts to batch files and avoid double clicking on batch files which are located in pathes with spaces.
Because you probably have to recreate the link/shortcut, whenever you change the location (for example the volume name, when using a usb-stck), that is not a good option - so you probably should avoid using path names with spaces.

But the odd thing is, that for you, the xp execution doesn't work properly, which works perfectly fine for all my system (native and vbox, without a difference).
That is somehow puzzling to me :? !
Could you open a "cmd.exe"-window, start that batch file there and copy paste the content of the screen (you might also want to anonymize private data like your username in pathes, if they show up)?


Sidenote: I just noticed, that you could remove the "echo.>>..."-line:

Code: Select all

echo exit | "%ComSpec%" /k prompt set drive=$N:$_ |find "set" >"%temp%\Tempdrv.bat"
Call "%temp%\Tempdrv.bat"
Echo %drive%
pause
(And in theory if you are clicking on the batch files, then the all except the first line is just a demonstration that the first line worked.)


penpen

ispy
Posts: 16
Joined: 25 Dec 2020 15:36

Re: Problem with variable Drive setup for XP/W98SE

#17 Post by ispy » 17 Feb 2021 12:04

Hi Penpen :D ,

I have tried to send you a private message, well several in fact but when I click on the send button it doesn't seem to flag up that something has been sent in the outbox. Edit - I think it may have been sent finally phew

Best Regards,

Ispy

ispy
Posts: 16
Joined: 25 Dec 2020 15:36

Re: Problem with variable Drive setup for XP/W98SE

#18 Post by ispy » 20 Feb 2021 13:47

Hi folks :D

Just to give an update to where I am up to with trying to write a batch file that is both compatible in XP & Windows 98SE, Although I think with the right skill set it can be done, I have decided to write respective batch files for each OS and branch with a "goto" :label to make things more specific to each OS. What I have come up with may be slightly unorthodox but I can report it works on my system.

Firstly will give originally suggested by pieh-ejdsch a further attempt in 98SE & XP. Penpen bug-fixed the original code & looked at why it was not working in my XPSP3 OS the new code is as follows for setting the drive variable:

Code: Select all

@echo off
echo exit | %ComSpec% /k prompt set drive=$N:$_ |find "set" >"%temp%\Tempdrv.bat"
call "%temp%\Tempdrv.bat"
echo Your Drive is %drive%
pause
This is the above batch code altered to include CWD Current working Dir with setup cleaning vars and cleanup Temp files deletion:

Code: Select all

@echo off
set DRV=
set CWD=
echo exit | %ComSpec% /k prompt set DRV=$N:$_ |find "set" >"%temp%\T1.BAT"
echo exit | %ComSpec% /k prompt set CWD=$P$_ |find "set" >"%temp%\T2.BAT"
Call "%temp%\T1.BAT"
Call "%temp%\T2.BAT"
del "%temp%\T?.BAT"
echo Your Drive is %DRV%
echo Your CWD is %CWD%
pause
The difference being the Comspec is not enclosed in double quotes "ComSpec" because of a setting that is in my environment variables /E:4096 CMD. to adjust/amend value. In XP open Control panel>System>Advanced tab>Environment Variables>Within System Variables window I removed /E:4096 I can report the batch file now works so the new Batch files under review & both work in XP & Windows 98SE are as follows:
Windows 98SE:

Code: Select all

@echo off
set CWD=
set DRV=
>T1.BAT echo @prompt set CWD=$P
>T2.BAT command /c T1.BAT
call T2.BAT
>T3.BAT echo @prompt set CD=$N:
>T4.BAT command /c T3.BAT
call T4.BAT
del T?.BAT
echo CurrentDRV = %DRV%
echo CurrentDIR = %CD%
Pause
The set statements are just to clear any previous variables, this bat file sets up both your current drive & Current Dir. Disadvantages are it needs temporary T.BAT files not really a good idea if working from read-only write protected sources. The last 3 lines of the bat file are only really there for testing purposes and can be omitted.

Batch file for Windows XP:

Code: Select all

@echo off
set DRV=
set CWD=
set "DRV=%cd:\="&rem %
set "CWD=%CD%"
echo Your Drive is %DRV%
echo Your CurDir is %CWD%
pause
In XP for me it was a lot easier to set both variables 3rd & 4th lines as with XP Cd there are many ways of doing this for example here are some alternatives depending on what you want to achieve.

Code: Select all

@echo off&setlocal
set CWD=
set CWD=%~dp0
if %CWD:~-1%==\ set CWD=%CWD:~0,-1%
echo Your Current Working dir is %CWD%
:: Using for command without trailing back slash
for %%i in ("%~dp0.") do set "CD=%%~fi"
echo Your Cdir is %CD%
for %%a in ("%cd%") do set "CurDir=%%~nxa"
echo Your Working Folder is %CurDir%
echo IF you want current path in both batch
echo or within commandline use %cd% and %~dp0
echo is only available within batch files.
echo The current directory is (Percent sign or shift<5> keys)cd(Percent Sign or shift<5> keys)
echo.%__CD__:~0,-1%
echo your Current Drive IS
for %%A in ("%CD%") do echo.%%~dA
pause
In respect of the contribution made by Jeb below it kinda works in the respect of saying the drive is unknown. I have tried using Dbl click method to open the bat file along with opening the command prompt navigating to the folder where the bat file is situated and ran from command prompt but it still fails for me even with the environmental setting altered. It however worked in Windows 98SE.

Code: Select all

@echo off
if "%1" == "" goto :main
goto %1

:main
set drv=unknown
%comspec% /c %0 :getdrv > drvtmp.bat
call drvtmp.bat
echo my drive is: %drv%
goto :eof

:getdrv
prompt set drv=$N
echo on
%=must be empty=%
@echo off

:eof
Maybe someone can adapt the above code to work as an alternative to PiehE's/Penpens code to provide a second working alternative. It's a shame that CD \ only seems to work @ the command-line requiring an enter key-press to make it work rather than in batch as CD works in both XP & W98SE.

I would just like to take this opportunity to thank everyone who has contributed to this post it's all a learning experience which hopefully others who visit this forum can benefit from too.

Best Regards,

Ispy :D

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Problem with variable Drive setup for XP/W98SE

#19 Post by Samir » 07 Mar 2022 18:43

This is definitely a fascinating thread as I remember seeing batch files back in the day from publishers as they wrestled with the same problems with their program installations from cd-roms. I know a lot of companies like Toshiba made a small .com program that would report back the current path (like cd shows) so they could use it in their installation batch. I need to see if I can dig up some of these old things and see if there's something there that would be of interest to post. :D

Post Reply