Jump to content

Batch Script Tips and Tricks for XPCDs


Recommended Posts

Hi,

TNX for this thread, I red it very carefully because i'm very concerned by.

DarkShadows

Even more critical is something that could happen if you have more than one CD-ROM drive (which I do). Because the code you posted searches all drives, it will also search my second CD drive that I do not have CD in. At which time Windows will generate a dialog with a message stating that media is not ready in the drive (or something like that). I personally find this problematic.

You describe exactly my problem. I tried many advises for a while without success.

I've 2CDCD-ROM and I'm using a UA/WPI (WinXP+Appz) DVD. When I run it, after the WinXP install and restart, i got an error message: "'Windows No Disk' 'There is no disk in the drive. [Cancel] [Try Again] [Continue]" . I've to click 2 or 3 times on [Continue] then WPI started from the DVD.

Here my winnt.sif command

[GuiRunOnce]
%systemdrive%\install\wpi\wpi.cmd

@Yzöwl: I'm not a coder and don't want making mistakes. May you please help me merging

@echo off&Mode 55,3&Color f2&Title Script By YzOwl
for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
fsutil fsinfo volumeinfo %%a:|find "UWXPCD">nul 2>&1&&echo Your specified drive is -^> %%a:\
)
ping -n 4 127.0.0.1>nul&goto :eof

to my wpi.cmd here enclosed???

Regards

coucou

Link to comment
Share on other sites


@ coucou

All you need to do is use the template I've already posted!

Example just put everything, (from your file), between

  • echo Found CD-Rom as drive %CDROM%

and

  • exit

in the appropriate place.

<Edit>

Alternatively, if you don't want to use the 'label' method, below is the template for 'CD loaded' method

@echo off&setlocal enableextensions&call :findrive
if '%CDROM%' equ '' echo/CD-ROM not found&ping -n 4 127.0.0.1>nul&goto endit

:: put your commands below here (%CDROM% variable is set)


:: do not add or replace anything below here
goto :endit
:findrive
for /f "tokens=1,2 delims=\ " %%a in ('fsutil fsinfo drives^|find /v "Drives"') do call :findcd %%a
goto :eof
:findcd
fsutil fsinfo volumeinfo %1|find "CDFS">nul 2>&1&&set CDROM=%1&goto :eof
:endit
endlocal&goto :eof

Remember it's still only for XP and above

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

TNX YzOwl for the advise.

May you let me know if the script bellow is correct???

@echo off&Mode 55,3&Color f2&Title Script By YzOwl
for %%i in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
fsutil fsinfo volumeinfo %%i:|find "UWXPCD">nul 2>&1&&echo Your specified drive is -^> %%i:\
)
ping -n 4 127.0.0.1>nul&goto :eof
set CDROM=%%i:

REM Determine the WPI startup path.
REM if wpi should run off the cd the replace %~dp0 with %cdrom%.
set wpipath=%cdrom%\Software\WPI

REM Force resolution to needed size for wpi interface.
start %wpipath%\common\VideoChanger.exe 1024x768x32@85 -q

REM Hide this command window.
"%wpipath%\common\cmdow.exe" @ /hid

REM Font installation - the smooth and customizable way.
start /wait %wpipath%\common\fonts\fontinstaller.exe

REM Special registry tweak needed.
regedit /s "%wpipath%\common\wpi.reg"

REM Make WPI directory the current directory.
for /f "delims=: tokens=1" %%i in ("%wpipath%") do %%i:
cd "%wpipath%"

REM Start WPI and wait for its end
start /wait WPI.hta

REM Cleaning up the desktop.
del /s/q "%userprofile%\desktop\*.lnk"

REM Rebooting the sytem to finalize the installation process.
--shutdown.exe -r -f -t 20 -c "Reboot in 10 sec..."

exit

:end

Regards

coucou

Link to comment
Share on other sites

Firstly, you haven't used either of the templates I posted!

Secondly, some of the commands you are adding are incorrect.

Thirdly, my own preference, lose all the comment lines, (i.e those starting with REM).

<Edit>

