Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

WinPE 2.0 simple Ghost Menu HTA

- - - - -

  • Please log in to reply
117 replies to this topic

#26
zstokes

zstokes
  • Member
  • 6 posts
Issue resolved. When I upped the resolution to 1280x1024 the problem went away completely. Now, ghost starts right up and starts plugging away.

Z


How to remove advertisement from MSFN

#27
JuMz

JuMz

    Advanced Member

  • Member
  • PipPipPip
  • 466 posts
Cool HTA!

#28
zstokes

zstokes
  • Member
  • 6 posts
I love this tool, and am just about ready to roll it into production - many thanks!

I have one question:
When Ghost finishes, I have the -rb flag set, but it doesn't seem to work. The hta is still up, and I have to manually hit the Reboot button to get the system to reboot.

Any ideas on how I can actually get the system to reboot when Ghost is finished? I'm using Ghost8 in my environment as well.

Thanks,
Z

#29
zorphnog

zorphnog

    Advanced Member

  • Member
  • PipPipPip
  • 427 posts
Yeah the reboot functionality of ghost does not work within the PE environment, at least not 8.2 (which I use most often). However, it does work with 11.0. Anyway, what I do is launch ghost with the "-fx" switch which exits ghost after cloning has finished, and reboot via the "wpeutil reboot" command once ghost has completed.

I've written my own HTA for restoring ghost images from disk, but the meat of the code still applies. Just ignore all of the html stuff:
'*****************************************************************************************
'* restoreBuild
'* starts the ghost restoration process for the selected build and method
'*****************************************************************************************
Sub restoreBuild
  Dim filename, taskCmd

  strTemp = "<h2>Restoring build...</h2>"
  general.InnerHTML = strTemp

  filename = cdrom & "\" & buildFilename
  If not objFso.FileExists(filename) Then
	strTemp = "<h2>ERROR: File not found " & filename & "</h2><ul>Ensure that <u><b>DISK 1</b></u> is loaded in the CD-ROM drive and click the " &_
			  "<i>Retry</i> button."
	document.buttonsForm.nextButton.value = "<u>R</u>etry"
	document.buttonsForm.nextButton.disabled = false
	document.buttonsForm.cancelButton.disabled = false
	general.InnerHTML = strTemp
  Else
	taskCmd = "%comspec% /c ghostontop.exe"
	objShell.Run taskCmd,0,false
	Select Case curMethod
	  Case "Initial"
		taskCmd = "%comspec% /c ghost32.exe -sure -fdsp -clone,mode=load,src=" & filename & ",dst=" & destinationDisk & ",szeL -fx > \ghost.log"
		objShell.Run taskCmd,0,true
		finishBuild
	  Case "Windows"
		taskCmd = "%comspec% /c ghost32.exe -sure -fdsp -clone,mode=prestore,src=" & filename & ":1,dst=" & destinationDisk & ":1,sze1=V -fx > \ghost.log"
		objShell.Run taskCmd,0,true
		finishBuild
	End Select
  End If
End Sub

'*****************************************************************************************
'* finishBuild
'* handles errors that occur during ghost and handles successful restorations
'*****************************************************************************************
Sub finishBuild
  Dim result, logFile, count

  Set logFile = objFso.GetFile("\ghost.log")
  If logFile.Size <> "0" Then
	Set logFile = objFso.OpenTextFile("\ghost.log")
	count = 1
	Do While logFile.AtEndOfStream <> true
	  result = result & count & "> " 
	  Do While logFile.AtEndOfLine <> true or logFile.AtEndOfStream <> true
		result = result & logFile.Read(1)
	  Loop
	  result = result & "<BR>"
	  general.InnerHTML = result
	  count = count + 1
	Loop
	logFile.Close
	strTemp = "<CENTER><H1>FAILED</H1><DIV style='color:red;text-align:left'>An attempt to restore the system failed with the " &_
			  "following error message:<BR><BR><DIV style='position:absolute;border-style:solid;border-color:black;left:5%;" &_ 
			  "width:95%;color:black;padding:5%;border-width:1;font-family:terminal;font-size:10pt;overflow:auto'>" & result &_
			  "</DIV></DIV></CENTER>"
	warning.InnerHTML = strTemp
	warning.style.top = "10%"
	warning.style.left = "10%"
	warning.style.width = "80%"
	warning.style.height = "75%"
	document.buttonsForm.cancelButton.value = "E<u>x</u>it"
	document.buttonsForm.cancelButton.accesskey = "x"
	document.buttonsForm.cancelButton.disabled = false
	warning.style.visibility = "visible"
  Else
	strTemp = "<h2>Complete!</h2><ul><font color=orange>" & result & "</font>The restoration process has finished without any " &_
			  "errors."
	document.buttonsForm.cancelButton.value = "E<u>x</u>it"
	document.buttonsForm.cancelButton.accesskey = "x"
	document.buttonsForm.cancelButton.disabled = false
	general.InnerHTML = strTemp
	warning.style.visibility = "visible"
	If needHAL = "yes" Then
	  handleHAL
	Else
	  rebootMe
	End If
  End If
