HELP needed with Batch Script (.bat file)
HELP needed with Batch Script (.bat file)
I'm trying to write a .bat file which has script to detect if WINDOWS or WINNT folder are on harddisk0, if yes then ok, if no then return "Echo Error message". For now no worries about which partition on hdd0.
Thank you,
Thank you,
Last edited by spt60 on Fri Mar 14, 2008 1:14 pm, edited 1 time in total.
-
rkawakami
- Admin

- Posts: 10055
- Joined: Sun Jun 04, 2006 1:26 am
- Location: San Jose, CA 95120 USA
- Contact:
Not sure how to test for a specific hard drive by drive number but this will solve part of your problem: (line numbers for description only)
1 @echo off
2 if exist c:\windows\nul goto :yes
3 echo No Windows directory exists!
4 goto :end
5 :yes
6 echo Yes Windows exists!
7 :end
Line 1 forces all echoing of subsequent commands off.
Line 2 does the actual test to see of the "nul" device exists within the Windows directory of the C: drive. If it is found, control branches to the ":yes" label on line 5.
Line 3 starts the "no" section. Here the error message is displayed.
Line 4 control branches to the ":end" label.
Line 5 defines the start of the ":yes" section.
Line 6 displays a message that says the folder exists.
Line 7 is the label which defines the end of the folder test.
1 @echo off
2 if exist c:\windows\nul goto :yes
3 echo No Windows directory exists!
4 goto :end
5 :yes
6 echo Yes Windows exists!
7 :end
Line 1 forces all echoing of subsequent commands off.
Line 2 does the actual test to see of the "nul" device exists within the Windows directory of the C: drive. If it is found, control branches to the ":yes" label on line 5.
Line 3 starts the "no" section. Here the error message is displayed.
Line 4 control branches to the ":end" label.
Line 5 defines the start of the ":yes" section.
Line 6 displays a message that says the folder exists.
Line 7 is the label which defines the end of the folder test.
Ray Kawakami
X22 X24 X31 X41 X41T X60 X60s X61 X61s X200 X200s X300 X301 Z60m Z61t Z61p 560 560Z 600 600E 600X T21 T22 T23 T41 T60p T410 T420 T520 W500 W520 R50 A21p A22p A31 A31p
NOTE: All links to PC-Doctor software hosted by me are dead. Files removed 8/28/12 by manufacturer's demand.
X22 X24 X31 X41 X41T X60 X60s X61 X61s X200 X200s X300 X301 Z60m Z61t Z61p 560 560Z 600 600E 600X T21 T22 T23 T41 T60p T410 T420 T520 W500 W520 R50 A21p A22p A31 A31p
NOTE: All links to PC-Doctor software hosted by me are dead. Files removed 8/28/12 by manufacturer's demand.
Thanks for your help, however it's not really what I was asking, the problem is that Windows is not always on C: drive, right now in my lab there are PCs with Windows on D: or E: ... so I'm trying to make sure doesn't matter what drive letter Windows is on, it has to be on the first hard drive, which is hdd0. Sorry but this is how the lab setup.
-
ArtShapiro
- Senior Member

- Posts: 639
- Joined: Fri Oct 13, 2006 12:48 am
- Location: Lake Forest, CA
Does it matter that the windows directory doesn't have to be called anything in particular? Most folks leave it as WINDOWS but I've used WIN or W in the past. Gee, it could be GORBENFRANZ.
The set variable WINDIR gives you the precise location of the Windows directory - SET WINDIR will display it in your command prompt. It has been too long since I've had to deal with this stuff, so I can't instantly spout off how to incorporate that into your batch file.
Art
The set variable WINDIR gives you the precise location of the Windows directory - SET WINDIR will display it in your command prompt. It has been too long since I've had to deal with this stuff, so I can't instantly spout off how to incorporate that into your batch file.
Art
-
rkawakami
- Admin

- Posts: 10055
- Joined: Sun Jun 04, 2006 1:26 am
- Location: San Jose, CA 95120 USA
- Contact:
%windir% will expand to the complete path for the Windows directory. So line 2 above changes to:
if exist %windir%\nul goto :yes
if exist %windir%\nul goto :yes
Ray Kawakami
X22 X24 X31 X41 X41T X60 X60s X61 X61s X200 X200s X300 X301 Z60m Z61t Z61p 560 560Z 600 600E 600X T21 T22 T23 T41 T60p T410 T420 T520 W500 W520 R50 A21p A22p A31 A31p
NOTE: All links to PC-Doctor software hosted by me are dead. Files removed 8/28/12 by manufacturer's demand.
X22 X24 X31 X41 X41T X60 X60s X61 X61s X200 X200s X300 X301 Z60m Z61t Z61p 560 560Z 600 600E 600X T21 T22 T23 T41 T60p T410 T420 T520 W500 W520 R50 A21p A22p A31 A31p
NOTE: All links to PC-Doctor software hosted by me are dead. Files removed 8/28/12 by manufacturer's demand.
Hey guys thanks a lot for your quick helps, may I ask for 1 extra favor: since we now have the %windir% which has the drive letter in it, how do we know which harddisk that drive letter is in. An easy example can be %windir% = C:\WINDOWS but what's the command in batch to check if C is in harddisk0?
Can u help me with an example for this?
Can u help me with an example for this?
Another question is how do you extract a part of a string, example is if I have a string "Hello World", how do you extract "Hello" out of it in batch? Thanks!k2jsv wrote:You should just be able to replace the c:\windows etc with harddisk0/partition1/... blah blah blah.
ok I tried this:
if exist \Device\Harddisk0\Partition1\WINDOWS goto yupe
(with the purpose of checking to see if WINDOWS is in the 1st hdd and 1st partition, which is the lab's requirement)
although it returns no error and in fact there is WINDOWS on hdd0-partition1, cmd still stated the path is not exist
What do you think? Thanks for your help.
if exist \Device\Harddisk0\Partition1\WINDOWS goto yupe
(with the purpose of checking to see if WINDOWS is in the 1st hdd and 1st partition, which is the lab's requirement)
although it returns no error and in fact there is WINDOWS on hdd0-partition1, cmd still stated the path is not exist
What do you think? Thanks for your help.
-
rkawakami
- Admin

- Posts: 10055
- Joined: Sun Jun 04, 2006 1:26 am
- Location: San Jose, CA 95120 USA
- Contact:
The path does not exist because you are asking DOS to look for a subdirectory in the current root drive ("\") named Device (and further subdirectories located therein). Not sure how (or if) you can specify a particular drive or partition using non-DOS references. In other words, DOS expects drive and partitions to be defined as letter "drives", C:\, D:\, etc.
Ray Kawakami
X22 X24 X31 X41 X41T X60 X60s X61 X61s X200 X200s X300 X301 Z60m Z61t Z61p 560 560Z 600 600E 600X T21 T22 T23 T41 T60p T410 T420 T520 W500 W520 R50 A21p A22p A31 A31p
NOTE: All links to PC-Doctor software hosted by me are dead. Files removed 8/28/12 by manufacturer's demand.
X22 X24 X31 X41 X41T X60 X60s X61 X61s X200 X200s X300 X301 Z60m Z61t Z61p 560 560Z 600 600E 600X T21 T22 T23 T41 T60p T410 T420 T520 W500 W520 R50 A21p A22p A31 A31p
NOTE: All links to PC-Doctor software hosted by me are dead. Files removed 8/28/12 by manufacturer's demand.
-
RealBlackStuff
- Admin
- Posts: 17517
- Joined: Mon Sep 18, 2006 5:17 am
- Location: Mt. Cobb, PA USA
- Contact:
You can do this much simpler.
Copy/paste the lot below in your xxx.bat file:
@echo off
if exist %windir% goto yes
echo No Windows directory exists!
goto end
:yes
set str=%windir%
set str=%str:~0,1%
REM strip the 'windir' of everything but the first letter
REM which is the Drive the Windows directory is on.
REM you can now work with this variable %str% = Drive-Letter
echo %str%
echo This Letter is your DRIVE
REM the rest is just for working with different drives or whatever...
set dr1=c
set dr2=d
set dr3=e
if %str%==%dr1% goto :driveC
if %str%==%dr2% goto :driveD
if %str%==%dr3% goto :driveE
goto driveX
:driveC
echo Windows is on Drive C:\
goto end
:driveD
echo Windows is on Drive D:\
goto end
:driveE
echo Windows is on Drive E:\
goto end
:driveX
echo Funny, Windows is on Drive %str%:\
:end
Copy/paste the lot below in your xxx.bat file:
@echo off
if exist %windir% goto yes
echo No Windows directory exists!
goto end
:yes
set str=%windir%
set str=%str:~0,1%
REM strip the 'windir' of everything but the first letter
REM which is the Drive the Windows directory is on.
REM you can now work with this variable %str% = Drive-Letter
echo %str%
echo This Letter is your DRIVE
REM the rest is just for working with different drives or whatever...
set dr1=c
set dr2=d
set dr3=e
if %str%==%dr1% goto :driveC
if %str%==%dr2% goto :driveD
if %str%==%dr3% goto :driveE
goto driveX
:driveC
echo Windows is on Drive C:\
goto end
:driveD
echo Windows is on Drive D:\
goto end
:driveE
echo Windows is on Drive E:\
goto end
:driveX
echo Funny, Windows is on Drive %str%:\
:end
Lovely day for a Guinness! (The Real Black Stuff)
Check out The Boardroom for Parts, Mods and Other Services.
Check out The Boardroom for Parts, Mods and Other Services.
So there's no way we can tell if either c: d: or any drive letter is on which hard disk and partition using dos batch?rkawakami wrote:In other words, DOS expects drive and partitions to be defined as letter "drives", C:\, D:\, etc.
Special thanks to RealBlackStuff for all the codings
-
rkawakami
- Admin

- Posts: 10055
- Joined: Sun Jun 04, 2006 1:26 am
- Location: San Jose, CA 95120 USA
- Contact:
Using a format such like what's in the boot.ini file ("multi(0)disk(0)rdisk(0)partition(1)" or Linux ("\Device\Harddisk0\Partition1")? Not that I know of. If you are trying to do this within the DOS framework, then the only thing I know about how to check various disk drives and/or partitions is with drive letters.
RBS seems to have the answer to determine which drive letter is being used but I don't think that will tell you exactly which physical disk drive and/or partition that the Windows directory is resident on.
RBS seems to have the answer to determine which drive letter is being used but I don't think that will tell you exactly which physical disk drive and/or partition that the Windows directory is resident on.
Ray Kawakami
X22 X24 X31 X41 X41T X60 X60s X61 X61s X200 X200s X300 X301 Z60m Z61t Z61p 560 560Z 600 600E 600X T21 T22 T23 T41 T60p T410 T420 T520 W500 W520 R50 A21p A22p A31 A31p
NOTE: All links to PC-Doctor software hosted by me are dead. Files removed 8/28/12 by manufacturer's demand.
X22 X24 X31 X41 X41T X60 X60s X61 X61s X200 X200s X300 X301 Z60m Z61t Z61p 560 560Z 600 600E 600X T21 T22 T23 T41 T60p T410 T420 T520 W500 W520 R50 A21p A22p A31 A31p
NOTE: All links to PC-Doctor software hosted by me are dead. Files removed 8/28/12 by manufacturer's demand.
-
- Similar Topics
- Replies
- Views
- Last post
-
-
Possible 4th batch of x62's
by jaspen-meyer » Wed Feb 15, 2017 3:14 pm » in Thinkpad X6x Series incl. X6x Tablet - 11 Replies
- 2018 Views
-
Last post by dmdsoftware
Thu Jun 29, 2017 5:41 pm
-
-
-
SOLD : Thinkpad x62 third batch
by gaelga » Mon May 08, 2017 2:12 am » in Marketplace - Forum Members only - 5 Replies
- 522 Views
-
Last post by gaelga
Sat May 13, 2017 5:40 am
-
-
-
Fan trouble - 3000 N200 + Type 0769 - ESG ACPI Script for NHC > NOTEBOOK HARDWARE CONTROL
by MatMor » Sun Mar 12, 2017 12:12 pm » in 3000 Series Laptops - 0 Replies
- 2632 Views
-
Last post by MatMor
Sun Mar 12, 2017 12:12 pm
-
-
-
[Please help! Advise Needed!] Lenovo T400 BIOS
by AvilanceStudios » Mon Mar 27, 2017 4:09 pm » in ThinkPad T400/410/420 and T500/510/520 Series - 2 Replies
- 858 Views
-
Last post by AvilanceStudios
Tue Mar 28, 2017 6:10 pm
-
Who is online
Users browsing this forum: No registered users and 3 guests




