none
query wim image with vbs RRS feed

  • Question

  • Hi,

    How to get WIM image info with VBS and put it in array or file. So the script should search in folders and subfolders for wim files. Query them and put info somewhere.

    I tried to write script that uses batch with dism. But I've got issues with passing variables back to vbs. 

    this is vbs:

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    set WshShell = WScript.CreateObject("WScript.Shell")
    objStartFolder = "d:\deploymentshare\operating systems"
    
    Set objFolder = objFSO.GetFolder(objStartFolder)
    'Set colFiles = objFolder.Files
    
    ShowSubfolders objFSO.GetFolder(objStartFolder)
    
    Sub ShowSubFolders(Folder)
        For Each Subfolder in Folder.SubFolders
            Set objFolder = objFSO.GetFolder(Subfolder.Path)
            Set colFiles = objFolder.Files
            For Each objFile in colFiles
    		If UCase(objFSO.GetExtensionName(objFile.name)) = "WIM" Then
    			WshShell.Run "test2.bat " + chr(34) + objfile + chr(34),0
    			output = wshshell.ExpandEnvironmentStrings("%EnvTaskSeqID%")
    			wscript.echo output			
    		end if
            Next
        Next
    End Sub

    And here is bat:

    FOR /F "tokens=1,3*" %%a IN ('dism /get-imageinfo /imagefile:%1') do if "%%a"=="Name" setx EnvTaskSeqID "%%b %%c"
    First, I tried SET command but it didn't pass variable at all. And here, with this example I use SETX command. And it creates environmental variable. But I should restart cmd session to get new value. And also will it work in WinPe?

    Sunday, October 25, 2015 12:43 PM

Answers

  • You cannot alter the environment of a running program.  You cannot pass data from a batch file to a VBS program.  You can output the info to a text file and then read it into VBS.

    If using Windows 8 or later you can use the PowerShell DISM module.


    \_(ツ)_/

    • Marked as answer by aldarik Monday, October 26, 2015 11:00 AM
    Sunday, October 25, 2015 1:09 PM

All replies

  • You cannot alter the environment of a running program.  You cannot pass data from a batch file to a VBS program.  You can output the info to a text file and then read it into VBS.

    If using Windows 8 or later you can use the PowerShell DISM module.


    \_(ツ)_/

    • Marked as answer by aldarik Monday, October 26, 2015 11:00 AM
    Sunday, October 25, 2015 1:09 PM
  • In the batch file there is only one line of code. How to insert it into vbs script?

    output = WshShell.Run(FOR /F "tokens=1,3*" %%a IN ('dism /get-imageinfo /imagefile:" & objfile & "') do if "%%a"=="Name" get-variable "%%b %%c")

    How to use quotes in this expression? And get variable?

    Sunday, October 25, 2015 2:26 PM
  • As I posted above. You cannot get data from a batch file.

    You can do this:
    cmd="dism /get-imageinfo /imagefile > c:\dism-out.txt"
    WshShell.Run cmd, 0, True

    now open the file in vbscript and read it.


    \_(ツ)_/



    • Edited by jrv Sunday, October 25, 2015 2:43 PM
    Sunday, October 25, 2015 2:42 PM
  • You can do this:
    cmd="dism /get-imageinfo /imagefile > c:\dism-out.txt"
    WshShell.Run cmd, 0, True

    The script will fail for two reasons:

    • dism.exe does not "know" about output redirection.
    • UAC does not allow files to be created in the root of the System partition.

    This should work if drive D: exists:

    cmd="cmd.exe /c dism /get-imageinfo /imagefile > d:\dism-out.txt"
    WshShell.Run cmd, 0, True

    Sunday, October 25, 2015 5:33 PM