First of all let me apologize to readers of this thread for answering an off topic question here.

Here is an idea of how I would use the template

@echo off&setlocal enableextensions

:: enter your CD label below e.g. set lab=UWXPCD (case insensitive)
set lab=

call :findrive

:: put your commands below here (%CDROM% variable is set)

pushd %CDROM%\Software\WPI\common
cmdow.exe @ /hid
start VideoChanger.exe 1024x768x32@85 -q
start /wait fonts\fontinstaller.exe
regedit /s wpi.reg
cd..
start /wait WPI.hta
popd
del /s/q "%userprofile%\desktop\*.lnk"
shutdown.exe -r -f -t 20 -c "Reboot in 20 sec..."

:: do not add or replace anything below here
endlocal&goto :eof
:findrive
set drv=c d e f g h i j k l m n o p q r s t u v w x y z
for %%a in (%drv%) do (
fsutil fsinfo volumeinfo %%a:|find /i "%lab%">nul 2>&1&&set CDROM=%%a:
)
goto :eof

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

Apologies to all readers of this thread too and sorry to pollute it... i'm not a coder although i try hardly.

Many TNX Yzöwl and sorry for bothering you.

Regards

coucou

Edited by coucou
Link to comment
Share on other sites

I Apologize for the slight off topicness of this, but Since noone berated Yzöwl :) for his most excellent explanation of redirects, I figured I'd contribute... As far as redirects, I've read that

  • 0>

is equivalent to

  • | (aka the pipe symbol).

Anyone heard of this?

Edited by JoeMSFN
Link to comment
Share on other sites

'0>' seems like a joke :

'1>' or '>' redirects STDOUT of preceding command to following file/port

'2>' redirects STDERR of preceding command to following file/port

'1>>' or '>>' appends STDOUT of preceding command to following file

'2>>' appends STDERR of preceding command to following file

'<' redirects following file/port to STDIN of preceding command

' | ' redirects STDOUT of preceding command to STDIN of following command

What is obvious is that the '>' and '>>' redirectors does execute only the preceding command ; where ' | ' redirector execute both preceding and following command.

And if you specify any number other than '1' or '2' before '>' or '>>', you get "access disallowed" ("accès refusé" in french) error...

You didn't test before posting that, did you ???

Link to comment
Share on other sites

Don't know, if anyone needs this, but you can use parametres in batch script with %1,%2,...( %1 for first, %2 for second,.....

parameter). So if you have the file test.cmd:

@echo off

echo %2 %1

exit

and call through command line:

"test.cmd there hello"

it will output "hello there"

It's a useless example, but just to point out, how it works.

With this you can get more variable batch files, for example the name of the CD or the file on CD, you're looking for.

Edited by Doc Symbiosis
Link to comment
Share on other sites

Great work DarkShadows.

But after some time I played with the scripts, I couldn't figure out, how to get the first free drive letter.

Only can get a list of all free drives with the following script:

@echo off

for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (

fsutil fsinfo drivetype %%a:|find "No such Root Directory">nul 2>&1&&echo/%%a:

)

pause&goto :eof

Thanks in advance.

Link to comment
Share on other sites

Great work DarkShadows.  But after some time I played with the scripts, I couldn't figure out, how to get the first free drive letter.  Only can get a list of all free drives with the following script:

:Start
@Echo Off
Setlocal enableextensions enabledelayedexpansion

:SetVars
Call :FreeDrvL

:Logic
:: Place your script command logic between :Logic and :End
:: (The %FreeDrvL% variable is set to your first available drive letter)
CLS
Echo.
Echo %%FreeDrvL%% = %FreeDrvL%
Echo.
Pause

:End
EndLocal
Goto :EOF

:: Only place called functions below this comment. Do NOT place an Exit
:: command anywhere in this script, if you plan to call it from
:: other batch scripts. Doing so will kill the parent script!

