class Inspec::Resources::VBScript
This resource allows users to run vbscript on windows machines. We decided not to use scriptcontrol, due to the fact that it works on 32 bit systems only: $script = new-object -comobject MSScriptControl.ScriptControl $script.language = “vbscript” $script.ExecuteStatement($Cmd)
For that reason, we call csript.exe directy with the script. Vbscript is embedded in Powershell
to ease the file transfer and reuse powershell encodedCommand since train does not allow file upload yet.
We run cscript with /nologo option to get the expected output only with the version information.
Since Windows does not delete tmp files automatically, we remove the VBScript
after we executed it @see msdn.microsoft.com/en-us/library/aa364991.aspx
Public Class Methods
new(vbscript)
click to toggle source
Calls superclass method
Inspec::Resources::Powershell::new
# File lib/inspec/resources/vbscript.rb, line 35 def initialize(vbscript) @seperator = SecureRandom.uuid cmd = <<~EOH $vbscript = @" #{vbscript} Wscript.Stdout.Write "#{@seperator}" "@ $filename = [System.IO.Path]::GetTempFileName() + ".vbs" New-Item $filename -type file -force -value $vbscript | Out-Null cscript.exe /nologo $filename Remove-Item $filename | Out-Null EOH super(cmd) end
Public Instance Methods
result()
click to toggle source
# File lib/inspec/resources/vbscript.rb, line 50 def result @result ||= parse_stdout end
to_s()
click to toggle source
# File lib/inspec/resources/vbscript.rb, line 54 def to_s "Windows VBScript" end
Private Instance Methods
parse_stdout()
click to toggle source
# File lib/inspec/resources/vbscript.rb, line 60 def parse_stdout res = inspec.backend.run_command(@command) parsed_result = res.stdout.gsub(/#{@seperator}\r\n$/, "") res.stdout = parsed_result res end