VBScript GetVirtualSystemThumbnailImage help!

Hey All!

I am writing an HTA application (some of you may have seen some of my other questions), and I am now stuck on the thumbnail image of a VM. I am taking the VBScript example from here:

https://msdn.microsoft.com/en-us/library/cc160707(v=vs.85).aspx

with slight modifications for root\virtualization\v2, but when I run it, all I get is a WScript.Echo "Done" and a log file with "Done" in it. I see two subs in the example to write the image (SaveThumbnailImage and PrintThumbnailImage), but they are never actually called in the script. Any attempts to call those with OutParams.ImageData error with a type mismatch.

Particularly, if you copy and paste the example, the mismatch error is on line 80 with the "stream.WriteText text".

Are the [] brackets shown in the above link required when passing the data to the sub? As in: SaveThumbnailImage(objOutParams.ImageData[])

I have seen the PowerShell examples, and I can get the PowerShell example to work, but being an HTA, I need this to work with VBScript. Has anybody successfully gotten a VBScript to output a thumbnail image? Any tips on getting this to work?

Thank you in advace!

Eric

EDIT: Tried adding the brackets [], but it throws an error "Expected ')'". Doesn't seem to like the brackets.

What exactly is being created with the ADODB.stream? Is that the issue? This one is new to me. I have .NET 3.5 and .NET 4.5 installed.

To Note, I have seen the PowerShell examples, and I am currently using that to get the thumbnails, but calling the PowerShell script with parameters is not working directly from the HTA. I have to call a VBScript with parameters, then the VBScript calls the PowerShell script. Ugly, but that's the only thing I have gotten to work so far. I would much rather just have VBScript entirely within the HTA.


  • Edited by Mako-Wish Monday, February 23, 2015 8:22 PM
February 23rd, 2015 11:11pm

The closest I have gotten to anything is

=====================================================

 imageBytes = objOutParams.ImageData

   Set objStream = CreateObject("ADODB.Stream")
   objStream.Open
    Redim text(ubound(imageBytes) \ 2)
    for i = lbound(imageBytes) to ubound(imageBytes) step 2
     text(i\2) = ChrW(imageBytes(i + 1) * &HFF + imageBytes(i))
    next
   For Each bit in text
    objStream.WriteText bit
   Next
   objStream.SaveToFile "C:\TEMP\test.png",2
   objStream.Close

=====================================================

This will actually write some data to the file, but it is not a valid image file. If I open the file with Notepad++, it is a ton of NULL characters and what appears to be tons of Chinese characters:

Opening a true PNG or BMP file does not show any of these characters, but there is a lot of NULLs and some plain-English mark-up.

What am I doing wrong here?

Free Windows Admin Tool Kit Click here and download it now
February 23rd, 2015 11:18pm

You are trying to input binary and write it as text. This converts each byte into a Unicode pair of characters. You must write the stream as binary.
February 24th, 2015 1:52am

This is how to do a binary write of a byte array:

Set objStream = CreateObject("ADODB.Stream")
objStream.Open
objStream.Write objOutParams.ImageData
objStream.SaveToFile "C:\TEMP\test.png",2
objStream.Close

Free Windows Admin Tool Kit Click here and download it now
February 24th, 2015 2:47am

Hi jrv,

Thank you for the reply. I have tried that already, and I get an error:

"Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another."

I also tried setting the stream type to binary (Google suggestion) with the same error result:

   Const adTypeBinary = 1
   Const adSaveCreateOverWrite = 2
   
   Set objStream = CreateObject("ADODB.Stream")
   objStream.Type = adTypeBinary
   objStream.Open
   objStream.Write objOutParams.ImageData
   objStream.SaveToFile "C:\Scripts\test.png",adSaveCreateOverWrite
   objStream.Close

  • Edited by Mako-Wish Tuesday, February 24, 2015 2:14 AM
February 24th, 2015 5:12am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics