Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Batch File to Search all drives

Posted on 2011-02-21
8
Medium Priority
?
838 Views
Last Modified: 2012-05-11
I'm trying to right a batch file to search all drives for the ghost32.exe file and also to search all drives for the actual ghost file and once it finds both to actually run ghost to clone the machine and use the image file found. I need to replace the "d:\image.gho" with the path where the image file is actually found through the search because the drive letter may not always be "D". This will all be done from PE so I'm editing the startnet.cmd file in PE.  Your help is greatly appreciated. This is what I have so far:

wpeinit

@echo off & setLocal EnableDELAYedeXpansion

for %%d 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 %%d: (
      for /f "tokens=* delims= " %%a in ('dir/b %%d:\ghost32.exe 2^>nul') do (
        "%%a" -clone,mode=load,src=d:\image.gho,dst=1
      )
  )
)

wpeutil reboot


Thanks again
0
Comment
Question by:Tlavette
  • 4
  • 4
8 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 34946533
This will only search the root of the drives found; is that intentionally?
Anyway, try this:

@echo off & setLocal EnableDELAYedeXpansion
for %%d 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 %%d: (
      for /f "tokens=* delims= " %%a in ('dir /b %%d:\ghost32.exe 2^>nul') do (
        "%%d:\%%a" -clone,mode=load,src=%%d:\image.gho,dst=1
      )
  )
)
wpeutil reboot

Open in new window

0
 

Author Comment

by:Tlavette
ID: 34946691
oBda,

I had a /s in as well to search the subfolders but don't think I need it. the only question that i have in your solution is will this also search for the image.gho file? for instance if I boot from a thumb stick the and have the image.gho file on a dvd then ghost32, which is on the thumb stick might be on drive D if that what the thumbstick gets mounted to and the the image.gho file would be on say drive E if that what the CD drive was mounted too?
0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 34946823
Sorry, misunderstood you.
Here's an enhanced version:

@echo off
setlocal EnableDelayedExpansion
set DriveList=C D E F G H I J K L M N O P Q R S T U V W X Y Z

set Ghost=
echo Searching for ghost.exe:
for %%a in (%DriveList%) do (
  echo Drive %%a ...
  if exist "%%a:\ghost.exe" (
    echo ... found.
    set Ghost=%%a\ghost.exe
    goto :FindImage
  )
)
:FindImage
if "%Ghost%"=="" (
  echo ghost.exe not found in any of the following drives:
  echo %DriveList%
  pause
  goto :eof
)
set Image=
echo Searching for image.gho:
for %%a in (%DriveList%) do (
  echo Drive %%a ...
  if exist "%%a:\image.gho" (
    echo ... found.
    set Image=%%a\image.gho
    goto :Clone
  )
)
:Clone
if "%Image%"=="" (
  echo image.gho not found in any of the following drives:
  echo %DriveList%
  pause
  goto :eof
)
echo Starting cloning ...
ECHO "%Ghost%" -clone,mode=load,src=%Image%,dst=1
ECHO wpeutil reboot

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Tlavette
ID: 34946833
oBda,

I tried your scripted and it did find the ghost32.exe file and it ran it, but was looking for the image.gho file on the same drive as the ghost32 file and it didn't find the image file. Normally I might have a small image file on the thumb stick so it would be on the same drive letter, but sometimes and have larger images that I put on DVD and it would be on a different drive letter.

Thanks again for the help
0
 
LVL 85

Expert Comment

by:oBdA
ID: 34946888
Just in case: I just noticed that I forgot to mention in the updated script above that it's in test mode; it will only display the "ghost" and "wpeutil" commands, instead of executing them.
Simply remove the capitalized ECHOs to run it for real.
0
 

Author Comment

by:Tlavette
ID: 34947380
oBda,

This worked beautifully. The only thing that I had to tweak was changed the file name from ghost.exe to ghost32.exe and I had to add the colon (:) after the "%%a" for each "set" command. After doing that it worked like a charm. Thanks for the quick response and quick solution. Any suggested reading in this area would be greatly appreciated as well.

Thanks
0
 

Author Closing Comment

by:Tlavette
ID: 34947388
Great solution...quick and precise.
0
 
LVL 85

Expert Comment

by:oBdA
ID: 34947461
A very nice scripting resource is http://www.robvanderwoude.com/
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview

916 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