Solved

Batch File to Search all drives

Posted on 2011-02-21
8
787 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 83

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 83

Accepted Solution

by:
oBdA earned 500 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 83

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 83

Expert Comment

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

18 Experts available now in Live!

Get 1:1 Help Now