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.



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

def initialize(vbscript)
  return skip_resource 'The `vbscript` resource is not supported on your OS yet.' unless inspec.os.windows?
  @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



53
54
55
# File 'lib/resources/vbscript.rb', line 53

def result
  @result ||= parse_stdout
end

#to_sObject



57
58
59
# File 'lib/resources/vbscript.rb', line 57

def to_s
  'Windows VBScript'
end