Jump to content

Running ImageX from VBScript


ryarnell

Recommended Posts

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.

Link to comment
Share on other sites


  • 2 weeks later...

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

Link to comment
Share on other sites

  • 1 year later...

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

Edited by allanf
Link to comment
Share on other sites

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=&amp...st&p=889162

Link to comment
Share on other sites

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

post-141570-1262648020_thumb.png

imagex_2.0_W7rc1

post-141570-1262648124_thumb.png

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

post-141570-1262709286_thumb.png

Regards :)

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
  • Recently Browsing   0 members

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