:FreeDrvL
Set SearchString="Error: The system cannot find the path specified."
For %%L In (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO (
IF {!FreeDrvL!}=={} fsutil fsinfo volumeinfo %%L:|Find /I %SearchString%> Nul 2>&1&&Set FreeDrvL=%%L:
)
Set SearchString=
Goto :EOF

:Notes

:: 1. This script is for WINDOWS XP ONLY! The command "fsutil" is only
:: supported in Windows XP or later.
::
:: 2. The "Setlocal enableextensions" command in the :Start section, is not
:: required, unless you have explicitly disabled command extensions
:: somewhere in: your Windows registry, Cmd.exe call, or a Setlocal
:: command in a parent command batch script calling this batch script.
:: Command extensions are enabled by default in Windows XP. Therefore,
:: if you haven't made any of the above mentioned changes, you can delete
:: "enableextensions" from the Setlocal command, and this script will work.
::
:: 3. The "Setlocal enabledelayedexpansion" command in the :Start section
:: is STRICTLY REQUIRED; it enables the !VariableName! expansion method.
:: This method allows code to check the dynamic status of an environmental
:: variable from within a For-In-Do loop. The %VariableName% method only
:: checks the value once just before execution. Therefore if you change
:: a variable from within a For-In-Do loop, !VariableName! will ALWAYS
:: pick up it's current value; however, %VariableName% will ONLY pick up
:: what the value was BEFORE the For-In-Do loop began.

Or this:

Method B:

:Start
@Echo Off
Setlocal enableextensions

:SetVars
Call :FreeDrvL

:Logic
:: Place your command batch script logic between :Logic and :End
:: At this point, The %FreeDrvL% variable has been set to your first
:: unused available drive letter.

CLS
Echo.
Echo First Free Drive Letter = %%FreeDrvL%% = %FreeDrvL%
Echo.
Pause

:End
EndLocal
Goto :EOF

:: Only place called functions below this comment. Do NOT place an Exit
:: command anywhere in this script, if you plan to call it from other
:: batch scripts, doing so will exit the parent script as well!

:FreeDrvL
Set SearchString="Error: The system cannot find the path specified."
For %%L In (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO (
If NOT Defined FreeDrvL (
fsutil fsinfo volumeinfo %%L:|Find /I %SearchString%> Nul 2>&1&&Set FreeDrvL=%%L:
)
)
Set SearchString=
Goto :EOF

:Notes

:: 1. This script is for WINDOWS XP ONLY! The command "fsutil" is only
:: supported in Windows XP or later.
::
:: 2. The "Setlocal enableextensions" command in the :Start section, and the
:: corresponding "Endlocal" command in the :End section aren't strictly
:: required, unless you have explicitly disabled command extensions
:: somewhere in: your Windows registry, Cmd.exe call, or a Setlocal
:: command in a parent command batch script calling this batch script.
:: Command extensions are enabled by default in Windows XP. Therefore,
:: if you haven't made any of the above mentioned changes, you can delete
:: these Setlocal and EndLocal commands, and this script will still work.

<Edits on 2005-07-13>

• Touched up Method A (and labled it Method A)

• Added Method B (inspired by Yzöwl's work below)

• Added FindFreeDriveLetter.zip download of both files.

Differences Between Method B and Yzöwl's work below

1) I've presented it in my command batch script template style

2) I use volumeinfo whereas Yzöwl's code uses drivetype

3) I have eliminated the need for the "Call :Check" and the :Check Label altogether in the code. This allows us to use just one label to self-contain the function.

I do not intend to take anything away from Yzöwl's contribution, I merely mean to add value to it.

Differences Between Method A and Method B

1) Method A requires delayed variable expansion Method B (like Yzöwl's code below) does not.

</Edits on 2005-07-13>

WARNING: This code is only for Windows XP

FindFreeDriveLetter.zip

Edited by DarkShadows
Link to comment
Share on other sites

@ Doc Symbiosis

Another method

@echo off&setlocal enableextensions
for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
fsutil fsinfo drivetype %%a:|find "No such Root Directory">nul 2>&1&&call :check %%a:
)

:: put your commands below here %drvlet% is set
:: example
echo/%drvlet%

endlocal&goto :eof
:check
if not defined drvlet set drvlet=%1&goto :eof

