Solved

Batch script problems

Posted on 2010-08-17
75
1,094 Views
Last Modified: 2012-06-27
Hello,

I'm trying to write a batch script to determines if grub4dos has to start one operating system or another. First of all I want that it tries to boot Windows and if a file (bootmgr) it is not in the right place,it should boots Knoppix. It should be something like this :

start.bat

@echo off
cls
c:
cd \menuwind
grub
IF ERRORLEVEL 1 goto start_linux
:start_linux
cls
c:
cd \
grub

This is the menu.lst located into the C:\menuwind folder

title Windows
root (hd0,1)
chainloader (hd0,1)/winzozz/bootmgr

and this is the menu.lst located to the root of the disk :

title Knoppix
kernel /KNOPPIX/BOOT/ISOLINUX/LINUX. ramdisk_size=100000 2 toram lang=it vt.default_utf8=0 apm=power-off vga=791 nomce quiet loglevel=0 tz=localtime
initrd /KNOPPIX/BOOT/ISOLINUX/MINIRT.GZ

for "IF ERRORLEVEL 1" I mean that when the file (bootmgr) located at : (hd0,1)/winzozz/bootmgr is not there,the script should jump to the :start_linux label,but it does not work !  
0
Comment
Question by:marietto2008
  • 32
  • 23
  • 7
  • +3
75 Comments
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
As you have written it, it does not make sense. In particular, the combination of

IF ERRORLEVEL 1 goto start_linux
:start_linux

is useless - execution is always continued with start_linux, because there is no command after the IF ERRORLEVEL line ...

I suppose grub does not report back the failure of the menu commands, and you have no errorlevel hence. I would do as follows:

@echo off

cls

if exist c:\winzozz\bootmgr (

cd /D c:\menuwind

grub

) else (

cd /d c:\

grub

)

Open in new window

0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
I can't do as you suggest,because (hd0,1) is formatted with the NTFS file system and under DOS I have no read access to the NTFS file system,instead grub4dos can detect it.
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
Bad luck. I do not have the slightest clue of how grub works, and if it returns an error code if it can't access the bootfile.
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
I need to find a way to capture the error 15 : file not found from the buffer
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
you can try if the following works:

@echo off



:start_Win

cls

c:

cd \menuwind

grup | find "error 15:"

if errorlevel 1 goto EOF



:start_linux

cls

c:

cd \

grub



:EOF

Open in new window

0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
Why not just use a version of DOS which can read NTFS Disks?  Windows ME for instance has NTFS support on Boot disks it creates and is still a "Real Mode" DOS, also I believe "FreeDoss will work

ALSO!  Never CD!  Always stay put, and call items using full paths wherever possible!

NOTE: If you can't READ NTFS you can't CD to NTFS anyway!  Making the whole thought pointless.  SO if you CAN CD to NTFS then you can just check "IF EXIST"

Now, that that has all been said, I did a little digging for you, and I think you can accomplish everything in the script below! =)



@ECHO OFF
CLS
SET "WinRoot=/winzozz/bootmgr"
SET "
SET "WinBoot=NO"
FOR /F "Tokens=*" %%F IN (' Grub Find /bootmgr ') DO SET "WinBoot=GO"&SET "BootDev=%%F"
IF /I "%WinBoot%"=="GO" Grub chainloader %BootDev%%WinRoot%
IF /I "%WinBoot%"=="NO" Grub

Open in new window

0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
Sorry one too many "SET" commands!

@ECHO OFF
CLS
SET "WinRoot=/winzozz/bootmgr"&SET "WinBoot=NO"
FOR /F "Tokens=*" %%F IN (' Grub Find /bootmgr ') DO SET "WinBoot=GO"&SET "BootDev=%%F"
IF /I "%WinBoot%"=="GO" Grub chainloader %BootDev%%WinRoot%
IF /I "%WinBoot%"=="NO" Grub

Open in new window

0
 
LVL 26

Expert Comment

by:pony10us
Comment Utility
QCubed:

Okay, you have peaked my interest. Why "ALSO!  Never CD!  Always stay put, and call items using full paths wherever possible!"

I have done it both ways and not had any issues but you sound like there may be a potential hazard in the CD function.

I will look at the rest of this thread tomorrow to see what develops.
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
Because if you CD to a location that does not exist or is on another drive or is on a network share it will fail to CD, leave you where you stand and continue on to the next command as if nothing wrong had happened.  Leaving your script to be executing commands in the wrong place!

