Module: Windows::User

Includes:
Beaker::CommandFactory
Included in:
Host
Defined in:
lib/beaker/host/windows/user.rb

Instance Attribute Summary

Attributes included from Beaker::CommandFactory

#assertions

Instance Method Summary collapse

Methods included from Beaker::CommandFactory

#execute, #fail_test

Instance Method Details

#user_absent(name, &block) ⇒ Object


29
30
31
# File 'lib/beaker/host/windows/user.rb', line 29

def user_absent(name, &block)
  execute("net user /delete \"#{name}\"", {:acceptable_exit_codes => [0,2]}, &block)
end

#user_get(name, &block) ⇒ Object


17
18
19
20
21
22
23
# File 'lib/beaker/host/windows/user.rb', line 17

def user_get(name, &block)
  execute("net user \"#{name}\"") do |result|
    fail_test "failed to get user #{name}" if result.exit_code != 0

    yield result if block_given?
  end
end

#user_list(&block) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/beaker/host/windows/user.rb', line 4

def user_list(&block)
  execute('cmd /c echo "" | wmic useraccount where localaccount="true" get name /format:value') do |result|
    users = []
    result.stdout.each_line do |line|
      users << (line.match(/^Name=(.+)/) or next)[1]
    end

    yield result if block_given?

    users
  end
end

#user_present(name, &block) ⇒ Object


25
26
27
# File 'lib/beaker/host/windows/user.rb', line 25

def user_present(name, &block)
  execute("net user /add \"#{name}\"", {:acceptable_exit_codes => [0,2]}, &block)
end