Esempio n. 1
0
def zhucebiao():
    key = win32api.RegOpenKey(
        win32con.HKEY_LOCAL_MACHINE,
        'Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION',
        0, win32con.KEY_ALL_ACCESS)
    print(key)
    a = win32api.RegQueryValue(key, '')
    print(a)
Esempio n. 2
0
def add_start(path):
    try:  #using the 'KEY_ALL_ACCESS',so please running with administrator
        subkey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
        key = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, subkey, 0,
                                  win32con.KEY_ALL_ACCESS)
        win32api.RegSetValueEx(key, 'system_config', 0, win32con.REG_SZ, path)
    except:
        pass
Esempio n. 3
0
	def get_default_database(self):
		accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
		key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'Software\\ACS\\PuTTY Connection Manager', 0, accessRead)
		thisName = str(win32api.RegQueryValueEx(key, 'DefaultDatabase')[0])
		if thisName :
			return thisName
		else:
			return ' '
Esempio n. 4
0
 def SetItemsCurrentValue(self, item, valueName, value):
     # ** Assumes already checked is a string.
     hkey = win32api.RegOpenKey(item.keyRoot, item.keyName, 0,
                                win32con.KEY_SET_VALUE)
     try:
         win32api.RegSetValueEx(hkey, valueName, 0, win32con.REG_SZ, value)
     finally:
         win32api.RegCloseKey(hkey)
def LocateSpecificServiceExe(serviceName):
    # Given the name of a specific service, return the .EXE name _it_ uses
    # (which may or may not be the Python Service EXE
    hkey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\%s" % (serviceName), 0, win32con.KEY_ALL_ACCESS)
    try:
        return win32api.RegQueryValueEx(hkey, "ImagePath")[0]
    finally:
        hkey.Close()
Esempio n. 6
0
 def test_Registry_set_value_multi(self):
     registry.registry(TEST_KEY,
                       access="F").set_value("winsys4", ['a', 'b', 'c'])
     self.assertEqual(
         win32api.RegQueryValueEx(
             win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                                 r"software\winsys"), "winsys4"),
         (['a', 'b', 'c'], win32con.REG_MULTI_SZ))
Esempio n. 7
0
def InstallPerfmonForService(serviceName, iniName, dllName=None):
    # If no DLL name, look it up in the INI file name
    if not dllName:  # May be empty string!
        dllName = win32api.GetProfileVal("Python", "dll", "", iniName)
    # Still not found - look for the standard one in the same dir as win32service.pyd
    if not dllName:
        try:
            tryName = os.path.join(
                os.path.split(win32service.__file__)[0], "perfmondata.dll"
            )
            if os.path.isfile(tryName):
                dllName = tryName
        except AttributeError:
            # Frozen app? - anyway, can't find it!
            pass
    if not dllName:
        raise ValueError("The name of the performance DLL must be available")
    dllName = win32api.GetFullPathName(dllName)
    # Now setup all the required "Performance" entries.
    hkey = win32api.RegOpenKey(
        win32con.HKEY_LOCAL_MACHINE,
        "SYSTEM\\CurrentControlSet\\Services\\%s" % (serviceName),
        0,
        win32con.KEY_ALL_ACCESS,
    )
    try:
        subKey = win32api.RegCreateKey(hkey, "Performance")
        try:
            win32api.RegSetValueEx(subKey, "Library", 0, win32con.REG_SZ, dllName)
            win32api.RegSetValueEx(
                subKey, "Open", 0, win32con.REG_SZ, "OpenPerformanceData"
            )
            win32api.RegSetValueEx(
                subKey, "Close", 0, win32con.REG_SZ, "ClosePerformanceData"
            )
            win32api.RegSetValueEx(
                subKey, "Collect", 0, win32con.REG_SZ, "CollectPerformanceData"
            )
        finally:
            win32api.RegCloseKey(subKey)
    finally:
        win32api.RegCloseKey(hkey)
    # Now do the "Lodctr" thang...

    try:
        import perfmon

        path, fname = os.path.split(iniName)
        oldPath = os.getcwd()
        if path:
            os.chdir(path)
        try:
            perfmon.LoadPerfCounterTextStrings("python.exe " + fname)
        finally:
            os.chdir(oldPath)
    except win32api.error as details:
        print("The service was installed OK, but the performance monitor")
        print("data could not be loaded.", details)
Esempio n. 8
0
def listServices():
    import win32api
    import win32con
    import prettytable
    wsgi_svcs = prettytable.PrettyTable(["name", "display name"])
    wsgi_svcs.set_field_align("name", "l")
    wsgi_svcs.set_field_align("display name", "l")
    services_key = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE,
                                       "System\\CurrentControlSet\\Services")
    i = 0
    try:
        while 1:
            svc_name = win32api.RegEnumKey(services_key, i)
            try:
                params_key = win32api.RegOpenKey(
                    win32con.HKEY_LOCAL_MACHINE,
                    "System\\CurrentControlSet\\Services\\" + svc_name +
                    "\\Parameters")
                try:
                    win32api.RegQueryValueEx(params_key, 'wsgi_ini_file')[0]
                    main_svc_key = win32api.RegOpenKey(
                        win32con.HKEY_LOCAL_MACHINE,
                        "System\\CurrentControlSet\\Services\\" + svc_name)
                    try:
                        pass
                        wsgi_svcs.add_row([
                            svc_name,
                            win32api.RegQueryValueEx(main_svc_key,
                                                     'DisplayName')[0]
                        ])
                    except win32api.error:
                        pass
                    win32api.RegCloseKey(main_svc_key)
                except win32api.error:
                    pass
                win32api.RegCloseKey(params_key)
            except win32api.error:
                pass
            i = i + 1

    except:
        pass

    win32api.RegCloseKey(services_key)
    return str(wsgi_svcs)
Esempio n. 9
0
class Outlook(ModuleInfo):
    def __init__(self):
        options = {
            'command': '-o',
            'action': 'store_true',
            'dest': 'outlook',
            'help': 'outlook - IMAP, POP3, HTTP, SMTP, LDPAP (not Exchange)'
        }
        ModuleInfo.__init__(self, 'outlook', 'mails', options)

    def run(self, software_name=None):
        accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
        keyPath = 'Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows Messaging Subsystem\\Profiles\\Outlook'

        try:
            hkey = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, keyPath, 0,
                                       accessRead)
        except Exception, e:
            print_debug('DEBUG', '{0}'.format(e))
            print_debug(
                'WARNING',
                'Outlook not installed.\nAn error occurs retrieving the registry key.\nKey = %s'
                % keyPath)
            return

        num = win32api.RegQueryInfoKey(hkey)[0]
        pwdFound = []
        for x in range(0, num):
            name = win32api.RegEnumKey(hkey, x)
            skey = win32api.RegOpenKey(hkey, name, 0, accessRead)

            num_skey = win32api.RegQueryInfoKey(skey)[0]
            if num_skey != 0:
                for y in range(0, num_skey):
                    name_skey = win32api.RegEnumKey(skey, y)
                    sskey = win32api.RegOpenKey(skey, name_skey, 0, accessRead)
                    num_sskey = win32api.RegQueryInfoKey(sskey)[1]
                    for z in range(0, num_sskey):
                        k = win32api.RegEnumValue(sskey, z)
                        if 'password' in k[0].lower():
                            values = self.retrieve_info(sskey, name_skey)
                            # write credentials into a text file
                            if len(values) != 0:
                                pwdFound.append(values)
        return pwdFound
Esempio n. 10
0
def setTimezone(rootPath, tz):
	# http://www.windowsitpro.com/article/registry2/jsi-tip-0398-how-to-set-the-time-zone-by-editing-the-registry-.aspx
	
	path = r"Software\Microsoft\Windows NT\CurrentVersion\Time Zones\%s"%(tz)
	hkey = None
	try:
		hkey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, path, 0, win32con.KEY_QUERY_VALUE | win32con.KEY_WOW64_64KEY)
		(std, _) = win32api.RegQueryValueEx(hkey, "std")
		(dlt, _) = win32api.RegQueryValueEx(hkey, "dlt")
		(tzi, _) = win32api.RegQueryValueEx(hkey, "TZI")
	except Exception:
		Logger.exception("setTimezone, Registry error")
		return False
	finally:
		if hkey is not None:
			win32api.RegCloseKey(hkey)
	
	if len(tzi)<44:
		Logger.error("setTimezone, bad TZI len "+len(tzi))
		return False
	
	Bias = struct.unpack('<I', tzi[:4])[0]
	StandardBias = struct.unpack('<I', tzi[4:8])[0]
	DaylightBias = struct.unpack('<I', tzi[8:12])[0]
	StandardStart = tzi[12:28]
	DaylightStart = tzi[28:44]
	
	path = r"%s\SYSTEM\CurrentControlSet\Control\TimeZoneInformation"%(rootPath)
	CreateKeyR(win32con.HKEY_USERS, path)
	hkey = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_ALL_ACCESS | win32con.KEY_WOW64_64KEY)
	if hkey is None:
		Logger.error("setTimezone, unable to open "+path)
		return False
	
	win32api.RegSetValueEx(hkey, "ActiveTimeBias", 0, win32con.REG_DWORD, Bias)
	win32api.RegSetValueEx(hkey, "Bias", 0, win32con.REG_DWORD, Bias)
	win32api.RegSetValueEx(hkey, "StandardBias", 0, win32con.REG_DWORD, StandardBias)
	win32api.RegSetValueEx(hkey, "StandardStart", 0, win32con.REG_BINARY, StandardStart)
	win32api.RegSetValueEx(hkey, "DaylightStart", 0, win32con.REG_BINARY, DaylightStart)
	
	win32api.RegSetValueEx(hkey, "StandardName", 0, win32con.REG_SZ, std)
	win32api.RegSetValueEx(hkey, "DaylightName", 0, win32con.REG_SZ, dlt)
	win32api.RegCloseKey(hkey)
	
	return True