I used popd and pushd a few times and similarly was really ticked to find the wrong things had happened XD  now I always Map a network drive check the drive exists and use full location to ensure things like that don;t happen.

It's pretty annoying when you are trying to copy a share-point site into a new one and instead you end up copying your user directory! XD
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Good points QCubed.  Just a couple of other things I'll add.

First, while it often isn't done, you can check that pushd (my preference over cd) succeeds by checking ERRORLEVEL afterwards, for example:

PUSHD c:\temp
IF %ERRORLEVEL%==1 goto :error

This can also be simplified to:

PUSHD c:\temp || goto error

I believe PUSHD will also switch drives if needed, whereas CD needs a switch to do this.

Agree that network drives can be problematic.

Also, in the case where the name of the directory involved is generated programatically, like output of a FOR or DIR command, then I view it as less risky that the folder doesn't exist.

~bp
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
Very true, but it can still be access denied even if it does exist XD

Still more: For a network location or removable media you also run the risk of a disconnection leaving your COMMAND session to error on the next command, depending on the command issued it will just error or jump back to your user directory, or C:\ if your user directory isn't available somehow.

Now your script is oce again orphaned and running commands against the wrong location.
0
 
LVL 16

Expert Comment

by:t0t0
Comment Utility
Wow! Some pretty good discussion here...

Oh, btw prew... I like 'PUSHD c:\temp || goto error'. It's been ages since I've seen code like that - most notably from Qlemo (a true genius at times)...
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
Yeah, I have to agree with t0t0, that code is vNice.  Wasn't aware you could get that sexy with error levels!
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
Yes, we can! :D
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
This code :

@ECHO OFF
CLS
SET "WinRoot=/winzozz/bootmgr"&SET "WinBoot=NO"
FOR /F "Tokens=*" %%F IN (' Grub Find /bootmgr ') DO SET "WinBoot=GO"&SET "BootDev=%%F"
IF /I "%WinBoot%"=="GO" Grub chainloader %BootDev%%WinRoot%
IF /I "%WinBoot%"=="NO" Grub

does not work,it says :  Bad variable specification
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
try this instead.

@ECHO OFF
CLS
SET "WinBoot=NO"
FOR /F "Tokens=*" %%F IN (' Grub Find /bootmgr ^Find /I "(" ') DO SET "WinBoot=GO"
IF /I "%WinBoot%"=="GO" FOR /F "Tokens=*" %%F IN (' Grub Find /bootmgr ^Find /I "(" ') DO Grub chainloader %%F/winzozz/bootmgrSET "WinBoot=GO"&SET "BootDev=%%F"
IF /I "%WinBoot%"=="NO" Grub

Open in new window

0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
WHOOPS!  LOST MY PIPE!  Don't use the last one, try this one!

@ECHO OFF
CLS
SET "WinBoot=NO"
FOR /F "Tokens=*" %%F IN (' Grub Find /bootmgr ^| Find /I "(" ') DO SET "WinBoot=GO"
IF /I "%WinBoot%"=="GO" FOR /F "Tokens=*" %%F IN (' Grub Find /bootmgr ^| Find /I "(" ') DO Grub chainloader %%F/winzozz/bootmgrSET "WinBoot=GO"&SET "BootDev=%%F"
IF /I "%WinBoot%"=="NO" Grub

Open in new window

0
 
LVL 26

Expert Comment

by:pony10us
Comment Utility
Thank you again QCubed, Bill and Qlemo for the education. I have not experienced any issue with CD in the past but I can appreciate what you both mention. Since I do most of my testing on the local drive I am pretty certain of what directories I am using so that explains why it has never come up for me.

Sorry for jumping in your thread marietto but these three helping you are some of the best coders I have worked with and I always learn something from them.

:)
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
doesn't work : bad variable specification
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
can you scrub echo off (rem it or delete it) and let me know which line is throwing this?
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility

FOR /F "Tokens=*" %F IN (' Grub Find /bootmgr ^| Find /I "("') DO SET "WinBoot=GO"



Bad variable specification.

Open in new window

0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
looks like it doesn't like for loops, or there is a problem w/ the grub statement

try just running at the ccommand line:

Grub Find /bootmgr

and also at the command line:

FOR /F "Tokens=*" %F IN ("HELLO") DO ECHO %F
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
also can you give me a link to your grub for dos, and what version of windows did you make your boot disk in??
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
1) grub find /bootmgr

grub : unrecognized or failed command line parameters. Usage :
grub [options]

options : --bypass, --time-out=T, --hot-key=K, --duce, --chs-no-tune,
options: --config-file="FILE"

The options are case-sensitive,you must use lower-case letters. each option can be specified only once at most.
FILE can be specified in GRUB or DOS style. if FILE is led by the pair "#@' ,then a DOS filename follows.
FILE can also be some GRUB commands delimited by semi-colon,or the whole content of a menu file (again semi-colon delimits each line of the menu file).
FILE can be double-quoted (this is recommended,especially for use as embedded commands or menu).

2) FOR /F "Tokens=*" %F IN ("HELLO") DO ECHO %F ---> Bad variable specification.

3) you can find grub4dos here :
 
http://download.gna.org/grub4dos/

4) I did my boot disk using this tool :

http://www.cgsecurity.org/wiki/Create_a_TestDisk_FreeDos_LiveCD
0
 
LVL 26

Expert Comment

by:pony10us
Comment Utility
Just an observation but here is the result of #2 when I run it in a command window:

C:\>FOR /F "Tokens=*" %F IN ("HELLO") DO ECHO %F

C:\>ECHO HELLO
HELLO
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
maybe because I'm using FreeDOS ? I can't use DOS because I can't redistribuite the Microsoft files,it is against the EULA.
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
C:\>VER

FreeCom version 0.82 pl 3 XMS_Swap [Dec 10 2003 06:49:21]

AFAIK I can use another kind of command.com if it fixes the problem.
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
FreeDOS does not support FOR /F (as doesn't any non-NT DOS emulation).
I cannot find the supported commands of grub4dos anywhere, so I cannot help on that part.
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
Ok I'm using 4dos 8.0 FreeDOS 7.10 and FOR /F is supported :

FOR /F "Token=*" %F IN ("HELLO") DO ECHO %F
HELLO
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
this is what happens when I run your script :

grub : unrecognized or failed command line parameters. Usage :
grub [options]

options : --bypass, --time-out=T, --hot-key=K, --duce, --chs-no-tune,
options: --config-file="FILE"

The options are case-sensitive,you must use lower-case letters. each option can be specified only once at most.
FILE can be specified in GRUB or DOS style. if FILE is led by the pair "#@' ,then a DOS filename follows.
FILE can also be some GRUB commands delimited by semi-colon,or the whole content of a menu file (again semi-colon delimits each line of the menu file).
FILE can be double-quoted (this is recommended,especially for use as embedded commands or menu).

d:\start.bat [4] File not found ""
d:\start.bat [5] Usage : IF [/I] [NOT] condition ...
d:\start.bat [6] Usage : IF [/I] [NOT] condition ...
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
Yeah, Free-DOS is not a full implementation of DOS yet.  Also it was hard to figure out what was a Grub verses a Grub4 DOS command.  However two things we CAN Do based off this info!

Since you can't currently read NTFS we can use this to load windows:

 GRUB --config-file="Title Windows NT; root (hd0,1); chainloader (hd0,1)/winzozz/bootmgr"

OR

2. Freedos DOES have the ability to read NTFS with the right drivers loaded.

So therefore, we can use the IF Exist command and call the menu file instead.
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
1) If we use this :

GRUB --config-file="Title Windows NT; root (hd0,1); chainloader (hd0,1)/winzozz/bootmgr"

and the file bootmgr is not there,grub4dos starts in command line mode....

2) Yeah,the easiest solution is to find a free (and at least read) NTFS driver so that we can use the IF exist command,but I've tried to find it for a lot of time and I've not found anything. There are no free NTFS drivers for DOS all around. There is the read only ntfs driver from mark russinovich and bryce cogswell from sysinternals,it works good,but if you load into the RAM memory ELTORITO.sys driver + Read only NTFS driver you have not enough memory to run grub4dos. When you try to run it or nothing happens or it says : invalid code,unload a device driver or tsr.
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
can you load the driver in HIMEM? or a HIMEM.SYS analog?  the problem sounds like the driver is being loaded in the first 640K environment.

If you can;t read the NTFS disk we can;t check for the file's existence.  If you can't read NTFS you also have to call the full list menu as I did in the last command.


0
 
LVL 16

Expert Comment

by:t0t0
Comment Utility
Oh for heaven sake.... Can't you spot the problem in the comment as far back as ID: 33460068?

Firstly, the error message you're getting:

    Bad variable specification

Is NOT a standard DOS error message. Not one I've ever come across anyway.