End Sub

'*****************************************************************************************
'* handleHAL
'* prepares the system for use with the correct HAL
'*****************************************************************************************
Sub handleHAL
  Dim strDest, inFile, outFile, line, words, lword

  strTemp = "<CENTER><H1>Updating HAL...</H1></CENTER>"
  warning.InnerHTML = strTemp
  objShell.Run "%comspec% /c diskpart /s X:\Windows\system32\probeParts.txt",0,true

  Select Case strHAL
	Case "acpiapic"
	  'Remove UpdateUPHal line from sysprep.inf
	  strDest = "C:\sysprep\sysprep.inf"
	  If objFso.FileExists(strDest) Then
		Set inFile = objFso.OpenTextFile(strDest,1,true)
		Set outFile = objFso.CreateTextFile(strDest & ".tmp",true)

		'Loop through sysprep.inf file
		Do While inFile.AtEndOfStream <> true
		  line = inFile.ReadLine
		  If line <> "" Then
			words = split(line,"=")
			lword = trim(words(0))
			outFile.WriteLine(line)
			If Lcase(lword) = "[unattended]" Then
			  If numProcs = 1 Then
				outFile.WriteLine("UpdateUPHAL=ACPIAPIC_UP,%WINDIR%\Inf\Hal.inf")
			  Else
				outFile.WriteLine("UpdateHAL=ACPIAPIC_MP,%WINDIR%\Inf\Hal.inf")
			  End If
			End If
		  Else
			outFile.WriteBlankLines(1)
		  End If
		Loop
		inFile.Close
		outFile.Close
		objFso.DeleteFile strDest,true
		objFso.MoveFile strDest & ".tmp", strDest
	  Else
		strTemp = "<CENTER><H1>FAILED</H1><DIV style='color:red;text-align:left'>An attempt to update your system HAL has " &_
				  "failed due to an inaccessible system drive.</DIV></CENTER>"
		warning.InnerHTML = strTemp
		warning.style.top = "10%"
		warning.style.left = "10%"
		warning.style.width = "80%"
		warning.style.height = "75%"
		document.buttonsForm.cancelButton.value = "E<u>x</u>it"
		document.buttonsForm.cancelButton.accesskey = "x"
		document.buttonsForm.cancelButton.disabled = false
	  End If
	  rebootMe
	Case Else
	   rebootMe
  End Select
End Sub

'*****************************************************************************************
'* rebootMe
'* opens the CD tray, delays 8 seconds and reboots
'*****************************************************************************************
Sub rebootMe
'Open CD tray
  strTemp = "<center><h1>Ejecting Media...</h1></center>"
  warning.InnerHTML = strTemp
  cdrom = cdrom & "\"
  CreateObject("Shell.Application").Namespace(17).ParseName(cdrom).InvokeVerb("Eject")

'Give delay to allow disk to eject
  objShell.Run "%comspec% /c cscript X:\Windows\system32\timer.vbs",0,true

'Reboot the system
  strTemp = "<center><h1>Rebooting System...</h1></center>"
  warning.InnerHTML = strTemp
  objShell.Run "%comspec% /c wpeutil reboot",0,false
End Sub

Edited by zorphnog, 27 July 2007 - 07:29 AM.


#30
zstokes

zstokes
  • Member
  • 6 posts
Thanks - this was something simple that I just haven't seen yet - wpeutil reboot.

I really need to learn to RTM.

Cheers,
Z

#31
Obet31

Obet31
  • Member
  • 5 posts
Thanks for sharing. I've taken a lot of the code into my own HTA but again I'm a newbie at this.

Can someone help me or point me to the correct direction on how to change the background image when an option is chosen from using a radio button? Here is my situation:

I added two(radio) buttons that say (development and production) to readily distinguish the environment that they are going to get the image from. My problem is I cannot change the background image (am totally inexperience in html or hta) defined in <DIV>. Can someone please help me on how to do this?

What I am doing is this:

strBody = strBody & "<td><Input type=radio name=envList checked value=Production onclick=ChangeBG>" &_
"Production" & "</BUTTON><BR>"
strBody = strBody & "<Input type=radio name=envList value=Development onclick=ChangeBG>" &_
"Development" & "</BUTTON></td>"

sub changeBG
...
end sub

Is it possible to change it this way? What am I suppose to put in the "changeBG" to change the SRC?


Thank you very much.

You guys rock!!!

#32
zorphnog

zorphnog

    Advanced Member

  • Member
  • PipPipPip
  • 427 posts
strBody = strBody & "<td><Input type=radio name=envList checked value=Production onclick=proBG>" &_

"Production" & "</BUTTON><BR>"

strBody = strBody & "<Input type=radio name=envList value=Development onclick=devBG>" &_

"Development" & "</BUTTON></td>"





Sub proBG

  bg.InnerHTML = "<img src='probg.bmp'>"

End Sub



Sub devBG

  bg.InnerHTML = "<img src='devbg.bmp'>"

End Sub


#33
Obet31

Obet31
  • Member
  • 5 posts
Thanks Zorph. Thank you. thank you... :D

#34
Stratuscaster

Stratuscaster

    Newbie

  • Member
  • 31 posts
What I'm finding is that whenever I attempt to launch a command line - for example, the entire "ghost32.exe -mode=load src=c:\image.gho etc..." it fails.

Usually I get a "the user cancelled this command" or something like that.

It seems to be related to the use of spaces in the variables building the command. I can launch the executable itself without issue, but try to add the switches to it and it fails.

#35
zorphnog

zorphnog

    Advanced Member

  • Member
  • PipPipPip
  • 427 posts
What is the exact command you are trying to run?

#36
Stratuscaster

Stratuscaster

    Newbie

  • Member
  • 31 posts
t:\Programs\ghost11\files\ghost32.exe  -clone,mode=restore,src=k:\images\sample.gho,dst=1
If I run just the executable part (t:\Programs\ghost11\files\ghost32.exe) it runs fine. Once I add the switches, it fails.

#37
egronski

egronski
  • Member
  • 1 posts
I am just floored right now, this is exactly what I need for our manufacturing environment. We currently use a DOS based imaging setup which was old when we created it, now it's up to me to bring our imaging up to the 32-bit standard. I am so pumped to find all this information, its going to take me a while to take it all in but I just wanted to pop up and say wow. :thumbup

#38
zorphnog

zorphnog

    Advanced Member

  • Member
  • PipPipPip
  • 427 posts

t:\Programs\ghost11\files\ghost32.exe  -clone,mode=restore,src=k:\images\sample.gho,dst=1
If I run just the executable part (t:\Programs\ghost11\files\ghost32.exe) it runs fine. Once I add the switches, it fails.


You're missing the last part of the clone command, the sze parameter.

#39
Stratuscaster

Stratuscaster

    Newbie

  • Member
  • 31 posts

t:\Programs\ghost11\files\ghost32.exe  -clone,mode=restore,src=k:\images\sample.gho,dst=1
If I run just the executable part (t:\Programs\ghost11\files\ghost32.exe) it runs fine. Once I add the switches, it fails.


You're missing the last part of the clone command, the sze parameter.

While that may be - and likely due to me just leaving it off when typing my reply - it doesn't solve the issue I'm having.

#40
zorphnog

zorphnog

    Advanced Member

  • Member
  • PipPipPip
  • 427 posts
Ok I've read some more and I think I was wrong about the sze switch as it is not necessarily needed, but still think the error is in the syntax of your switch. I've searched and I cannot find a mode=restore. There is a mode=prestore or mode=load. The prestore mode restores a specific partition and the load mode restores the entire disk. Heres a link to the -clone syntax. Switches: Cloning

#41
Stratuscaster

Stratuscaster

    Newbie

  • Member
  • 31 posts
Let's try this again:
t:\Programs\ghost11\files\ghost32.exe  -clone,mode=load,src=k:\images\sample.gho,dst=1

The above string, when passed to be run by the click of a button, does not work.

#42
zorphnog

zorphnog

    Advanced Member

  • Member
  • PipPipPip
  • 427 posts
Ok, I'm at a loss. Can you post the code as you are using it in your HTA? It would give me a better idea of the context in which you are trying to run the command.

Edited by zorphnog, 24 October 2007 - 02:25 PM.


#43
Stratuscaster

Stratuscaster

    Newbie

  • Member
  • 31 posts
It's the original wizard.hta script, with my ghost32.exe locations...
<html>
<!--
'********************************************************************
'*
'* File: wizard.hta
'* Author: greg & fisher
'* Created: Mar 2007
'* Modified:
'* Version: .9
'*
'* Description: windows imaging platform
'*
'* Dependencies: tested on and for WinPE 2.0 with WMI, Scripting,
'* XML, HTA packages
'* Notes: Line 26 - might want to make this "normal" when you are
'* testing and don't want the hta fullscreen
'* Line 58 - customize your headings here
'* Line 72, 101 - confirm directory.name path, this would be a mapped
'* drive to the filer where the images shorcut dir is
'* Line 193 - confirm background image source location
'* Line 200 - confirm path to ghost executable
'*
'********************************************************************
-->

<!****************************************************************************>
<!* HTA Header >
<!****************************************************************************>
<HEAD>
<TITLE>Imaging Application</TITLE>
<HTA:APPLICATION
BORDER = None
APPLICATION = Yes
WINDOWSTATE = normal
INNERBORDER = No
SHOWINTASKBAR = Yes
SCROLL = No
APPLICATIONNAME = "Windows PE Wizard"
NAVIGABLE = Yes
>
<!-- external stylesheet -->
<link rel="stylesheet" type="text/css" href="htaStyle.css" />
</HEAD>

<!****************************************************************************>
<!* Begin Script >
<!****************************************************************************>
<script Language=VBScript>

'****************************************************************************
'* Globals
'* setup global script parameters
'****************************************************************************
Option Explicit
Dim strTaskValue, objShell, objFso, strBody, objWmiService
Set objShell = CreateObject("WScript.Shell")
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject ("winmgmts:\\.\root\cimv2")

'****************************************************************************
'* Window_OnLoad
'* load up behavior and preferences
'****************************************************************************
Sub Window_Onload
self.Focus()
strBody = "<H1>PE Build and Recovery Environment</H1>" &_
"<H2>Select Images to apply an OS image using Ghost.<BR><BR>" &_
"Please select an image category:<BR><BR>"
enumDirs
End Sub

'****************************************************************************
'* enumDirs
'* find directories and create category buttons
'****************************************************************************
Sub enumDirs
Dim colSubfolders, objFolder, fileName
'enumerate folders in images folder
Set colSubfolders = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='z:\winpe'} Where AssocClass = Win32_Subdirectory ResultRole = PartComponent")
'create html buttons from each folder name
For Each objFolder in colSubfolders
fileName = objFolder.fileName
strBody = strBody &_
"<button id='" & fileName & "' onClick='enumImages("" & fileName & "")'>" & fileName & "</BUTTON>"
Next
'post resulting html body to document
strBody = strBody & "<BR><HR><BR>"
body.innerHTML = strBody
End Sub

'****************************************************************************
'* enumImages
'* find images and create radio buttons
'****************************************************************************
'this sub is a little messy because of limitations of win32_shortcutfile and need to go between fso and wmi for different info
'also, without the advantages of .net sorting classes, the old bubble sorting is not the funnest

