MSFN Forum: Running ImageX from VBScript - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Running ImageX from VBScript Rate Topic: -----

#1 User is offline   ryarnell 

  • Group: Members
  • Posts: 7
  • Joined: 30-January 07

Posted 30 July 2008 - 04:46 PM

Hello,
I am having some trouble running ImageX from a vbScript in VistaPE.
Here is what the script looks like and the error it throws.

Dim Shell
Dim myResult

Set shell = CreateObject("WScript.Shell")
myResult = shell.Run("imagex.exe", 1, True)

When I run this is get:
The operation was cancelled by the user.

Here is what I have done / tried.

If I replace imagex with notepad, notepad comes up just fine so, I know the script is OK.
I have imagex.exe in the same directory as the script. I have even added the path like this "c:\test\imagex.exe"
still the same error.
I even copied imagex.exe over to the system32 directory so it would be in the path and still get the same error.

If I type imagex.exe at the prompt it gives the normal help output to the screen you would expect to see.
I can also type out the whole line with /apply and it works from the command line.
It just doesn't work inside the script.

Has anyone else ever seen this or know how to make this work.

Thanks a bunch.


#2 User is offline   CoffeeFiend 

  • Coffee Aficionado
  • Group: Super Moderator
  • Posts: 5,031
  • Joined: 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 30 July 2008 - 05:02 PM

It might have something to do with VistaPE, because it runs just fine as-is on Vista, no error messages at all.

#3 User is offline   Br4tt3 

  • World famous sausage eater...
  • PipPipPipPip
  • Group: Members
  • Posts: 566
  • Joined: 20-April 04

Posted 13 August 2008 - 08:08 AM

Hi,

First of all, like u say... if u try to run notepad.exe it works right? well, as long as u execute ur .vbs file with cscript.exe (default is wscript.exe) from within an existing cmd console, this should also work.... if u try to execute a CLI command from an vbscript which in turn is kicked by wscript.exe, there should only be quick flicker on the screen... instead, open up cmd.exe, type <cscript.exe my_vbs_file.vbs>, execute and u should see the /INFO list poping up....

Option Explicit

WScript.Echo ExecAppRM("imagex.exe /info D:\Distribution\Captures\WINVISTA_X64_ENT.wim")

Function ExecAppRM(pstrCommand)
  Dim oRun
  Dim n
  Dim WshShell
  Dim strResult

  Set WshShell = WScript.CreateObject("WScript.Shell")	
  
  n=0
  Set oRun=WshShell.Exec(pstrCommand)		
  ExecAppRM = oRun.StdOut.ReadAll

End Function


Hope it does it for you....

#4 User is offline   allanf 

  • Junior
  • Pip
  • Group: Members
  • Posts: 65
  • Joined: 01-June 07

Posted 03 January 2010 - 04:27 AM

Time has passed, but I think something may have changed.

I have dug up an old HTA that was working as expected - similar to the above script - but can't figure out what has broke.

The only Echo I get from the "stdout.readall" from "imagex /xml /info" is:
ÿ_<


This presumably is the first symbol and first bracket in the "well-formed XML" seen by running the imagex command straight on the command line:
 ■< W I M >
	 < T O T A L B Y T E S > 1 8 2 7 4 3 7 5 7 < / T O T A L B Y T E S >
	 < I M A G E   I N D E X = " 1 " >
		 < N A M E > M i c r o s o f t   W i n d o w s   V i s t a   P E   ( x 8
 6 ) < / N A M E >
		 < D E S C R I P T I O N > M i c r o s o f t   W i n d o w s   V i s t a
   P E   ( x 8 6 ) < / D E S C R I P T I O N >
		 < W I N D O W S >

etc, etc


To test the cmd-line output and the "stdout.readall" Echo, I have used the following adaptation of Br4tt3's vbscript executed with cscript from the cmd-line. A separate cmd-window opens from "WshShell.Run" to show the normal XML output, and the "WScript.Echo ExecAppRM(strArgument)" Echos the strange stdout.readall in the main cmd-window.

Option Explicit
  Dim strWIMFile
  Dim strArgument
  Dim strArgumentRun
  strWIMFile = "C:\Program Files\Windows AIK\Tools\PETools\x86\winpe.wim"
  strArgument = Chr(34) & "C:\Program Files\Windows AIK\Tools\x86\imagex.exe" & _
  Chr(34) & " /XML /info " & Chr(34) & strWIMFile & Chr(34)
  strArgumentRun = Chr(40) & strArgument & Chr(41)
	
WScript.Echo ExecAppRM(strArgument)

