0

I had a script which worked on win xp but beacuse some of the methods are not available anymore I had to rewrite the script and use mshta.exe.

VBS script should do two things:

  1. Read from file
  2. Parse the info to the batch file

I have done the 1st bit but in the 2nd part I am getting an error. Could you please point me to the right direction?

Option Explicit

Dim objFso
Dim strFileName
Dim strFile
Dim objShell
Dim cimv2
Dim RemoteMachine
Dim YesNo 
Dim out
Dim crt
Dim objDialog, intResult
Dim objTextFile, strText, iintresult
Dim objExec, strMSHTA, wshShell

mainMenu

Sub mainMenu()
do
out = inputbox("Choose option:" & vbcr & "1 - Deployment" & vbcr & "0 - Exit", "Menu", "0")
If out="1" then
call SelectFile
End If
If out="0" 
then WScript.Quit
End if
loop
End Sub 

Sub bgInfo(param) 
YesNo = Msgbox("deployment? " & param, 4)
if YesNo = vbYes Then 
            do while not strMSHTA.AtEndOfStream
                            RemoteMachine = strMSHTA.ReadLine()
                            On Error Resume Next


                            objShell.Run "bginfo.bat " & RemoteMachine, 1, true


                            On Error Goto 0   
            loop
end if
End Sub 

Sub SelectFile( )
strMSHTA = "mshta.exe ""about:" & "<" & "input type=file id=FILE>" _
         & "<" & "script>FILE.click();new ActiveXObject('Scripting.FileSystemObject')" _
         & ".GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);" & "<" & "/script>"""
Set wshShell = CreateObject( "WScript.Shell" )
Set objExec = wshShell.Exec( strMSHTA )

intResult = objExec.StdOut.ReadLine( )
msgbox iintresult
If intResult <> "" Then
call bgInfo(intResult)
End If

Set objExec = Nothing
Set wshShell = Nothing

End Sub

Set objFso = Nothing
Set strFileName = Nothing
Set strFile = Nothing
Set objShell = Nothing
Set cimv2 = Nothing
Set RemoteMachine = Nothing
Set fso = Nothing

I am getting an error in line 33 char 5 Error: Object required: strMSHTA

thank you! :)

Matt
  • 74,352
  • 26
  • 153
  • 180
user2339910
  • 21
  • 3
  • 5
  • Not sure whether this'll help, but have you seen [npocmaka's hybrid Batch / HTA file chooser](http://stackoverflow.com/a/24415437/1683264)? It might simplify your interaction between batch and HTA. You should also consider submitting an answer to your own question to help future coders in case they have a similar problem as you had. – rojo Dec 17 '14 at 15:46
  • missing code: Set objFso = CreateObject("Scripting.FileSystemObject") set strFile = objFso.OpenTextFile(param2, 1, True) Set objShell = WScript.CreateObject("Wscript.Shell") – user2339910 Dec 17 '14 at 16:32

1 Answers1

0

I had to add this code:

Set objFso = CreateObject("Scripting.FileSystemObject")
set strFile = objFso.OpenTextFile(param2, 1, True)
Set objShell = WScript.CreateObject("Wscript.Shell")`
Matt
  • 74,352
  • 26
  • 153
  • 180
user2339910
  • 21
  • 3
  • 5