| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import collections | 5 import collections |
| 6 import ctypes | 6 import ctypes |
| 7 import platform | 7 import platform |
| 8 import re | 8 import re |
| 9 import subprocess | 9 import subprocess |
| 10 import time | 10 import time |
| 11 try: | 11 try: |
| 12 import pywintypes # pylint: disable=F0401 | 12 import pywintypes # pylint: disable=F0401 |
| 13 import win32api # pylint: disable=F0401 | 13 import win32api # pylint: disable=F0401 |
| 14 from win32com.shell import shell # pylint: disable=F0401 |
| 15 from win32com.shell import shellcon # pylint: disable=F0401 |
| 14 import win32con # pylint: disable=F0401 | 16 import win32con # pylint: disable=F0401 |
| 15 import win32process # pylint: disable=F0401 | 17 import win32process # pylint: disable=F0401 |
| 16 except ImportError: | 18 except ImportError: |
| 17 pywintypes = None | 19 pywintypes = None |
| 20 shell = None |
| 21 shellcon = None |
| 18 win32api = None | 22 win32api = None |
| 19 win32con = None | 23 win32con = None |
| 20 win32process = None | 24 win32process = None |
| 21 | 25 |
| 22 from telemetry import decorators | 26 from telemetry import decorators |
| 23 from telemetry.core import exceptions | 27 from telemetry.core import exceptions |
| 24 from telemetry.core.platform import desktop_platform_backend | 28 from telemetry.core.platform import desktop_platform_backend |
| 25 from telemetry.core.platform import platform_backend | 29 from telemetry.core.platform import platform_backend |
| 26 | 30 |
| 27 | 31 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 ('ThreadCount', ctypes.c_ulong)] | 198 ('ThreadCount', ctypes.c_ulong)] |
| 195 | 199 |
| 196 def __init__(self): | 200 def __init__(self): |
| 197 self.size = ctypes.sizeof(self) | 201 self.size = ctypes.sizeof(self) |
| 198 super(PerformanceInfo, self).__init__() | 202 super(PerformanceInfo, self).__init__() |
| 199 | 203 |
| 200 performance_info = PerformanceInfo() | 204 performance_info = PerformanceInfo() |
| 201 ctypes.windll.psapi.GetPerformanceInfo( | 205 ctypes.windll.psapi.GetPerformanceInfo( |
| 202 ctypes.byref(performance_info), performance_info.size) | 206 ctypes.byref(performance_info), performance_info.size) |
| 203 return performance_info | 207 return performance_info |
| 208 |
| 209 def LaunchApplication( |
| 210 self, application, parameters=None, elevate_privilege=False): |
| 211 """Launch an application. Returns a PyHANDLE object.""" |
| 212 |
| 213 # Use ShellExecuteEx() instead of subprocess.Popen()/OpenProcess() to |
| 214 # elevate privileges. A new console will be created if the new process has |
| 215 # different permissions than this process. |
| 216 proc_info = shell.ShellExecuteEx( |
| 217 fMask=shellcon.SEE_MASK_NOCLOSEPROCESS | shellcon.SEE_MASK_NO_CONSOLE, |
| 218 lpVerb='runas' if elevate_privilege else '', |
| 219 lpFile=application, |
| 220 lpParameters=' '.join(parameters) if parameters else [], |
| 221 nShow=win32con.SW_HIDE) |
| 222 if proc_info['hInstApp'] <= 32: |
| 223 raise Exception('Unable to launch %s' % application) |
| 224 return proc_info['hProcess'] |
| OLD | NEW |