Jump to content

*SOLVED* Image WIM Script, One Problem To Figure Out


Recommended Posts

I have a script configured to automatically reimage a computer by simply answering yes...

There is one snafu though, it seems that different computers like to grab the USB drive and give it different letters, I guess this is due to a computer having a cd/dvd drive or sd slot etc...

I would like for my script to find the USB drive by doing this (yes it's cheesy but in a small scale test it worked)

If FileExits ( 'driveletter:\USE.THIS.DRIVE.txt' ) Then
 RunWait ( 'driveletter:\windows\system32\imagex /apply 1 C:\', '', @SW_HIDE )

My question is how can I have it look for that file on each possible drive letter and when it locates that file, use that drive as my DRIVE LETTER or

just have it run my script with appropriate drive letter and after Imagex runs, continue with the rest of the script (basically just informing the user that the computer is going to reboot)

It's confusing to explain so I hope I've done a good job... I will make sure that the thumbdrive has a unique file name on the root

UPDATE:

The script in my last post was the answer I was looking for

Thanks to all (again)

Edited by Elephant007
Link to comment
Share on other sites

Are you trying to get the drive letter that the script is being run from? If so you can use @ScriptDir and parse that to get the drive letter from it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

My question is how can I have it look for that file on each possible drive letter and when it locates that file, use that drive as my DRIVE LETTER

An example:

Global $driveletter = ""
$uniquefile = "yourunique.file"
$aDrive=DriveGetDrive("ALL")

For $i=1 to $aDrive[0]
    If FileExists($aDrive[$i] & "\" & $uniquefile) Then
    $driveletter = $aDrive[$i]
    ExitLoop
    EndIf
Next

If $driveletter = "" Then
    MsgBox(0,"No Luck", "I didn't find the file on any drive")
Else
    MsgBox(0,"Yes", "I've found the file on " & $driveletter)
EndIf

Note: Take a look to DriveGetDrive because you can search for only FIXED, REMOVABLE, etc drives.

Link to comment
Share on other sites

Are you trying to get the drive letter that the script is being run from? If so you can use @ScriptDir and parse that to get the drive letter from it.

Oh! That is nice to know, unfortunately the script is running from X:\ which is WinPE..

Thank you for the information though because it will become useful

An example:

Global $driveletter = ""
$uniquefile = "yourunique.file"
$aDrive=DriveGetDrive("ALL")

For $i=1 to $aDrive[0]
    If FileExists($aDrive[$i] & "\" & $uniquefile) Then
    $driveletter = $aDrive[$i]
    ExitLoop
    EndIf
Next

If $driveletter = "" Then
    MsgBox(0,"No Luck", "I didn't find the file on any drive")
Else
    MsgBox(0,"Yes", "I've found the file on " & $driveletter)
EndIf

Note: Take a look to DriveGetDrive because you can search for only FIXED, REMOVABLE, etc drives.

This one looks like what I need, I will begin testing right now and let you know results as quickly as possible
Link to comment
Share on other sites

Odd, when I run a test from my Windows 7 box it works flawlessly

When I run it in a WinPE it doesn't work

Now if I have WinPE open a cmd prompt and I type in my autoit script executable (imager.exe) it works

With that in mind, I might have WinPE start a batch file that simple opens imager.exe

What the...

#include <GUIConstantsEx.au3>
#include <String.au3>

Global $driveletter = ""

$uniquefile = "keep.this.on.root.txt"
$aDrive=DriveGetDrive("ALL")
For $i=1 to $aDrive[0]
    If FileExists($aDrive[$i] & "\" & $uniquefile) Then
    $driveletter = $aDrive[$i]
    ExitLoop
    EndIf
Next

$ImageCmpt = MsgBox ( 1 , "Image", "Do you want to Image this computer?" & @CRLF & "Okay = Proceed with Image" & @CRLF & "Cancel = Reboots Comptuer" )
If $ImageCmpt = 1 Then
SplashTextOn ( "Format", "Formatting Disk 0", 200, 100, 200, 400 )
RunWait ( "diskpart /s x:\Windows\System32\dsk\prepdisk", "", @SW_HIDE )
SplashOff ()
SplashTextOn ( "Applying Image", "Imaging Disk 0" & @CRLF & "Will Reboot when complete", 200, 100, 200, 400 )

If $driveletter = "" Then
    MsgBox(0,"No Luck", "file not found on any drive")
Else
    RunWait ( "X:\Windows\System32\imagex /apply " & $driveletter & "\Image\AISDImage.wim 1 C:\", "", @SW_HIDE )
EndIf
EndIf
SplashOff()
SplashTextOn ( "Reboot...", "Rebooting Computer" & @CRLF & "Remove thumbdrive", 200, 100, 200, 400 )
Sleep ( 5000 )
SplashOff()

Here's how I tweaked the code

my attempt to have a batch file run imager.exe still failed to locate my thumbdrive

I'm about tempted to put the AISDImage.wim inside the BOOT.WIM (which becomes X) haha

UPDATE:

When I have WinPE bring up a cmd prompt and I type in imager.exe it works without a problem

Perhaps I can write my script to where it will bring up GImageX when the script can't find the thumbdrive that has the WIM image on it

I was trying to make this a simple as possible for our field tech, I should say as automated as possible...

Any other ideas?

Edited by Elephant007
Link to comment
Share on other sites

just have starnet.cmd kick off your script?

make sure the first line of startnet.cmd is/remains wpeinit.

and putting everything inside the boot.wim is not a horrible plan thats how i do my action

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

just have starnet.cmd kick off your script?

make sure the first line of startnet.cmd is/remains wpeinit.

and putting everything inside the boot.wim is not a horrible plan thats how i do my action

Now there's an idea

would I have to remove the wpeinit from startnet.cmd and put imager.exe in its place?

I think I have it figured out, I change the order of the script

#include <GUIConstantsEx.au3>
#include <String.au3>

Global $driveletter = ""

$ImageCmpt = MsgBox ( 1 , "Image", "Do you want to Image this computer?" & @CRLF & "Okay = Proceed with Image" & @CRLF & "Cancel = Reboots Comptuer" )
If $ImageCmpt = 1 Then
$uniquefile = "keep.this.on.root.txt"
$aDrive=DriveGetDrive("ALL")
For $i=1 to $aDrive[0]
    If FileExists($aDrive[$i] & "\" & $uniquefile) Then
    $driveletter = $aDrive[$i]
    ExitLoop
    EndIf
Next
SplashTextOn ( "Format", "Formatting Disk 0", 200, 100, 200, 400 )
RunWait ( "diskpart /s x:\Windows\System32\dsk\prepdisk", "", @SW_HIDE )
SplashOff ()
SplashTextOn ( "Applying Image", "Imaging Disk 0" & @CRLF & "Will Reboot when complete", 200, 100, 200, 400 )

If $driveletter = "" Then
    RunWait ( 'x:\windows\system32\gimagex', '', @SW_SHOW )
Else
    RunWait ( "X:\Windows\System32\imagex /apply " & $driveletter & "\Image\AISDImage.wim 1 C:\", "", @SW_HIDE )
EndIf
EndIf
SplashOff()
SplashTextOn ( "Reboot...", "Rebooting Computer" & @CRLF & "Remove thumbdrive", 200, 100, 200, 400 )
Sleep ( 5000 )
SplashOff()

The above script works on the computer I was having problems with (HP 2740P Tablet) now I have to check others

I will change the title of this thread if/when the script is solve

Thanks everyone!

Link to comment
Share on other sites

  • 2 years later...

Now there's an idea

would I have to remove the wpeinit from startnet.cmd and put imager.exe in its place?

I think I have it figured out, I change the order of the script

#include <GUIConstantsEx.au3>
#include <String.au3>

Global $driveletter = ""

$ImageCmpt = MsgBox ( 1 , "Image", "Do you want to Image this computer?" & @CRLF & "Okay = Proceed with Image" & @CRLF & "Cancel = Reboots Comptuer" )
If $ImageCmpt = 1 Then
$uniquefile = "keep.this.on.root.txt"
$aDrive=DriveGetDrive("ALL")
For $i=1 to $aDrive[0]
    If FileExists($aDrive[$i] & "\" & $uniquefile) Then
    $driveletter = $aDrive[$i]
    ExitLoop
    EndIf
Next
SplashTextOn ( "Format", "Formatting Disk 0", 200, 100, 200, 400 )
RunWait ( "diskpart /s x:\Windows\System32\dsk\prepdisk", "", @SW_HIDE )
SplashOff ()
SplashTextOn ( "Applying Image", "Imaging Disk 0" & @CRLF & "Will Reboot when complete", 200, 100, 200, 400 )

If $driveletter = "" Then
    RunWait ( 'x:\windows\system32\gimagex', '', @SW_SHOW )
Else
    RunWait ( "X:\Windows\System32\imagex /apply " & $driveletter & "\Image\AISDImage.wim 1 C:\", "", @SW_HIDE )
EndIf
EndIf
SplashOff()
SplashTextOn ( "Reboot...", "Rebooting Computer" & @CRLF & "Remove thumbdrive", 200, 100, 200, 400 )
Sleep ( 5000 )
SplashOff()

The above script works on the computer I was having problems with (HP 2740P Tablet) now I have to check others

I will change the title of this thread if/when the script is solve

Thanks everyone!

 

 

It is best to keep wpeinit as the first thing in startnet.cmd. 

"wpeinit : Wpeinit.exe specifically installs PnP devices, processes Unattend.xml settings, and loads network resources."

If you have issues with drivers loading, it is probably cause wpeinit isn't in your startnet.. 

Link to comment
Share on other sites

Really Chip?  2011 called and said they dont care about this issue anymore.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...