Furthermore, it's plainly obvious 'find' is not one of Grub's command line options. It's also obvious there is a pipe missing between 'Grub' and 'Find' and because of this, Grub attempts to parse 'Find' as one of it's own command line options. I'm fairly confident that's where the problem is.

Please try the following code:


@echo off
setlocal enabledelayedexpansion
cd \menuwind

for /f "tokens=1,2 delims=/" %%a in ('grub^|find /i "chainloader"') do set chainloader=%%b
set chainloader=!chainloader: =!
   
if /i "%chainloader%"=="io.sys" (
   echo DOS
   echo Windows 95
   echo Windows 98
   echo Windows ME
   exit /b 0
)

if /i "%chainloader%"=="ntldr" (
   echo Windows NT
   echo Windows 2000
   echo Windows XP
   echo Windows 2003
   exit /b 0
)

if /i "%chainloader%"=="bootmgr" (
   echo Windows Vista
   exit /b 0
)

echo Linux
exit /b 0
0
 
LVL 16

Expert Comment

by:t0t0
Comment Utility
You might have to muck about with that code but that's as much as I know without playing with playing with Grub myself.

Sorry for being so vague...
0
 
LVL 16

Expert Comment

by:t0t0
Comment Utility
Instead of this

    FOR /F "Tokens=*" %F IN (' Grub Find /bootmgr ^| Find /I "("') DO SET "WinBoot=GO"

try this:

Grub|find /i "/bootmgr"
if not errorlevel 1 set WinBoot=GO
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
t0t0 pls read the rest of the discussion.
 
 She is using FreeDOS, hence the 'strange' output.
 
 Delayed Expantion is not supported.
 
 FOR was not supported, however she believes she found a version of  FreeDOS where it is supported, therefore yes we could not re-implement a  FOR
 
 She's unable to read NTFS, hence the dancing around the checking for files or calling files.
 
 We know how to check for the files, we know how to load the files or via  command.  We just need to get a driver to read NTFS.  Your script may  work if we do it without delayed expansion and if the chainloader she  was looking for were in the place she's running from.
 
 However it's actually on another disk, which is NTFS, and can't be  changed to, by default Grub4DOS only checks it's current root.

I'm currently working through this from an angle of if we can read NTFS then we can just check and see if the loader exists.

  I have already tried to run a find command similar to the one you are doing here, based off Grub commands I found on the internet, however that command did not work in Grub4DOS.

~Q
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 16

Assisted Solution

by:t0t0
t0t0 earned 50 total points
Comment Utility
Why not just use NTFSDOS.EXE... AFAIK, it's free.


0
 
LVL 16

Expert Comment

by:t0t0
Comment Utility
The reason for delayed expansion is the line 'set chainloader=!chainloader: =!' but this can just as well be 'set chainloader=%chainloader: =%'. I accidentally left the delayed expansion code in however, I have since moved the subtitution outside of the FOR loop. It's not needed.


0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
these are my configuration files :

autoexec.bat

@ECHO OFF
\DRIVERS\shsucdx.exe /D:CDROM001

config.sys

!DEVICE=\DRIVERS\himem.exe
!DEVICE=\DRIVERS\Eltorito.sys /D:CDROM001
!SHELL=\COMMAND.COM /E:256 /P
!FILES=20
!BUFFERS=20
!LASTDRIVE=Z

inside the memory has been loaded :

1) Eltorito.sys
2) 4DOS XMS (swapping initialized (271 K)
3) ntfsdos.exe (initialized 500KB of XMS cache)

when I run gru4dos it says : dos mem corrupt,first_mcb=025a
panic : MCB chain corrupted
system halted
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
t0t0 : I've renamed the file bootmgr to bootmgr_ and I run your script. It is started by making the boot of Windows,but that's not right,because there is no bootmgr file present. It should have started with linux
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
change your autoexec to:

LOADHIGH NTFSDOS.exe

0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
c:\loadhigh ntfsdos.exe

No UMBs; loading low "ntfsdos.exe"
initialized 500 KB of XMS cache

c:\grub.exe
dos mem corrupt,first_mcb=025a
panic : mcb chain corrupted
0
 
LVL 26

Assisted Solution

by:pony10us
pony10us earned 50 total points
Comment Utility
QCubed:

Don't you need to include the himem.sys in the config.sys file before running loadhigh?

From Microsoft Technet:

Remarks
Windows XP does not use this command. It is accepted only for compatibility with MS-DOS files.

To use the loadhigh command, you must include the dos=umb command in your Config.nt or equivalent startup file. For more information about the dos=umb command, see dos in Related Topics.

