How to use _openRegistryKeyAnyArch method in fMBT

Best Python code snippet using fMBT_python

fmbtwindows_agent.py

Source:fmbtwindows_agent.py Github

copy

Full Screen

...1568 if not firstKey.startswith("HKEY_") or HKEY == None:1569 raise ValueError("invalid HKEY_* at the beginning of the key %s" % (repr(key),))1570 regKey = _winreg.OpenKey(HKEY, subKey, 0, accessRights)1571 return regKey1572def _openRegistryKeyAnyArch(key, accessRights):1573 regKey = None1574 regError = None1575 for archBits in _g_archRegistryKeys:1576 try:1577 regKey = _openRegistryKey(key, accessRights | archBits)1578 break1579 except OSError, e:1580 regError = e1581 continue1582 if regKey == None:1583 raise regError1584 return regKey1585def kill(*pids):1586 rv = True1587 for pid in pids:1588 handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, pid)1589 if handle:1590 rv = rv and (ctypes.windll.kernel32.TerminateProcess(handle, -1) != 0)1591 ctypes.windll.kernel32.CloseHandle(handle)1592 else:1593 rv = False1594 return rv1595def processList():1596 retval = []1597 MAX_NUMBER_OF_PROCESSES = 1024 * 641598 processIds = (MAX_NUMBER_OF_PROCESSES * DWORD)()1599 bytesReturned = DWORD()1600 if ctypes.windll.psapi.EnumProcesses(processIds,1601 ctypes.sizeof(processIds),1602 ctypes.byref(bytesReturned)) != 0:1603 for procIndex in xrange(bytesReturned.value / ctypes.sizeof(DWORD)):1604 processId = processIds[procIndex]1605 hProcess = ctypes.windll.kernel32.OpenProcess(1606 PROCESS_QUERY_INFORMATION, False, processId)1607 if hProcess:1608 bytesReturned.value = ctypes.sizeof(_filenameBufferW)1609 if ctypes.windll.kernel32.QueryFullProcessImageNameW(1610 hProcess,1611 0, # Win32 path format1612 ctypes.byref(_filenameBufferW),1613 ctypes.byref(bytesReturned)) != 0:1614 retval.append({1615 "pid": int(processId),1616 "ProcessImageFileName": _filenameBufferW.value})1617 ctypes.windll.kernel32.CloseHandle(hProcess)1618 return retval1619def processStatus(pid):1620 hProcess = ctypes.windll.kernel32.OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, False, pid)1621 if hProcess == 0:1622 raise ValueError('cannot get status of process %s' % (pid,))1623 rv = {"pid": pid}1624 if GetProcessMemoryInfo(hProcess,1625 ctypes.byref(_processMemoryCountersEx),1626 ctypes.sizeof(_processMemoryCountersEx)) != 0:1627 for fieldName, fieldType in _processMemoryCountersEx._fields_:1628 if fieldName == "cb":1629 continue1630 rv[fieldName] = int(getattr(_processMemoryCountersEx, fieldName))1631 bytesReturned = DWORD()1632 bytesReturned.value = ctypes.sizeof(_filenameBufferW)1633 if ctypes.windll.kernel32.QueryFullProcessImageNameW(1634 hProcess,1635 0, # Win32 path format1636 ctypes.byref(_filenameBufferW),1637 ctypes.byref(bytesReturned)) != 0:1638 rv["ProcessImageFileName"] = _filenameBufferW.value1639 if ctypes.windll.kernel32.GetProcessTimes(1640 hProcess,1641 ctypes.byref(_creationTime),1642 ctypes.byref(_exitTime),1643 ctypes.byref(_kernelTime),1644 ctypes.byref(_userTime)) != 0:1645 rv["UserTime"] = ((_userTime.dwHighDateTime << 32) + _userTime.dwLowDateTime) / 10000000.01646 rv["KernelTime"] = ((_kernelTime.dwHighDateTime << 32) + _kernelTime.dwLowDateTime) / 10000000.01647 if ctypes.windll.kernel32.GetProcessHandleCount(1648 hProcess,1649 ctypes.byref(_dword)) != 0:1650 rv["HandleCount"] = int(_dword.value)1651 ctypes.windll.kernel32.CloseHandle(hProcess)1652 return rv1653def products(properties=("ProductName", "Publisher",1654 "Version", "VersionString",1655 "InstallDate", "InstallLocation",1656 "InstallSource", "LocalPackage")):1657 retval = []1658 iProductIndex = 01659 cchValueBuf = DWORD(0)1660 enumStatus = ctypes.windll.msi.MsiEnumProductsW(iProductIndex, _filenameBufferW)1661 while enumStatus == 0:1662 productCode = _filenameBufferW.value1663 productInfo = {"ProductCode": productCode}1664 for pname in properties:1665 cchValueBuf.value = ctypes.sizeof(_filenameBufferW)1666 if ctypes.windll.msi.MsiGetProductInfoW(1667 productCode, unicode(pname), _filenameBufferW,1668 ctypes.byref(cchValueBuf)) == 0:1669 productInfo[pname] = _filenameBufferW.value1670 retval.append(productInfo)1671 iProductIndex += 11672 enumStatus = ctypes.windll.msi.MsiEnumProductsW(iProductIndex, _filenameBufferW)1673 return retval1674def setRegistry(key, valueName, value, valueType=None):1675 key = key.replace("/", "\\")1676 if not _winreg:1677 return False1678 if valueType == None:1679 if isinstance(value, basestring):1680 valueType = "REG_SZ"1681 elif isinstance(value, int) or isinstance(value, long):1682 valueType = "REG_DWORD"1683 else:1684 raise TypeError("valueType must be specified for value of %s" %1685 (type(value),))1686 REG_type = getattr(_winreg, valueType, None)1687 if not valueType.startswith("REG_") or REG_type == None:1688 raise ValueError("invalid value type (REG_*): %s" % (repr(valueType),))1689 regKey = _openRegistryKeyAnyArch(key, _winreg.KEY_SET_VALUE)1690 try:1691 _winreg.SetValueEx(regKey, valueName, 0, REG_type, value)1692 finally:1693 _winreg.CloseKey(regKey)1694 return True1695def getRegistry(key, valueName):1696 key = key.replace("/", "\\")1697 regKey = _openRegistryKeyAnyArch(key, _winreg.KEY_QUERY_VALUE)1698 try:1699 value, valueType = _winreg.QueryValueEx(regKey, valueName)1700 finally:1701 _winreg.CloseKey(regKey)1702 return value, _REG_types.get(valueType, None)1703def findRegistry(rootKey, key=None, valueName=None, limit=None):1704 rootKey = rootKey.replace('/', '\\')1705 if key != None:1706 key = re.compile(key.replace('/', '\\'))1707 if valueName != None:1708 valueName = re.compile(valueName)1709 if limit == None:1710 limit = -11711 resultList = []...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful