vbs从文件读取并将其解析为批处理文件

时间:2014-12-17 15:32:23

标签: batch-file vbscript

我有一个在win xp上工作的脚本,但由于某些方法不再可用,我不得不重写脚本并使用mshta.exe。

VBS脚本应该做两件事:

  1. 从文件中读取
  2. 将信息解析为批处理文件
  3. 我已经完成了第1位,但在第2部分我收到了错误。你能指点我正确的方向吗?

    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
    

    我在第33行char 5中收到错误 错误:需要对象:strMSHTA

    谢谢你! :)

1 个答案:

答案 0 :(得分:0)

我必须添加此代码:

Set objFso = CreateObject("Scripting.FileSystemObject")
set strFile = objFso.OpenTextFile(param2, 1, True)
Set objShell = WScript.CreateObject("Wscript.Shell")`