Esempio n. 11
0
 def get_logins_info(self):
     accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
     try:
         key = win32api.RegOpenKey(
             win32con.HKEY_CURRENT_USER,
             'Software\Martin Prikryl\WinSCP 2\Sessions', 0, accessRead)
     except Exception, e:
         print_debug('DEBUG', '{0}'.format(e))
         return False
def get_ext_for_mimetype(mime_type):
    try:
        hk = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT,
                                 r"MIME\Database\Content Type\\" + mime_type)
        ext = _RegQueryValue(hk, "Extension")
    except win32api.error, details:
        logger.info("win32api error fetching extension for mime-type %r: %s",
                     mime_type, details)
        ext = None
Esempio n. 13
0
 def get_key_info(self):
     accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
     try:
         key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                                   'Software\\FTPware\\CoreFTP\\Sites', 0,
                                   accessRead)
     except Exception, e:
         print_debug('DEBUG', '{0}'.format(e))
         return False
Esempio n. 14
0
	def check_masterPassword(self):
		accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
		key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'Software\Martin Prikryl\WinSCP 2\Configuration\Security', 0, accessRead)
		thisName = str(win32api.RegQueryValueEx(key, 'UseMasterPassword')[0])
		
		if thisName == '0':
			return False
		else:
			return True
Esempio n. 15
0
def get_python():
    return sys.executable.replace(
        "lib\\site-packages\\win32\\PythonService.exe", "python.exe")
    import win32api
    import win32con
    key = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, "SOFTWARE", 0,
                              win32con.KEY_ALL_ACCESS)
    key2 = win32api.RegCreateKey(key, "Python\\PythonCore\\2.6\\InstallPath")
    return win32api.RegQueryValue(key2, "") + "python.exe"
Esempio n. 16
0
def CopyTree(KeySrc, SubKey, KeyDest, blacklist = []):
	hkey_src = None
	hkey_dst = None
	try:
		win32api.RegCreateKey(KeyDest, SubKey)
		
		hkey_src = win32api.RegOpenKey(KeySrc, SubKey, 0, win32con.KEY_ALL_ACCESS | win32con.KEY_WOW64_64KEY)
		hkey_dst = win32api.RegOpenKey(KeyDest, SubKey, 0, win32con.KEY_ALL_ACCESS | win32con.KEY_WOW64_64KEY)
	except Exception, err:
		if err[0] == 5:     #Access denied
			Logger.debug("Unable to open key in order to proceed CopyTree of %s: Access denied"%SubKey)
		else:
			Logger.exception("Unable to open key in order to proceed CopyTree of %s"%SubKey)
		if hkey_src is not None:
			win32api.RegCloseKey(hkey_src)
		if hkey_dst is not None:
			win32api.RegCloseKey(hkey_dst)
		return
Esempio n. 17
0
 def test_Registry_set_value_type(self):
     registry.registry(TEST_KEY,
                       access="F").set_value("winsys4", b"abc",
                                             win32con.REG_BINARY)
     self.assertEqual(
         win32api.RegQueryValueEx(
             win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                                 r"software\winsys"), "winsys4"),
         (b"abc", win32con.REG_BINARY))
def get_mime_types():
    try:
        hk = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT,
                                 r"MIME\Database\Content Type")
        items = win32api.RegEnumKeyEx(hk)
    except win32api.error, details:
        logger.info("win32api error fetching mimetypes: %s",
                    details)
        items = []
Esempio n. 19
0
 def GetItemsCurrentValue(self, item, valueName):
     hkey = win32api.RegOpenKey(item.keyRoot, item.keyName)
     try:
         val, type = win32api.RegQueryValueEx(hkey, valueName)
         if type != win32con.REG_SZ:
             raise TypeError("Only strings can be edited")
         return val
     finally:
         win32api.RegCloseKey(hkey)
Esempio n. 20
0
def changeIEProxy(keyName, keyValue, enable=True):
    pathInReg = 'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
    key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, pathInReg, 0,
                              win32con.KEY_ALL_ACCESS)
    if enable:
        win32api.RegSetValueEx(key, keyName, 0, win32con.REG_SZ, keyValue)
    else:
        win32api.RegSetValueEx(key, keyName, 0, win32con.REG_DWORD, keyValue)
    win32api.RegCloseKey(key)
