HTA and batch hybrid by passing variables from a BATCH section

I am trying to write a batch + hta hybrid script that will allow me to pass variables from the script package section to the hta section so that I can generate things like computer model number, etc.

This is what I still have - Package:

<!-- :: Batch section
    @echo off
    Pushd "%~dp0"
    setlocal

    FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get Model /value') do SET model=%%A

    for /F "delims=" %%a in ('mshta.exe "%~F0" "%model%"') do set "HTAreply=%%a"
    echo End of HTA window, reply: "%HTAreply%"
    goto :EOF
    -->

As you can see, I tried to use %model%as a parameter, and I tried to use arg1the VBScript section to try to use this variable, but that didn't work.

So, in my hta section, this is my vbscript:

<script language="VBScript">

    MsgBox arg1

</script>

Which only opens an empty box.

- , , . , script, , hta batch, .

+4
1

HTA Wscript.Shell COM object Environment. HTA stdout Scripting.FileSystemObject GetStandardStream. :

<!-- :: Batch section
@echo off & setlocal
Pushd "%~dp0"

FOR /F "tokens=2 delims==" %%A in ('wmic ComputerSystem Get Model /value') do SET model=%%A

for /F "delims=" %%a in ('mshta.exe "%~f0"') do set "HTAreply=%%a"
echo End of HTA window, reply: "%HTAreply%"
goto :EOF
-->
<script language="VBScript">

    Set Env = CreateObject("Wscript.Shell").Environment("Process")
    Set StdOut = CreateObject("Scripting.FileSystemObject").GetStandardStream(1)

    MsgBox Env("model")
    StdOut.Write("response")

    Set Env = Nothing
    Set StdOut = Nothing

    close()

</script>

VBScript , cscript, .wsf. , HTA, , , script , Environment("Process").

<!-- : batch portion
@echo off & setlocal

FOR /F "tokens=2 delims==" %%A in ('wmic ComputerSystem Get Model /value') do SET model=%%A

for /F "delims=" %%a in ('cscript /nologo "%~f0?.wsf" "%model%"') do set "VBreply=%%a"
echo End of VB script, reply: "%VBreply%"

goto :EOF

: VBScript -->
<job>
    <script language="VBScript">
        model = WScript.Arguments(0)

        MsgBox model
        Wscript.Echo "response"
    </script>
</job>

hybrid Batch + JScript . VBScript, JScript .wsf.

+5

Source: https://habr.com/ru/post/1673545/


All Articles