Before you can load a program into the upper memory area, you must install the Himem.sys extended memory manager. Use the device command in your Config.nt or equivalent startup file to install Himem.sys.

If you use the loadhigh command to load a program, Windows XP attempts to load it into the UMA. If there is insufficient space in the UMA, the program is loaded into conventional memory; the memory area used is not indicated.

The most convenient way to use the loadhigh command is to include it in your Autoexec.nt or equivalent startup file.

Top of page

0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
ok this is my new config.sys :

!DEVICE=\DRIVERS\himem.exe
!DOS=HIGH,UMB
!DEVICE=\DRIVERS\Eltorito.sys /D:CDROM001
!SHELL=\COMMAND.COM /E:256 /P
!FILES=20
!BUFFERS=20
!LASTDRIVE=Z

when Freedos starts it says :  Kernel : allocated 41 Diskbuffers = 21812 bytes in HMA

and then I do : loadhigh ntfsdos.exe : it starts correctly and then I try to run grub,but nothing happens.
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
P10, she had HIMEM actually I checked for that.

But I did forget about needing the HIGH,UMB statement, it's been a while man, a long while! XD  let me take a quick look at how I configured my Win 3.11 VM..
0
 
LVL 26

Expert Comment

by:pony10us
Comment Utility
QCubed:

I see that now. But it appears that adding the DOS=HIGH,UMB was necessary.  I was kind of acting on memory myself. I had to think back to my old 286 where I had one drive loaded with Win 3.0 and another with Win 3.1. I just remembered that you had to change something in both the autoexec.bat and config.sys.
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
THOSE were the days!

FYI looks like on my 311 I have it just

Device=HIMEM.SYS
DOS=HIGH
FILES=30

when I throw a MEM command DOS's Way I get 522 Free conventional
and 61 MB free Extended (XMS)



0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
freeram = 620,288 (before to load ntfsdos.exe)

loadhigh ntfsdos.exe
initialized 500 kb of xms cache

freeram = 307,504 (after having load ntfsdos.exe)

grub.exe : undefined error ---> not enough conventional memory left to run grub.exe
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
idea : we can load the ntfsdos.exe driver into the memory,make the check to see if on (hd0,1) there is the bootmgr and then unload the driver and start grub...now I'm looking for a way to unload a dos driver
0
 
LVL 16

Expert Comment

by:t0t0
Comment Utility
From a boot floppy or CD, if you enter the following command, it should tell you which OS is installed.

   ATTRIB C:\*

If you see NTLDR listed along with IO.SYS and MSDOS.SYS etc then you can boot to WinXP or whatever OS is installed. Different OS's will have different system files.

Is this any help to you?
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
maybe you haven't understood very well what is my situation :

A:\ here there are the system files of Freedos (Drivers,autoexec.bat,command.com,config.sys,kernel.sys)

c:

0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
C:\ there are all other files
A:\ and C:\ drives are located on the cd rom
hd (0,0) is the first hard disk ; (hd0,0) is the first ntfs reserved windows 7 partition and (hd0,1) is where the windows 7 files are saved.
on (hd0,1)/winzozz/ there are saved the windows installation files of windows 7. I want to start the installation of windows 7 chainloading bootmgr using the cd/rom of freedos
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
I think that I've been able to make it work everything correctly :

CONFIG.SYS

!DEVICE=\DRIVERS\HIMEM.EXE
!DOS=HIGH,UMB,AUTO
!DEVICE=\DRIVERS\UMBPCI.SYS
BUFFERS=11,0
FILES=60
LASTDRIVE=I
FCBS=1,0
STACKS=0,0
DEVICEHIGH=\DRIVERS\eltorito.SYS /D:CDROM001
SHELL=\COMMAND.COM C:\ /E:1280 /L:160 /U:160 /P /F

AUTOEXEC.BAT

@ECHO OFF
loadhigh shsucdx.exe /D:CDROM001
SET CDDRIVE=
FOR %%x 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 EXIST %%x:\AUTORUN.BAT SET CDDRIVE=%%x:
IF "%CDDRIVE%"=="" GOTO errormsg
%CDDRIVE%
CD \
REM Note that we do NOT 'call' AUTORUN.BAT, so we should not return
AUTORUN.BAT
:errormsg
ECHO ERROR: Failure loading; unable to find CD-ROM drive!
ECHO ERROR: If you have multiple CD-ROM drives, please remove the other
ECHO ERROR: CD-ROM discs and try again.  Otherwise your disc may be corrupt
ECHO ERROR: or the CD-ROM driver does not correctly support your system.
ECHO ERROR:
ECHO ERROR: Please reboot your computer now.
:loopforever
pause > NUL
GOTO loopforever