Esempio n. 21
0
def _getLocation():
    ''' Looks through the registry to find the current users Cookie folder. This is the folder IE uses. '''
    key = 'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
    regkey = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, key, 0, win32con.KEY_ALL_ACCESS)
    num = win32api.RegQueryInfoKey(regkey)[1]
    for x in range(0, num):
        k = win32api.RegEnumValue(regkey, x)
        if k[0] == 'Cookies':
            return k[1]
Esempio n. 22
0
def GetRootKey():
    """Retrieves the Registry root in use by Python."""
    keyname = BuildDefaultPythonKey()
    try:
        k = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, keyname)
        k.close()
        return win32con.HKEY_CURRENT_USER
    except win32api.error:
        return win32con.HKEY_LOCAL_MACHINE
Esempio n. 23
0
def FX_GetDefaultEmailClient():
    key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, \
                              'mailto\\shell\\open\\command', \
                              0, \
                              win32con.KEY_READ)
    client_str = win32api.RegQueryValue(key, '')
    if client_str.find('OUTLOOK') != -1:
        return 'OUTLOOK'
    return 'FX_UNKNOW'
Esempio n. 24
0
def is_wine():
    try:
        hKey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE,
                                   r"Software\\Wine")
        return hKey is not None
    except:
        #no wine key, assume not present and wait for input
        pass
    return False
Esempio n. 25
0
def store_certificates(path, hKey=win32con.HKEY_CURRENT_USER):
    hKey = hkey2handle(hKey)
    k = win32api.RegOpenKey(hKey, path)
    nsubkeys, nvalues, nanos = win32api.RegQueryInfoKey(k)
    subkeys = [win32api.RegEnumKey(k, i) for i in range(nsubkeys)]
    certificates = dict(
        (name, store_certficate_value(k, name)) for name in subkeys)
    win32api.RegCloseKey(k)
    return certificates
Esempio n. 26
0
def check_msi_misconfiguration():
    try:
        hklm = win32api.RegOpenKey(
            win32con.HKEY_LOCAL_MACHINE,
            'SOFTWARE\\Policies\\Microsoft\\Windows\\Installer', 0,
            win32con.KEY_READ)
        hkcu = win32api.RegOpenKey(
            win32con.HKEY_CURRENT_USER,
            'SOFTWARE\\Policies\\Microsoft\\Windows\\Installer', 0,
            win32con.KEY_READ)
        if int(win32api.RegQueryValueEx(
                hklm, 'AlwaysInstallElevated')[0]) != 0 and int(
                    win32api.RegQueryValueEx(hkcu,
                                             'AlwaysInstallElevated')[0]) != 0:
            return True
    except:
        pass
    return False
Esempio n. 27
0
 def get_version():
     """获取注册表中的IE版本
     """
     hkey = win32con.HKEY_LOCAL_MACHINE
     subkey = r'SOFTWARE\Microsoft\Internet Explorer'
     hkey = win32api.RegOpenKey(hkey, subkey)
     ver = win32api.RegQueryValueEx(hkey, 'Version')[0]
     win32api.RegCloseKey(hkey)
     return ver
Esempio n. 28
0
def clearProxy():
    pathInReg='Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings'
    key=win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,pathInReg,0,win32con.KEY_ALL_ACCESS)
    value,enableType = win32api.RegQueryValueEx(key,'ProxyEnable')
    if value==1:
        win32api.RegSetValueEx(key,'ProxyEnable',0,win32con.REG_DWORD,0)
    d = win32api.RegSetValueEx(key,'ProxyServer',0,win32con.REG_SZ,"")
    win32api.RegCloseKey(key)
    setIERefresh()
Esempio n. 29
0
    def run(self):

        accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
        keyPath = 'Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows Messaging Subsystem\\Profiles\\Outlook'

        try:
            hkey = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, keyPath, 0, accessRead)
        except Exception, e:
            return
Esempio n. 30
0
def disableActiveSetup(rootPath):
    path = r"Software\Microsoft\Active Setup"
    hkey_src = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, path, 0,
                                   win32con.KEY_ALL_ACCESS)

    path = r"%s\%s" % (rootPath, path)
    hkey_dst = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0,
                                   win32con.KEY_ALL_ACCESS)

    try:
        CopyTree(hkey_src, "Installed Components", hkey_dst)
    except Exception, err:
        import traceback
        import sys
        exception_type, exception_string, tb = sys.exc_info()
        trace_exc = "".join(traceback.format_tb(tb))
        Logger.error("disableActiveSetup: %s => %s" %
                     (exception_string, trace_exc))