Function ExecAppRM(pstrCommand)
  Dim oRun
  Dim n
  Dim WshShell
  Dim strResult

  Set WshShell = WScript.CreateObject("WScript.Shell")
  
  n=0
  WshShell.Run "cmd /k "+strArgumentRun, , True
  Set oRun=WshShell.Exec(pstrCommand)		
  ExecAppRM = oRun.StdOut.ReadAll

End Function


Could anyone explain what's going wrong? I'm sure it used to work. Tested on XP SP3 and Win7 RC1.

Thanks :)

Edit: Cleaned up vbscript - used "strArgument" in "strArgumentRun = "

Edit: Hmmm... Not to worry. I found that changing to the version of imagex from WAIK for Win7 solves the problem (but does not solve the mystery of why an older version of imagex used to work then suddenly didn't...)

This post has been edited by allanf: 04 January 2010 - 12:14 AM


#5 User is offline   Tripredacus 

  • K-Mart-ian Legend
  • Group: Super Moderator
  • Posts: 6,988
  • Joined: 28-April 06
  • OS:Windows 7 x86
  • Country: Country Flag

Posted 04 January 2010 - 09:34 AM

Allan, this is quite simple. You can see for yourself if you create a WIM with Imagex from PE 2.x and also one from PE 3.0. Then run imagex /info on each and compare! The XML nodes are in a different order from the Windows 7 WAIK. I ran into this problem with the GimageX HTA. Fellow user dabone fixed it with the following, perhaps it will give you some insight:

http://www.msfn.org/board/index.php?s=&...st&p=889162

#6 User is offline   allanf 

  • Junior
  • Pip
  • Group: Members
  • Posts: 65
  • Joined: 01-June 07

Posted 04 January 2010 - 05:40 PM

Tripredacus

Thanks for your reply.

The issue I am having may not be apparent when the stdout is redirected to file. However, the hta I am using reads directly from the stdout.

Apart from the node re-ordering, there seems to be some significant change in the rendering of the well-formed XML.

On each system, I have installed and re-installed the various Windows AIK versions, taking care to properly uninstall an existing version before installing a new.

To illustrate the differences between the rendering of the XML, here are two screenshots - one of XP SP3 with WAIK 1.1 (for Vista SP1 and Server 2008), and one of Windows 7 RC1 with WAIK 2.0 (for Windows 7). It does not matter which system is used - XP or Win7. The results are the same for each of the two versions of imagex on either system.

imagex_1.1_XPsp3
Attached File  imagex_1.1_XPsp3.gif (11.13K)
Number of downloads: 14

imagex_2.0_W7rc1
Attached File  imagex_2.0_W7rc1.gif (13.77K)
Number of downloads: 14

Notice for imagex from WAIK 1.1 the leading symbol that I mentioned in my earlier post. There is also the rather obvious spacing between each letter in the stdout. What is going on here?

Thanks :)

#7 User is offline   Tripredacus 

  • K-Mart-ian Legend
  • Group: Super Moderator
  • Posts: 6,988
  • Joined: 28-April 06
  • OS:Windows 7 x86
  • Country: Country Flag

Posted 05 January 2010 - 09:23 AM

On larger /INFOs, if I need to find an Index, for example, I'll do an command such as:

imagex /info d:\images\temp2.wim > d:\images\temp2.xml


Which is the old "print to file" command. On the server it has OPK for Vista SP1 (Win PE 2.1), not sure how it equates to WAIK version. If I just try to open the XML with IE, it will return a parse error because PE 2.x has a header on the file before the root node. And these first few lines are not escaped out or put into CDATA or anything, so the XML parser fails. Now I would just print to .txt and open in Notepad.

Oh interesting that /xml switch you are using. I have not used that before.

#8 User is offline   allanf 

  • Junior
  • Pip
  • Group: Members
  • Posts: 65
  • Joined: 01-June 07

Posted 05 January 2010 - 10:38 AM

View PostTripredacus, on Jan 5 2010, 10:23 AM, said:

Oh interesting that /xml switch you are using. I have not used that before.


HeHe! I thought everyone was using it. I misread Br4tt3's VBScript and don't quite understand dabone's "parseFile" Sub.

Makes me wonder now if the stdout from the earlier imagex's "/xml /info" switches was ever readable/parseable by the DOM.

My hta was originally scripted with Win 7 Tools installed, but I dropped the project. At some stage, I switched back to WAIK for Vista SP1, then recently tried to restart the hta project but couldn't figure out what was wrong. Misreading Br4tt3's VBScript from Aug 2008 also made me think that others had had things working with the earlier imagex. Now, I guess I'll never know.

The hta parses the entire stdout (without redirect/print to file) from imagex /xml /info into readable html for the hta's display. I use it for selecting and customizing WinPEs.

Attached File  WinPE_3.0_omatic.gif (25.16K)
Number of downloads: 27

Regards :)

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy