Sha256: 348102a58e61eb1d086d4bf9d8191b85941d0dd5b9834f82ff559025f174dfec

Contents?: true

Size: 852 Bytes

Versions: 93

Compression:

Stored size: 852 Bytes

Contents

module Windows::User
  include Beaker::CommandFactory

  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=([\w ]+)/) or next)[1]
      end

      yield result if block_given?

      users
    end
  end

  def user_get(name, &block)
    execute("net user \"#{name}\"") do |result|
      fail_test "failed to get user #{name}" unless result.stdout =~ /^User name\s+#{name}/

      yield result if block_given?
    end
  end

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

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

Version data entries

93 entries across 93 versions & 1 rubygems

Version Path
beaker-1.15.0 lib/beaker/host/windows/user.rb
beaker-1.14.1 lib/beaker/host/windows/user.rb
beaker-1.14.0 lib/beaker/host/windows/user.rb
beaker-1.13.1 lib/beaker/host/windows/user.rb
beaker-1.13.0 lib/beaker/host/windows/user.rb
beaker-1.12.2 lib/beaker/host/windows/user.rb
beaker-1.12.1 lib/beaker/host/windows/user.rb
beaker-1.12.0 lib/beaker/host/windows/user.rb
beaker-1.11.2 lib/beaker/host/windows/user.rb
beaker-1.11.1 lib/beaker/host/windows/user.rb
beaker-1.11.0 lib/beaker/host/windows/user.rb
beaker-1.10.0 lib/beaker/host/windows/user.rb
beaker-1.9.1 lib/beaker/host/windows/user.rb
beaker-1.9.0 lib/beaker/host/windows/user.rb
beaker-1.8.2 lib/beaker/host/windows/user.rb
beaker-1.8.1 lib/beaker/host/windows/user.rb
beaker-1.8.0 lib/beaker/host/windows/user.rb
beaker-1.7.0 lib/beaker/host/windows/user.rb
beaker-1.6.2 lib/beaker/host/windows/user.rb
beaker-1.6.1 lib/beaker/host/windows/user.rb