I have started at C: since I'm fairly sure you aren't wanting A: or B:

<Edit>

Usual stuff about only for XP and newer

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

Here Are Two One Long Line Cmd That Make A Basic Ua Work Area For Either A

CDROM Install Of The Apps , Or Harddrive Install Of The Apps, After XP Is Installed.

CDROM Install Ua Work Area

Echo Off && CLS && Mode 55,4 && Color 5e && Title Gsm MKUaDirForCD_Intall && Mkdir %SystemDrive%\XPCD %SystemDrive%\XPCD\Apps %SystemDrive%\XPCD\$OEM$ %SystemDrive%\XPCD\$OEM$\$$ %SystemDrive%\XPCD\$OEM$\$$\Fonts %SystemDrive%\XPCD\$OEM$\$$\Media %SystemDrive%\XPCD\$OEM$\$$\Resources %SystemDrive%\XPCD\$OEM$\$$\Resources\Themes %SystemDrive%\XPCD\$OEM$\$$\System32 %SystemDrive%\XPCD\$OEM$\$$\Web %SystemDrive%\XPCD\$OEM$\$$\Web\Wallpaper %SystemDrive%\XPCD\$OEM$\$1 %SystemDrive%\XPCD\$OEM$\$1\Drivers %SystemDrive%\XPCD\$OEM$\$1\Drivers\002_graphics %SystemDrive%\XPCD\$OEM$\$1\Drivers\004_sound %SystemDrive%\XPCD\$OEM$\$Docs "%SystemDrive%\XPCD\$OEM$\$Docs\All Users" "%SystemDrive%\XPCD\$OEM$\$Docs\All Users\Start Menu" "%SystemDrive%\XPCD\$OEM$\$Docs\All Users\Start Menu\Programs" %SystemDrive%\XPCD\$OEM$\$Progs

Hard Drive Install Ua Work Area

Echo Off && CLS && Mode 55,4 && Color 5e && Title Gsm MKUaDirForHD_Intall && Mkdir %SystemDrive%\XPCD %SystemDrive%\XPCD\$OEM$ %SystemDrive%\XPCD\$OEM$\$$ %SystemDrive%\XPCD\$OEM$\$$\Fonts %SystemDrive%\XPCD\$OEM$\$$\Media %SystemDrive%\XPCD\$OEM$\$$\Resources %SystemDrive%\XPCD\$OEM$\$$\Resources\Themes %SystemDrive%\XPCD\$OEM$\$$\System32 %SystemDrive%\XPCD\$OEM$\$$\Web %SystemDrive%\XPCD\$OEM$\$$\Web\Wallpaper %SystemDrive%\XPCD\$OEM$\$1 %SystemDrive%\XPCD\$OEM$\$1\Drivers %SystemDrive%\XPCD\$OEM$\$1\Drivers\002_graphics %SystemDrive%\XPCD\$OEM$\$1\Drivers\004_sound %SystemDrive%\XPCD\$OEM$\$1\Install %SystemDrive%\XPCD\$OEM$\$Docs "%SystemDrive%\XPCD\$OEM$\$Docs\All Users" "%SystemDrive%\XPCD\$OEM$\$Docs\All Users\Start Menu" "%SystemDrive%\XPCD\$OEM$\$Docs\All Users\Start Menu\Programs" %SystemDrive%\XPCD\$OEM$\$Progs                               

Link to comment
Share on other sites

@Yzöwl: At first very much thanks for the script to detect the first free drive letter. Works fine. Only thing is, that I wonder, were the variable %drvlet% comes from, because it isn't mentioned in the script before. Why does it have the right value?

Link to comment
Share on other sites

@Yzöwl: At first very much thanks for the script to detect the first free drive letter. Works fine.  Only thing is, that I wonder, were the variable %drvlet% comes from, because it isn't mentioned in the script before. Why does it have the right value?

Look closer at his code, it comes from the Set command in the IF condition:

:check
if not defined drvlet set drvlet=%1&goto :eof

Edited by DarkShadows
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...