Sha256: e951b41db94e72daebd4c5937e98ecd2eaea93796bc1e03dbd51991503bad77e

Contents?: true

Size: 839 Bytes

Versions: 52

Compression:

Stored size: 839 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=(.+)/) 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}" if result.exit_code != 0

      yield result if block_given?
      result
    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

52 entries across 52 versions & 1 rubygems

Version Path
beaker-4.38.1 lib/beaker/host/windows/user.rb
beaker-4.38.0 lib/beaker/host/windows/user.rb
beaker-4.37.2 lib/beaker/host/windows/user.rb
beaker-4.37.1 lib/beaker/host/windows/user.rb
beaker-4.37.0 lib/beaker/host/windows/user.rb
beaker-4.36.1 lib/beaker/host/windows/user.rb
beaker-4.36.0 lib/beaker/host/windows/user.rb
beaker-4.35.0 lib/beaker/host/windows/user.rb
beaker-4.34.0 lib/beaker/host/windows/user.rb
beaker-4.33.0 lib/beaker/host/windows/user.rb
beaker-4.32.0 lib/beaker/host/windows/user.rb
beaker-4.31.0 lib/beaker/host/windows/user.rb
beaker-4.30.0 lib/beaker/host/windows/user.rb
beaker-4.29.1 lib/beaker/host/windows/user.rb
beaker-4.29.0 lib/beaker/host/windows/user.rb
beaker-4.28.1 lib/beaker/host/windows/user.rb
beaker-4.28.0 lib/beaker/host/windows/user.rb
beaker-4.27.1 lib/beaker/host/windows/user.rb
beaker-4.27.0 lib/beaker/host/windows/user.rb
beaker-4.26.0 lib/beaker/host/windows/user.rb