locked
Reading a created text file using VBScript withing HTA RRS feed

  • Question

  • Hi, Having a little problem that is perplexing me. I have some VBScript in a HTA that outputs DeviceID and number of Partitions of the single hard drive to a text file called HDPART.TXT-

     Set oShell = CreateObject("wScript.shell")
     Command = "cmd /c wmic DISKDRIVE GET DEVICEID, PARTITIONS > " & TEXT & "\HDPART.TXT"
     oShell.Run Command

    Where TEXT is the drive letter of a USB flash drive.

    I want to read the contents of that file into a variable called strLine and then display them;

     HD = TEXT & "\HDPART.TXT"
     SET oFSO = CreateObject("Scripting.FileSystemObject")
     SET oFILE=oFSO.OpenTextFile(HD, 1)
     strLine = oFile.ReadAll
     oFile.Close

    document.getElementById("ScriptArea").value    = strLine

    Problem is all I get as a result is gobbled-gook

    Any help appreciated.

    Thursday, September 21, 2017 2:19 PM

Answers

  • There is no need to call wmic, redirect output, read the file, etc.

    Just call WMI directly from the VBScript in the HTA.

    Better yet, abandon HTA altogether and switch to PowerShell.


    PS C:\> Get-WmiObject Win32_DiskDrive


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Bill_Stewart Tuesday, November 7, 2017 9:59 PM
    Thursday, September 21, 2017 2:33 PM

All replies

  • There is no need to call wmic, redirect output, read the file, etc.

    Just call WMI directly from the VBScript in the HTA.

    Better yet, abandon HTA altogether and switch to PowerShell.


    PS C:\> Get-WmiObject Win32_DiskDrive


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Bill_Stewart Tuesday, November 7, 2017 9:59 PM
    Thursday, September 21, 2017 2:33 PM
  • Even if the HTA etc is being run under WinPE?
    Thursday, September 21, 2017 2:49 PM
  • Even if the HTA etc is being run under WinPE?

    Yes.  WMIC is just a wrapper that makes the same WMI calls.


    \_(ツ)_/

    Thursday, September 21, 2017 2:52 PM