Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch File to Search all drives

Posted on 2011-02-21
8
Medium Priority
?
828 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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 antispam), the admini…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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