AUTORUN.BAT

@echo off
LoadHigh ntfsdos.exe /N /X

START.BAT

@echo off
cls
Set TAG="\winzozz\bootmgr"
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 If Exist "%%i:%TAG%" goto s_vista7

Set TAG="\winzozz\ntldr"
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 If Exist "%%i:%TAG%" goto s_xp

if not exist "%%i:%TAG%" goto s_linux

:s_vista7

cls
c:

if "%%i"="D" goto hd00
if "%%i"="E" goto hd01

:hd00

cls
c:
cd \s_vista7\hd00\
grub
goto fine

:hd01

cls
c:
cd \s_vista7\hd01\
grub
goto fine

:s_xp

cls
c:
cd \s_xp
grub
goto fine

:s_linux

cls
c:
cd \
grub

:fine

exit

can someone help me to optimizes START.BAT ? Thanks.
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
Hey, awesome.  Optimizing start-bat would be my speciality.  I prefer classic prep/main/subs/end style, but I willn't (yes it's a real word) be able to for 40 minutes while on my AM commute.  Likely someone will beet me to it by then.

I have Two Important questions for you though:

1.). What is the full command-set supported in FreeDOS - (A link to a web-page with the command list would be perfect!)

2.). Several options in your config sys are new to me, would you mind reposting it here with comment lines?

  I know I could probably just google all this info, but you've already done the work so it'll likely be easy for you to summarize the config.sys and post the link to the command reference before I get to a computer.
0
 
LVL 26

Expert Comment

by:pony10us
Comment Utility
I remember most of the commands listed in the config.sys but there is one line in particular that concerns me.

LASTDRIVE=I

That line was basically dropped after Windows 3.11 as it caused issues with Windows 95 and 98.
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
I found this GOOD website :

http://www.mdgx.com/mem7.htm

and it saves my ass. Go there,you will see that there nothing more to say. its *very* good. Anyway another problem is occurred. The read only NTFS driver that I'm using it is unable to read correctly the contents of the folders inside the NTFS partitions. So it is useless. So much work wasted.
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
Freedos use its own syntax. I don't know what it is and I'm not interested because it is very limited. With 4dos I can use a larger database of commands and structures.
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
FYI Start.bat is a bad name to use because START is a command (may not be in FreeDOS but still never name a batch script the same name as a command or another batch.)

As often happens I've been mega busy at work but I keep poking away in my spare time.  Okay attached is all three of your batch scripts re-done in my preferred style (it's worth noting you can drop some of the labels and in some cases all for them, however I use labels to denote separate sections of code because they are callable and close them with a like label and indenting change to help draw your attention to them.

Attached is ALL THREE Batch Files redone, however youc ould really do ALL of this in 1 autoexec script or do thsi in two batch files (AUTOEXEC and RUNGRUB) the AutoStart script isn't useful as a 2ndary script.


::---------------------------------------------------------------------------------::
:: Script Name: AUTOEXEC.BAT													   ::
::---------------------------------------------------------------------------------::
:Begin-Script
	@ECHO OFF
	:Start-Prep
		LOADHIGH shsucdx.exe /D:CDROM001
		SET "CDDRIVE=NOMATCH"
	:End-Prep
	:Start-Main
		FOR %%x 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 EXIST %%x:\AUTORUN.BAT SET CDDRIVE=%%x:
		IF /I "%CDDRIVE%"=="NOMATCH" GOTO Start-ErrorMsg
		%CDDRIVE%\AUTORUN.BAT
	:End-main
	GOTO End-Script
	:Start-ErrorMsg
		ECHO.
		ECHO --------------------------------------------------------------------------------
		ECHO -- ERROR: Failure loading: unable to find CD-ROM drive!					   --
		ECHO -- ERROR: If you have multiple CD-ROM drives, please remove the other CD-ROM  --
		ECHO -- ERROR:  discs and try again.  Otherwise your disc may be corrupt or the    --
		ECHO -- ERROR:  CD-ROM driver does not correctly support your system.			   --
		ECHO -- ERROR:																	   --
		ECHO -- ERROR: Please reboot your computer now.									   --
		ECHO --------------------------------------------------------------------------------
		ECHO.
	:End-ErrorMsg
	:Start-LoopForever
		PAUSE > NUL
		GOTO Start-LoopForever
	:End-LoopForever