Sub enumImages(fileName)
Dim colFilelist, objFile, strButtons, objShortcut, colTargetList, objTarget, x, y, strKey, strItem
ReDim arrButtons(1,-1)

'reset display element style
details.innerHTML = ""
details.style.visibility = "hidden"
' strButtons = "<table id=buttonTable>"
'enumerate ghost image shortcuts in specific images subfolder from enumDirs
Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='z:\winpe\" & fileName & "'} Where ResultClass = CIM_DataFile")
'find ghost image shortcut targetpath (fso)
For each objFile in colFileList
If objFile.Extension = "lnk" Then
Set objShortcut = objShell.CreateShortcut(objFile.name)
'find ghost image shortcut target (wmi)
Set colTargetList = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where name = '" & replace(objShortcut.targetpath,"\","\\") & "'")
'add radio button label (from fso) and radio button target (from wmi) to an array
For each objTarget in colTargetList
ReDim Preserve arrButtons(1,UBound(arrButtons,2)+1)
arrButtons(0,UBound(arrButtons,2)) = objShortcut.Description
arrButtons(1,UBound(arrButtons,2)) = "<Input type=radio name=radioList id='" & objTarget.Drive & objTarget.Path &

objTarget.fileName &_
"' onClick=showRadioInfo>" & objShortcut.Description & "</BUTTON><BR>"
Next
End If
Next
'perform a a shell sort of the string array based on button label
For x = 0 To UBound(arrButtons,2) - 1
For y = x To UBound(arrButtons,2)
If StrComp(arrButtons(0,x),arrButtons(0,y),vbTextCompare) > 0 Then
strKey = arrButtons(0,x)
strItem = arrButtons(1,x)
arrButtons(0,x) = arrButtons(0,y)
arrButtons(1,x) = arrButtons(1,y)
arrButtons(0,y) = strKey
arrButtons(1,y) = strItem
End If
Next
Next
'create combined buttons html code from sorted buttons array
For x = 0 To UBound(arrButtons,2)
strButtons = strButtons & "<tr><td id=buttonTd>" & arrButtons(1,x) & "</td></tr>"
Next
' strButtons = strButtons & "</table>"
'create a start button with start image command and append and post resulting html to body
body.innerHTML = strBody & strButtons & "<BR><HR><BR><button id=start Accesskey=S onclick=doTask(strTaskValue)><U>S</U>tart

Image!</BUTTON><BR>"
start.style.visibility="hidden"
End Sub

'****************************************************************************
'* doTask
'* run task selected by radio button
'****************************************************************************
Sub doTask(doMe)
objShell.Run doMe
End Sub

'****************************************************************************
'* showRadioInfo
'* display details of radio button selection in details divider
'****************************************************************************
Sub showRadioInfo
Dim objTextFile, Radio, strRadioValue, strDetails
'set details and start element styles
details.style.visibility = "visible"
start.style.visibility = "visible"
'find checked button
For Each Radio in Document.getElementsByName("radioList")
If Radio.Checked = True Then
'create imaging command line from button id
strTaskValue = Chr(34) & "t:\Programs\ghost11\files\ghost32.exe" & Chr(34) & " -clone,mode=load,src=" & Chr(34) &

Radio.Id & ".gho" & Chr(34) & ",dst=1"
'display image details in details element if they exist
If objFso.FileExists(Radio.Id & ".htm") Then
Set objTextFile = objFso.OpenTextFile(Radio.Id & ".htm", 1)
strDetails = objTextFile.ReadAll()
Else
'display error message in details element if no matching details file found
strDetails = "Can't find anything!!!<BR><BR>" &_
"Make sure the info file has the same name as the .gho and has an .htm extension."
End If
End If
Next
'post resulting html to details element
Details.innerHTML = strDetails
End Sub

'****************************************************************************
'* Reset
'* reset the tool interface, also reloads the code (helpful for programming)
'****************************************************************************
Sub Reset
Location.Reload(True)
End Sub

</Script>
<!****************************************************************************>
<!* End Script / Begin HTML >
<!****************************************************************************>

