Solved

Batch File to Search all drives

Posted on 2011-02-21
8
796 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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 …
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

775 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