:End-Script
:: You should never reach this point!
ECHO ________________________________________________________________________________
ECHO.
ECHO !!				-THE SCRIPT AUTOEXEC.BAT HAS REACHED THE END-				   !!
ECHO ________________________________________________________________________________
GOTO :EOF

::----------------------------------------------------------------------------::
:: Script Name: AUTORUN.BAT													  ::
::----------------------------------------------------------------------------::
:Begin-Script
	@ECHO OFF
	:Start-Prep
		LOADHIGH %CDDRIVE%\ntfsdos.exe /N /X
	:End-Prep
	:Start-Main

	:End-main
	GOTO End-Script
:End-Script
ECHO ________________________________________________________________________________
ECHO.
ECHO !!				-THE SCRIPT AUTORUN.BAT HAS REACHED THE END-				   !!
ECHO ________________________________________________________________________________
GOTO :EOF






::---------------------------------------------------------------------------------::
:: Script Name: RUNGRUB.BAT													   ::
::---------------------------------------------------------------------------------::
:Begin-Script
	@ECHO OFF
	CLS
	:Start-Prep
		Set "TAG=\winzozz\bootmgr"
		SET "CDDRIVE=NOMATCH"
	:End-Prep
	:Start-Main
		FOR %%x 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 EXIST %%x:\AUTORUN.BAT SET CDDRIVE=%%x:
		IF /I "%CDDRIVE%"=="NOMATCH" GOTO Start-ErrorMsg
		%CDDRIVE%\AUTORUN.BAT
	:End-main
	GOTO End-Script
	:Start-ErrorMsg
		ECHO.
		ECHO --------------------------------------------------------------------------------
		ECHO -- ERROR: Failure loading: unable to find CD-ROM drive!					   --
		ECHO -- ERROR: If you have multiple CD-ROM drives, please remove the other CD-ROM  --
		ECHO -- ERROR:  discs and try again.  Otherwise your disc may be corrupt or the    --
		ECHO -- ERROR:  CD-ROM driver does not correctly support your system.			   --
		ECHO -- ERROR:																	   --
		ECHO -- ERROR: Please reboot your computer now.									   --
		ECHO --------------------------------------------------------------------------------
		ECHO.
	:End-ErrorMsg
	:Start-LoopForever
		PAUSE > NUL
		GOTO Start-LoopForever
	:End-LoopForever
:End-Script
:: You should never reach this point!
ECHO ________________________________________________________________________________
ECHO.
ECHO !!				-THE SCRIPT RUNGRUB.BAT HAS REACHED THE END-				   !!
ECHO ________________________________________________________________________________
GOTO :EOF




::---------------------------------------------------------------------------------::
:: Script Name: RUNGRUB.BAT													   ::
::---------------------------------------------------------------------------------::
:Begin-Script
	@ECHO OFF
	CLS
	:Start-Prep
		SET "TAG=DEFAULT"
		SET "HDD=NOMATCH"
		SET Tags="winzozz\bootmgr", "winzozz\ntldr"
	:End-Prep
	:Start-Main
		FOR %%T IN (%Tags%) DO CALL :Start-Drive-Loop %%T
		IF/I "%Drv%"=="D" SET "HDD=hd00"
		IF/I "%Drv%"=="E" SET "HDD=hd01"
		C:
		CALL :Start-%TAG%
	:End-main
	GOTO End-Script
	:Start-Subroutines
		:Start-Drive-Loop
			SET "TTAG=%~1"
			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 If Exist "%%a:%TTAG%" SET "Drv=%%a"&SET "TAG=%TTAG%"
			GOTO :EOF
		:END-Drive-Loop
		:Start-winzozz\bootmgr
			CD C:\s_vista7\%HDD%\
			GRUB
			GOTO :EOF
		:End-winzozz\bootmgr
		:Start-winzozz\ntldr
			CD C:\s_xp
			GRUB
			GOTO :EOF
		:End-winzozz\ntldr
		:Start-DEFAULT
			CD C:\
			GRUB
			GOTO :EOF
		:End-DEFAULT
	:End-Subroutines

:End-Script
ECHO ________________________________________________________________________________
ECHO.
ECHO !!				-THE SCRIPT RUNGRUB.BAT HAS REACHED THE END-				   !!
ECHO ________________________________________________________________________________
GOTO :EOF

Open in new window

0
 
LVL 11

Accepted Solution