<BODY>
<DIV id=bg>
<img src=winpe.bmp>
</DIV>

<DIV id=body></DIV>
<DIV id=details></DIV>

<DIV id=tools>
<Button id=ghost onclick=doTask('"t:\Programs\ghost11\files\ghost32.exe"')>Ghost</BUTTON>
<Button id=cmd onclick=doTask('%comspec%')> Cmd </BUTTON>
<Button id=notepad onclick=doTask('notepad')> Notepad </BUTTON>
<Button id=taskmgr onclick=doTask('taskmgr')> Taskmgr </BUTTON>
<Button id=close onclick=self.close()> Quit </BUTTON>
<Button id=reset onclick=reset> ResetApp </BUTTON>
<Button id=reboot onclick=self.navigate('reboot.hta')> Reboot </BUTTON>
</DIV>
</BODY>
</HTML>

<!****************************************************************************>
<!* End HTML >
<!****************************************************************************>


This is the snippet that creates the string that should get launched by the button:
'find checked button
For Each Radio in Document.getElementsByName("radioList")
If Radio.Checked = True Then
'create imaging command line from button id
strTaskValue = Chr(34) & "t:\Programs\ghost11\files\ghost32.exe" & Chr(34) & " -clone,mode=load,src=" & Chr(34) & Radio.Id & ".gho" & Chr(34) & ",dst=1"


#44
Tyrell

Tyrell
  • Member
  • 1 posts
Many Thanks for sharing keythom, I'm just getting into HTAs and yours is very cool!

#45
MichaelG

MichaelG
  • Member
  • 6 posts
i love this hta menu. i use it on my software imaging recovery program but i need help on it. i used a 2 different recovery program, how can i used the button to distinguish which program to used to reload the image. for example
image a, image b, image c use a recovery software
image d, image e, image f uses another recovery software


i want to use this menu to keep it simple for my techs.


any ideas or sugesstion or how to code properly.

remind you that i am total noobie at this. i have general idea how it works but not to code it ... any ideas would appreciated


thanks

#46
zorphnog

zorphnog

    Advanced Member

  • Member
  • PipPipPip
  • 427 posts
Do the recovery files have different extensions? Use the file extension to determine what application needs to be executed.

#47
MichaelG

MichaelG
  • Member
  • 6 posts
yes, i forgot to add that. one has img extension used by imgit by briwave in china and the other is pqi - powerquest

#48
Stratuscaster

Stratuscaster

    Newbie

  • Member
  • 31 posts
Thanks to those that attempted to help with my issues.

Went back into the HTA and through trial and error located the problems - lots of confusion between " and Chr(34) and ' placement that just kept breaking things.

As of right now, it appears to be working correctly. I changed the layout a bit - put the list of images on the right side where the HTML details were, because in our setup we have lots of clients with lots of images and I needed the room.

On the HTML "details" side of things, I have a small section above the "tools" buttons to show those details - we only use a line or two (if we use them at all) - so that works out fine for us.

Someone here at work asked for a keyboard shortcut for each 'client' button - as nice as that would be, I think we could run out of letters and numbers before we ran out of client buttons.

The only other issue I have - and it's no fault of the script - is when the actual GHO image file name or the directory name contains 'odd' characters in them - like parentheses and apostrophes. That's more a training issue here - get folks to keep the images directories simple and put the notes and things in the HTML details file instead.

Kudos again for a fine piece of work. :D

#49
someoneingbg

someoneingbg
  • Member
  • 3 posts
Hello
I have problems to get WMI to work with UBCD4Win PE Builder 3.1.10a.

Need help to get WMI Support to work, any suggestions?

THX in advance!

#50
EricWoodland

EricWoodland
  • Member
  • 2 posts
What is the quickest way to change the Title text to another color than Black?
IE "Build and Recovery Center"

Also, how tough would it be to create a button which will kick-off a specific session, such as:
"X:\Program Files\Ghost\Ghost32.exe" -clone,mode=restore,src=@mcHP,dst=1,SZE1=20471M,SZEL -sure -RB

I'm trying to migrate my existing Ghost configuration into this GUI without changing a lot behind the scenes.

Thanks!

-=Woody=-




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN