def run_as_admin(command, cwd=None, environ=None):
  """
  Runs a command as an admin in the specified *cwd* and *environ*.
  On Windows, this creates a temporary directory where this information
  is stored temporarily so that the new process can launch the proper
  subprocess.
  """

  if isinstance(command, str):
    command = shlex.split(command)

  if os.name == 'nt':
    return _run_as_admin_windows(command, cwd, environ)

  elif os.name == 'posix':
    command = ['sudo', '-E'] + list(command)
    sys.exit(subprocess.call(command))

  else:
    raise RuntimeError('Unsupported os: {!r}'.format(os.name))
Runs a command as an admin in the specified *cwd* and *environ*.
  On Windows, this creates a temporary directory where this information
  is stored temporarily so that the new process can launch the proper
  subprocess.