Class: Inspec::Resources::VBScript

Inherits:
PowershellScript show all
Defined in:
lib/resources/vbscript.rb

Overview

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

Instance Attribute Summary

Attributes inherited from Cmd

#command

Instance Method Summary collapse

Methods inherited from PowershellScript

#exist?, #strip

Methods inherited from Cmd

#exist?, #exit_status, #stderr, #stdout

Constructor Details

#initialize(vbscript) ⇒ VBScript

Returns a new instance of VBScript.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/resources/vbscript.rb', line 36

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

Instance Method Details

#resultObject



51
52
53
# File 'lib/resources/vbscript.rb', line 51

def result
  @result ||= parse_stdout
end

#to_sObject



55
56
57
# File 'lib/resources/vbscript.rb', line 55

def to_s
  'Windows VBScript'
end