by:
Ben Personick earned 400 total points
Comment Utility
well whats the dif we just need to check "IF EXIST" or is it giving false positives and negatives?
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
your script is good,but I found a problem. I tried it on another computer and it didn't work. This computer has two hard disks and when you reboot,the hard disk n.1 is seen as n.2. For this reason D: is related to (hd1,0) and E: to (hd1,1). The sub-routine Start-Drive-Loop gives always the correct drive letter,but the values to put inside menu.lst can't be always right,because hard drives are seen inverted. Any workaround ?
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
I don't think that " IF /I " is correct,it causes these errors : (I renamed start.bat into go.bat)

c:\go.bat [11] Usage : IF [/I] [NOT] condition ...
c:\go.bat [12] Usage : IF [/I] [NOT] condition ...

/I is not necessary...
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
your script seems to make the memory too low. When I make dir inside D: or E: drive it says : running out of memory and I can't get the list of the files inside.  
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
Hey Marietto, the syntax may not be supported in '4DOS' I didn't see your posts till after I posted it, also I can definitely tighten the scripts up, or just be less fancy and do things more linearly similar to how you did.  I'm a little confused when yous aid it worked and then it didn't; though.

  Once I saw your problem about the HD letter I figured I would have to re-do this as GRUB commands as best I could but I've been at work nearly 20 hours so I haven't been able to spend too much time on it.  Sorry.
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
Since the NTFS drivers are giving to me a lot of troubles (and because they aren't free),I took the decision to don't use them.They are hungry of memory and they are unable to detect correcly the files inside the NTFS partitions. I've tought that the best thing to do is to make an unique menu.lst and save it on the root of the disk...something like this :

title 1) Start Linux (the first time you repair Windows choose this option)
kernel /KNOPPIX/BOOT/ISOLINUX/LINUX. ramdisk_size=100000 2 toram lang=it vt.default_utf8=0 apm=power-off vga=791 nomce quiet loglevel=0 tz=localtime
initrd /KNOPPIX/BOOT/ISOLINUX/MINIRT.GZ

title 2) Repair Windows Vista/7 on disk n.1 / partition n.1
root (hd0,0)
chainloader (hd0,0)/winzozz/bootmgr

title 3) Repair Windows Vista/7 su disk n.1 / partition n.2
root (hd0,1)
chainloader (hd0,1)/winzozz/bootmgr

title 4) Repair Windows Vista/7 on disk n.2 / partition n.1
root (hd1,0)
chainloader (hd1,0)/winzozz/bootmgr

title 5) Repair Windows Vista/7 on disk n.2 / partition n.2
root (hd1,1)
chainloader (hd1,1)/winzozz/bootmgr

title 6) Repair Windows XP on disk n.1 / partition n.1
root (hd0,0)
chainloader (hd0,0)/winzozz/ntldr

title 7) Repair Windows XP on disk n.2 / partition n.1
root (hd1,0)
chainloader (hd1,0)/winzozz/ntldr

Users have to try each option from 2 to 7 and use which one that works. It's not complicated at all,because everytime that they choose the wrong options,they can come back to the menu and they can choose another option very fastly.
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
If that si the case why not just try to  use the Grub commands

grub --config-file"--find-root /ntldr"

and

grub --config-file"--find-root /bootloader"

to find it
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
the command "--find-root /" does not exist AFAIK
0
 
LVL 2

Author Closing Comment

by:marietto2008
Comment Utility
Thanks to everyone for your help. You helped me a lot indirectly.
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
Thanks for the points, glad I could help, what did you end up doing?
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
read ID: 33483234
0
 
LVL 26

Expert Comment

by:pony10us
Comment Utility
Thank you and I agree with QCubed. It would be interesting see what you ended up with.
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
I took the decision to make a menu with 7 entries. After having chosen the first option,users should try the others,one by one. It is not a refined solution, but at least it's effective.
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
Ahh I see, thanks for the clarification I am glad we could get you an effective solution.  I apologize it could not be more refined though.
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
Two refined solution could be implemented,but I think that it tooks a lot of time to think about how to do :

1) when grub4dos chainload bootmgr or ntldr and don't find it,it gives error 19: could not find file,I think that there could be a solution to manage this error to do something else

2) there could be an automatic way to choose options by pressing the related key on the grub4dos menu,one by one until it finds the working one,but it could take a lot of time to do it.
0
 
LVL 2

Author Comment

by:marietto2008
Comment Utility
now I've posted another question. It is related to Knoppix. IF you know it very well please help me there,too :D

http://www.experts-exchange.com/OS/Linux/Setup/Q_26418912.html
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now