Passing variables to VBScript

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
TheEek
Junior Coder
Posts: 31
Joined: Mon Jun 22, 2009 2:53 pm

Passing variables to VBScript

Post by TheEek » Tue Feb 15, 2011 6:07 pm

Using the VBScript found in http://www.mjtnet.com/forum/viewtopic.p ... highlight=.

I managed to get my little script working, it will check a process of a remote system, and save the result in a text file. How do I pass a variable to that script? Anything I do just crashes the script...

Code: Select all

VBSTART
Function GetIn()
  Dim WshShell, oExec, input
  Set WshShell = CreateObject("WScript.Shell")
  Set oExec    = WshShell.Exec("sc.exe \\target_workstation query LIveUpdate")
  input = ""

  Do While True
     If Not oExec.StdOut.AtEndOfStream Then
          input = input & oExec.StdOut.Read(1)
          If oExec.StdOut.AtEndOfStream Then Exit Do
     End If
  Loop

  GetIn = input
End Function
VBEND

let>target_workstation=10.10.10.4
vbeval>GetIn(),result
writeln>c:\temp\output.txt,wres,%result%
In this instance I want to pass "target_workstation" as the variable, so sc.exe queries 10.10.10.4, this could be a hostname as well.

I can just have the line written to a batch file, then use MS to run the batch file, but produces it's own problems.

Any ideas?
[/code]

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Tue Feb 15, 2011 6:30 pm

This should give you the right idea..... I couldn't test it
but the syntax is mostly correct :)

Code: Select all

VBSTART
Function GetIn(host)
  Dim WshShell, oExec, input
  Set WshShell = CreateObject("WScript.Shell")
  Set oExec    = WshShell.Exec("sc.exe \\" + host + " query LIveUpdate")
  input = ""

  Do While True
     If Not oExec.StdOut.AtEndOfStream Then
          input = input & oExec.StdOut.Read(1)
          If oExec.StdOut.AtEndOfStream Then Exit Do
     End If
  Loop

  GetIn = input
End Function
VBEND

let>target_workstation=10.10.10.4
vbeval>GetIn("%target_workstation%"),result
writeln>c:\temp\output.txt,wres,%result%


TheEek
Junior Coder
Posts: 31
Joined: Mon Jun 22, 2009 2:53 pm

Post by TheEek » Tue Feb 15, 2011 6:54 pm

Thanks adroege, works a treat.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts