chrome/updater/test/service/win/impersonate.py
def RunAsStandardUser(command_line, env, cwd, timeout):
  """Runs a command as non-elevated logged-on user.

  Args:
    command_line: The command line string, including arguments, to run.
    env: Environment variables for child process, None to inherit.
    cwd: Working directory for child process, None to inherit from parent.
    timeout: How long in seconds should wait for child process.

  Returns:
      (pid, exit_code, sdtout, stderr) tuple.

  Raises:
    ImpersonationError: when impersonation failed.
  """
  logging.info('Running "%s" as the logon user.', command_line)

  # Adjust current process to be part of the trusted computer base.
  current_process_token = win32security.OpenProcessToken(
      win32api.GetCurrentProcess(), win32security.TOKEN_ALL_ACCESS)
  tcb_privilege_flag = win32security.LookupPrivilegeValue(
      None, win32security.SE_TCB_NAME)
  se_enable = win32security.SE_PRIVILEGE_ENABLED
  win32security.AdjustTokenPrivileges(current_process_token, 0,
                                      [(tcb_privilege_flag, se_enable)])

  active_session_id = proc_util.GetActiveSessionID()
  if not active_session_id:
    raise ImpersonationError('Cannot find active logon session.')

  try:
    logon_user_token = win32ts.WTSQueryUserToken(active_session_id)
  except pywintypes.error as err:
    if err.winerror == winerror.ERROR_NO_TOKEN:
      raise ImpersonationError('No user is logged on.')
    else:
      raise ImpersonationError('Failed to get user token: %s' % err)

  return _RunAsOnWindowStationDesktop(
      command_line, logon_user_token, 'WinSta0', 'default', env, cwd, timeout)
Runs a command as non-elevated logged-on user.

  Args:
    command_line: The command line string, including arguments, to run.
    env: Environment variables for child process, None to inherit.
    cwd: Working directory for child process, None to inherit from parent.
    timeout: How long in seconds should wait for child process.

  Returns:
      (pid, exit_code, sdtout, stderr) tuple.

  Raises:
    ImpersonationError: when impersonation failed.
  
Runs a command as non-elevated logged-on user.
Runs a command as non - elevated logged - on user .
def RunAsStandardUser(command_line, env, cwd, timeout):
  logging.info('Running "%s" as the logon user.', command_line)
  current_process_token = win32security.OpenProcessToken(
      win32api.GetCurrentProcess(), win32security.TOKEN_ALL_ACCESS)
  tcb_privilege_flag = win32security.LookupPrivilegeValue(
      None, win32security.SE_TCB_NAME)
  se_enable = win32security.SE_PRIVILEGE_ENABLED
  win32security.AdjustTokenPrivileges(current_process_token, 0,
                                      [(tcb_privilege_flag, se_enable)])
  active_session_id = proc_util.GetActiveSessionID()
  if not active_session_id:
    raise ImpersonationError('Cannot find active logon session.')
  try:
    logon_user_token = win32ts.WTSQueryUserToken(active_session_id)
  except pywintypes.error as err:
    if err.winerror == winerror.ERROR_NO_TOKEN:
      raise ImpersonationError('No user is logged on.')
    else:
      raise ImpersonationError('Failed to get user token: %s' % err)
  return _RunAsOnWindowStationDesktop(
      command_line, logon_user_token, 'WinSta0', 'default', env, cwd, timeout)
def RunAsStandardUser ( command_line , env , cwd , timeout ) : logging . info ( 'Running "%s" as the logon user.' , command_line ) current_process_token = win32security . OpenProcessToken ( win32api . GetCurrentProcess ( ) , win32security . TOKEN_ALL_ACCESS ) tcb_privilege_flag = win32security . LookupPrivilegeValue ( None , win32security . SE_TCB_NAME ) se_enable = win32security . SE_PRIVILEGE_ENABLED win32security . AdjustTokenPrivileges ( current_process_token , 0 , [ ( tcb_privilege_flag , se_enable ) ] ) active_session_id = proc_util . GetActiveSessionID ( ) if not active_session_id : raise ImpersonationError ( 'Cannot find active logon session.' ) try : logon_user_token = win32ts . WTSQueryUserToken ( active_session_id ) except pywintypes . error as err : if err . winerror == winerror . ERROR_NO_TOKEN : raise ImpersonationError ( 'No user is logged on.' ) else : raise ImpersonationError ( 'Failed to get user token: %s' % err ) return _RunAsOnWindowStationDesktop ( command_line , logon_user_token , 'WinSta0' , 'default' , env , cwd , timeout )
Runs a command as non-elevated logged-on user.
Runs a command as non - elevated logged - on user .
"""Runs a command as non-elevated logged-on user.

  Args:
    command_line: The command line string, including arguments, to run.
    env: Environment variables for child process, None to inherit.
    cwd: Working directory for child process, None to inherit from parent.
    timeout: How long in seconds should wait for child process.

  Returns:
      (pid, exit_code, sdtout, stderr) tuple.

  Raises:
    ImpersonationError: when impersonation failed.
  """ # Adjust current process to be part of the trusted computer base.
(pid, exit_code, sdtout, stderr) tuple.
( pid exit_code sdtout stderr ) tuple .
when impersonation failed.
when impersonation failed .
ImpersonationError
command_line
The command line string, including arguments, to run.
The command line string including arguments to run .
env
Environment variables for child process, None to inherit.
Environment variables for child process None to inherit .
cwd
Working directory for child process, None to inherit from parent.
Working directory for child process None to inherit from parent .
timeout
None