Exemplo n.º 1
0
 def test_Registry_set_value_default(self):
     registry.registry(TEST_KEY, access="F").set_value("", "test")
     self.assertEqual(
         win32api.RegQueryValueEx(
             win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                                 r"software\winsys"), None),
         ("test", win32con.REG_SZ))
Exemplo n.º 2
0
 def test_Registry_set_value_expand_odd_percent(self):
     registry.registry(TEST_KEY, access="F").set_value("winsys4", "50%")
     self.assertEqual(
         win32api.RegQueryValueEx(
             win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                                 r"software\winsys"), "winsys4"),
         ("50%", win32con.REG_SZ))
Exemplo n.º 3
0
 def test_Registry_set_value_non_empty_string(self):
     registry.registry(TEST_KEY, access="F").set_value("winsys4", "winsys")
     self.assertEqual(
         win32api.RegQueryValueEx(
             win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                                 r"software\winsys"), "winsys4"),
         ("winsys", win32con.REG_SZ))
Exemplo n.º 4
0
def set_registry_permissions(student_user):
    reg = registry.registry(r"HKLM\Software\OPE")
    with reg.security() as s:
        # Break inheritance causes things to reapply properly
        s.break_inheritance(copy_first=True)
        if student_user is not None:
            s.dacl.append(
                (student_user, registry.Registry.ACCESS["Q"], "ALLOW"))
        s.dacl.append((accounts.me(), registry.Registry.ACCESS["F"], "ALLOW"))
        # s.dacl.dump()

    reg = registry.registry(r"HKLM\Software\OPE\OPELMS")
    with reg.security() as s:
        # Break inheritance causes things to reapply properly
        s.break_inheritance(copy_first=True)
        if student_user is not None:
            s.dacl.append(
                (student_user, registry.Registry.ACCESS["Q"], "ALLOW"))
        s.dacl.append((accounts.me(), registry.Registry.ACCESS["F"], "ALLOW"))
        # s.dacl.dump()

    reg = registry.registry(r"HKLM\Software\OPE\OPELMS\student")
    with reg.security() as s:
        # Break inheritance causes things to reapply properly
        s.break_inheritance(copy_first=True)
        if student_user is not None:
            s.dacl.append(
                (student_user, registry.Registry.ACCESS["W"], "ALLOW"))
        s.dacl.append((accounts.me(), registry.Registry.ACCESS["F"], "ALLOW"))
Exemplo n.º 5
0
 def test_Registry_set_value_int(self):
     registry.registry(TEST_KEY, access="F").set_value("winsys4", 1)
     self.assertEqual(
         win32api.RegQueryValueEx(
             win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                                 r"software\winsys"), "winsys4"),
         (1, win32con.REG_DWORD))
Exemplo 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))
Exemplo n.º 7
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))
Exemplo n.º 8
0
 def test_Registry_getattr_key(self):
     win32api.RegCreateKey(win32con.HKEY_CURRENT_USER,
                           r"software\winsys\winsys3")
     try:
         self.assertEqual(
             registry.registry(TEST_KEY).winsys3,
             registry.registry(TEST_KEY).get_key("winsys3"))
     finally:
         win32api.RegDeleteKey(win32con.HKEY_CURRENT_USER,
                               r"Software\winsys\winsys3")
Exemplo n.º 9
0
 def test_walk (self):
   walker = registry.walk (TEST_KEY)
   key, subkeys, values = next (walker)
   assert key == registry.registry (TEST_KEY)
   assert list (values) == [("winsys1", GUID), ("winsys2", GUID)]
   key, subkeys, values = next (walker)
   assert key == registry.registry (TEST_KEY) + "win:sys3"
   key, subkeys, values = next (walker)
   assert key == registry.registry (TEST_KEY) + "winsys2"
   assert list (values) == [("winsys2", GUID)]
Exemplo n.º 10
0
 def test_walk (self):
   walker = registry.walk (TEST_KEY)
   key, subkeys, values = next (walker)
   assert key == registry.registry (TEST_KEY)
   assert list (values) == [("winsys1", GUID), ("winsys2", GUID)]
   key, subkeys, values = next (walker)
   assert key == registry.registry (TEST_KEY) + "win:sys3"
   key, subkeys, values = next (walker)
   assert key == registry.registry (TEST_KEY) + "winsys2"
   assert list (values) == [("winsys2", GUID)]
Exemplo n.º 11
0
 def test_walk(self):
     walker = registry.walk(TEST_KEY)
     key, subkeys, values = next(walker)
     self.assertEqual(key, registry.registry(TEST_KEY))
     self.assertEqual(list(values), [("winsys1", GUID), ("winsys2", GUID)])
     key, subkeys, values = next(walker)
     self.assertEqual(key, registry.registry(TEST_KEY) + "win:sys3")
     key, subkeys, values = next(walker)
     self.assertEqual(key, registry.registry(TEST_KEY) + "winsys2")
     self.assertEqual(list(values), [("winsys2", GUID)])
Exemplo n.º 12
0
 def test_walk(self):
     walker = registry.walk(TEST_KEY)
     key, subkeys, values = next(walker)
     self.assertEqual(key, registry.registry(TEST_KEY))
     self.assertEqual(list(values), [("winsys1", GUID),("winsys2", GUID)])
     key, subkeys, values = next(walker)
     self.assertEqual(key, registry.registry(TEST_KEY) + "win:sys3")
     key, subkeys, values = next(walker)
     self.assertEqual(key, registry.registry(TEST_KEY) + "winsys2")
     self.assertEqual(list(values), [("winsys2", GUID)])
Exemplo n.º 13
0
 def test_copy_exists_empty (self):
   key0 = registry.registry (TEST_KEY)
   key1 = registry.registry (TEST_KEY1)
   assert not bool (key1)
   key1.create ()
   assert bool (key1)
   registry.copy (key0, key1)
   try:
     assert keys_are_equal (key0, key1)
   finally:
     key1.delete ()
Exemplo n.º 14
0
 def test_create_does_not_exist_deep (self):
   key1 = registry.registry (TEST_KEY1)
   key2 = registry.registry (TEST_KEY2)
   assert not bool (key1)
   assert not bool (key2)
   registry.create (key2)
   try:
     assert bool (key1)
     assert bool (key2)
   finally:
     key1.delete ()
Exemplo n.º 15
0
 def test_copy_exists_empty (self):
   key0 = registry.registry (TEST_KEY)
   key1 = registry.registry (TEST_KEY1)
   assert not bool (key1)
   key1.create ()
   assert bool (key1)
   registry.copy (key0, key1)
   try:
     assert keys_are_equal (key0, key1)
   finally:
     key1.delete ()
Exemplo n.º 16
0
 def test_create_does_not_exist_deep (self):
   key1 = registry.registry (TEST_KEY1)
   key2 = registry.registry (TEST_KEY2)
   assert not bool (key1)
   assert not bool (key2)
   registry.create (key2)
   try:
     assert bool (key1)
     assert bool (key2)
   finally:
     key1.delete ()
Exemplo n.º 17
0
 def test_copy_exists_empty(self):
     key0 = registry.registry(TEST_KEY)
     key1 = registry.registry(TEST_KEY1)
     self.assertFalse(key1)
     key1.create()
     self.assertTrue(key1)
     registry.copy(key0, key1)
     try:
         self.assertTrue(keys_are_equal(key0, key1))
     finally:
         key1.delete()
Exemplo n.º 18
0
 def test_copy_exists_empty(self):
     key0 = registry.registry(TEST_KEY)
     key1 = registry.registry(TEST_KEY1)
     self.assertFalse(key1)
     key1.create()
     self.assertTrue(key1)
     registry.copy(key0, key1)
     try:
         self.assertTrue(keys_are_equal(key0, key1))
     finally:
         key1.delete()
Exemplo n.º 19
0
 def test_create_does_not_exist_deep(self):
     key1 = registry.registry(TEST_KEY1)
     key2 = registry.registry(TEST_KEY2)
     self.assertFalse(key1)
     self.assertFalse(key2)
     registry.create(key2)
     try:
         self.assertTrue(key1)
         self.assertTrue(key2)
     finally:
         key1.delete()
Exemplo n.º 20
0
 def test_create_does_not_exist_deep(self):
     key1 = registry.registry(TEST_KEY1)
     key2 = registry.registry(TEST_KEY2)
     self.assertFalse(key1)
     self.assertFalse(key2)
     registry.create(key2)
     try:
         self.assertTrue(key1)
         self.assertTrue(key2)
     finally:
         key1.delete()
Exemplo n.º 21
0
 def test_copy_exists_not_empty_keys(self):
     key0 = registry.registry(TEST_KEY)
     key1 = registry.registry(TEST_KEY1)
     self.assertFalse(key1)
     key1.create()
     self.assertTrue(key1)
     try:
         key1.create("winsys4")
         registry.copy(key0, key1)
         self.assertTrue(key0_subset_of_key1(key0, key1))
     finally:
         key1.delete()
Exemplo n.º 22
0
 def test_copy_exists_not_empty_keys (self):
   key0 = registry.registry (TEST_KEY)
   key1 = registry.registry (TEST_KEY1)
   assert not bool (key1)
   key1.create ()
   assert bool (key1)
   try:
     key1.create ("winsys4")
     registry.copy (key0, key1)
     assert key0_subset_of_key1 (key0, key1)
   finally:
     key1.delete ()
Exemplo n.º 23
0
 def test_copy_exists_not_empty_keys (self):
   key0 = registry.registry (TEST_KEY)
   key1 = registry.registry (TEST_KEY1)
   assert not bool (key1)
   key1.create ()
   assert bool (key1)
   try:
     key1.create ("winsys4")
     registry.copy (key0, key1)
     assert key0_subset_of_key1 (key0, key1)
   finally:
     key1.delete ()
Exemplo n.º 24
0
 def test_copy_exists_not_empty_keys(self):
     key0 = registry.registry(TEST_KEY)
     key1 = registry.registry(TEST_KEY1)
     self.assertFalse(key1)
     key1.create()
     self.assertTrue(key1)
     try:
         key1.create("winsys4")
         registry.copy(key0, key1)
         self.assertTrue(key0_subset_of_key1(key0, key1))
     finally:
         key1.delete()
Exemplo n.º 25
0
 def test_copy_exists_not_empty_values (self):
   key0 = registry.registry (TEST_KEY)
   key1 = registry.registry (TEST_KEY1)
   assert not bool (key1)
   key1.create ()
   assert bool (key1)
   try:
     key1.winsys4 = GUID
     registry.copy (key0, key1)
     assert set (set (key1.flat ()) - set (key0.flat ())) == \
       set ([("winsys4", GUID), key1, key1 + "win:sys3", key1 + "winsys2"])
   finally:
     key1.delete ()
Exemplo n.º 26
0
 def test_copy_exists_not_empty_values (self):
   key0 = registry.registry (TEST_KEY)
   key1 = registry.registry (TEST_KEY1)
   assert not bool (key1)
   key1.create ()
   assert bool (key1)
   try:
     key1.winsys4 = GUID
     registry.copy (key0, key1)
     assert set (set (key1.flat ()) - set (key0.flat ())) == \
       set ([("winsys4", GUID), key1, key1 + "win:sys3", key1 + "winsys2"])
   finally:
     key1.delete ()
Exemplo n.º 27
0
 def test_copy_exists_not_empty_values(self):
     key0 = registry.registry(TEST_KEY)
     key1 = registry.registry(TEST_KEY1, access="F")
     self.assertFalse(key1)
     key1.create()
     self.assertTrue(key1)
     try:
         key1.winsys4 = GUID
         registry.copy(key0, key1)
         self.assertEqual(set(set(key1.flat()) - set(key0.flat())),
             set([("winsys4", GUID), key1, key1 + "win:sys3", key1 + "winsys2"])
         )
     finally:
         key1.delete()
Exemplo n.º 28
0
 def test_copy_exists_not_empty_values(self):
     key0 = registry.registry(TEST_KEY)
     key1 = registry.registry(TEST_KEY1, access="F")
     self.assertFalse(key1)
     key1.create()
     self.assertTrue(key1)
     try:
         key1.winsys4 = GUID
         registry.copy(key0, key1)
         self.assertEqual(
             set(set(key1.flat()) - set(key0.flat())),
             set([("winsys4", GUID), key1, key1 + "win:sys3",
                  key1 + "winsys2"]))
     finally:
         key1.delete()
Exemplo n.º 29
0
 def test_walk_access_denied(self):
     with self.assertRaises(registry.exc.x_access_denied):
         key = registry.registry(TEST_KEY,
                                 access=registry.REGISTRY_ACCESS.KEY_NOTIFY)
         walker = registry.walk(key)
         key, keys, values = next(walker)
         list(keys)
Exemplo n.º 30
0
    def __init__(self, computer, name):
        core._WinSysObject.__init__(self)
        self.computer = computer or "."
        self.name = name
        try:
            key = registry.registry(self.REG_ROOT % self.computer).get_key(
                self.name)
        except exc.x_winsys as err:
            warnings.warn(
                "Registry access failed with error: %s; log access may still be possible"
                % err.args[-1])
            values = dict()
        else:
            if key:
                values = dict(key.values())
            else:
                raise exc.x_not_found(None, "EventLog",
                                      r"\\%s\%s" % (self.computer, self.name))

        self.auto_backup_log_files = values.get("AutoBackupLogFiles")
        self.display_name_file = values.get("DisplayNameFile")
        self.display_name_id = values.get("DisplayNameID")
        self.file = values.get("File")
        self.max_size = values.get("MaxSize")
        self.primary_module = values.get("PrimaryModule")
        self.restrict_guest_access = values.get("RestrictGuestAccess")
        self.retention = values.get("Retention")
        self.sources = values.get("Sources")
        self._handle = wrapped(win32evtlog.OpenEventLog, self.computer,
                               self.name)
Exemplo n.º 31
0
    def __init__(self, computer, name):
        core._WinSysObject.__init__(self)
        self.computer = computer or "."
        self.name = name
        try:
            key = registry.registry(self.REG_ROOT % self.computer).get_key(self.name)
        except exc.x_winsys as err:
            warnings.warn("Registry access failed with error: %s; log access may still be possible" % err.args[-1])
            values = dict()
        else:
            if key:
                values = dict(key.values())
            else:
                raise exc.x_not_found(None, "EventLog", r"\\%s\%s" % (self.computer, self.name))

        self.auto_backup_log_files = values.get("AutoBackupLogFiles")
        self.display_name_file = values.get("DisplayNameFile")
        self.display_name_id = values.get("DisplayNameID")
        self.file = values.get("File")
        self.max_size = values.get("MaxSize")
        self.primary_module = values.get("PrimaryModule")
        self.restrict_guest_access = values.get("RestrictGuestAccess")
        self.retention = values.get("Retention")
        self.sources = values.get("Sources")
        self._handle = wrapped(win32evtlog.OpenEventLog, self.computer, self.name)
Exemplo n.º 32
0
def test_create_does_not_exist ():
  key1 = registry.registry (TEST_KEY1)
  assert not bool (key1)
  registry.create (key1)
  try:
    assert bool (key1)
  finally:
    key1.delete ()
Exemplo n.º 33
0
def set_environment(**kwargs):
    root = registry.registry("HKCU")
    env = root.Environment
    for label, value in kwargs.iteritems():
        env.set_value(label, value)
    win32gui.SendMessageTimeout(win32con.HWND_BROADCAST,
                                win32con.WM_SETTINGCHANGE, 0, "Environment",
                                win32con.SMTO_ABORTIFHUNG, 2000)
Exemplo n.º 34
0
 def __init__ (self, computer, name):
   core._WinSysObject.__init__ (self)
   self.computer = computer or "."
   self.name = name
   try:
     key = registry.registry (self.REG_ROOT % self.computer).get_key (self.name)
   except exc.x_winsys, err:
     warnings.warn ("Registry access failed with error: %s; log access may still be possible" % err.args[-1])
     values = dict ()
Exemplo n.º 35
0
def set_environment (**kwargs):
  root = registry.registry ("HKCU")
  env = root.Environment
  for label, value in kwargs.iteritems ():
    env.set_value (label, value)
  win32gui.SendMessageTimeout (
    win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE,
    0, "Environment",
    win32con.SMTO_ABORTIFHUNG, 2000
  )
Exemplo n.º 36
0
    def test_Registry_nonzero_not_exists(self):
        try:
            win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, r"Software\winsys1")
        except win32api.error as error:
            errno, errctx, errmsg = error.args
            if errno != winerror.ERROR_FILE_NOT_FOUND:
                raise
        else:
            raise RuntimeError("Key exists but should not")

        self.assertFalse(registry.registry(TEST_KEY1))
Exemplo n.º 37
0
def test_flat_ignore_access_denied ():
  remove_access (r"software\winsys\winsys2")
  try:
    key = registry.registry (TEST_KEY)
    assert list (registry.flat (key, ignore_access_errors=True)) == [
      key, 
      ("winsys1", GUID), 
      ("winsys2", GUID),
    ]
  finally:
    restore_access (r"software\winsys\winsys2")
Exemplo n.º 38
0
def get_reg_key(key_str, user_name=None):
    reg = registry.registry(key_str)

    with reg.security() as s:
        # Break inheritance causes things to reapply properly
        s.break_inheritance(copy_first=True)
        if user_name is not None:
            s.dacl.append((user_name, "Q", "ALLOW"))
        s.dacl.append((accounts.me(), "F", "ALLOW"))
        # s.dacl.dump()
    return reg
Exemplo n.º 39
0
  def test_Registry_nonzero_not_exists (self):
    try:
      win32api.RegOpenKey (win32con.HKEY_CURRENT_USER, r"Software\winsys1")
    except win32api.error as error:
      errno, errctx, errmsg = error.args
      if errno != winerror.ERROR_FILE_NOT_FOUND:
        raise
    else:
      raise RuntimeError ("Key exists but should not")

    assert not bool (registry.registry (TEST_KEY1))
Exemplo n.º 40
0
 def test_flat (self):
   key = registry.registry (TEST_KEY)
   assert list (registry.flat (key)) == [
     key,
     ("winsys1", GUID),
     ("winsys2", GUID),
     key + "win:sys3",
     ("winsys3", GUID),
     key + "winsys2",
     ("winsys2", GUID)
   ]
Exemplo n.º 41
0
 def test_flat (self):
   key = registry.registry (TEST_KEY)
   assert list (registry.flat (key)) == [
     key,
     ("winsys1", GUID),
     ("winsys2", GUID),
     key + "win:sys3",
     ("winsys3", GUID),
     key + "winsys2",
     ("winsys2", GUID)
   ]
def _get_python_paths(exclude=None, include=None):
	regbase = registry.registry(r"HKLM\SOFTWARE\Python\PythonCore")
	versions = [vers for vers in regbase]
	if exclude:
		versions = [vers for vers in versions if exclude not in vers.name]	
	if include:
		versions = [vers for vers in versions if include in vers.name]	

	install_paths = [_extract_installpath(vers) for vers in versions]
	install_paths = [path for path in install_paths if path is not None]
	return install_paths
Exemplo n.º 43
0
 def test_Registry_security(self):
     security_information = win32security.OWNER_SECURITY_INFORMATION | win32security.DACL_SECURITY_INFORMATION
     key = registry.registry(TEST_KEY)
     security = key.security(security_information)
     sd = win32security.GetSecurityInfo(
         win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                             r"software\winsys"),
         win32security.SE_REGISTRY_KEY, security_information)
     self.assertEqual(
         security.as_string(),
         win32security.ConvertSecurityDescriptorToStringSecurityDescriptor(
             sd, win32security.SDDL_REVISION_1, security_information))
Exemplo n.º 44
0
 def remove_key(key_path):
     try:
         # Open the key
         key = registry.registry(key_path, 
             access=REGISTRY_ACCESS.KEY_READ|REGISTRY_ACCESS.KEY_WOW64_64KEY)
         key.delete()
     except Exception as ex:
         p("}}rnError - couldn't remove registry key }}xx\n" + str(key_path) + "\n" + \
             str(ex), debug_level=1)
         return False
     
     return True
Exemplo n.º 45
0
 def __init__(self, computer, name):
     core._WinSysObject.__init__(self)
     self.computer = computer or "."
     self.name = name
     try:
         key = registry.registry(self.REG_ROOT % self.computer).get_key(
             self.name)
     except exc.x_winsys, err:
         warnings.warn(
             "Registry access failed with error: %s; log access may still be possible"
             % err.args[-1])
         values = dict()
Exemplo n.º 46
0
 def test_flat_ignore_access_denied(self):
     remove_access(r"software\winsys\winsys2")
     try:
         key = registry.registry(TEST_KEY)
         self.assertEqual(
             list(registry.flat(key, ignore_access_errors=True)), [
                 key,
                 ("winsys1", GUID),
                 ("winsys2", GUID),
                 key + "win:sys3",
                 ("winsys3", GUID),
             ])
     finally:
         restore_access(r"software\winsys\winsys2")
Exemplo n.º 47
0
 def test_flat(self):
     key = registry.registry(TEST_KEY)
     self.assertEqual(
         list(registry.flat(key)),
         [
             key,
          ("winsys1", GUID),
          ("winsys2", GUID),
             key + "win:sys3",
          ("winsys3", GUID),
             key + "winsys2",
          ("winsys2", GUID)
         ]
     )
Exemplo n.º 48
0
 def test_flat_ignore_access_denied(self):
     remove_access(r"software\winsys\winsys2")
     try:
         key = registry.registry(TEST_KEY)
         self.assertEqual(
             list(registry.flat(key, ignore_access_errors=True)),
             [
             key,
          ("winsys1", GUID),
          ("winsys2", GUID),
             key + "win:sys3",
          ("winsys3", GUID),
         ])
     finally:
         restore_access(r"software\winsys\winsys2")
Exemplo n.º 49
0
 def test_Registry_security (self):
   security_information = win32security.OWNER_SECURITY_INFORMATION | win32security.DACL_SECURITY_INFORMATION
   key = registry.registry (TEST_KEY)
   security = key.security (security_information)
   sd = win32security.GetSecurityInfo (
     win32api.RegOpenKey (win32con.HKEY_CURRENT_USER, r"software\winsys"),
     win32security.SE_REGISTRY_KEY,
     security_information
   )
   assert \
     security.as_string () == \
       win32security.ConvertSecurityDescriptorToStringSecurityDescriptor (
         sd,
         win32security.SDDL_REVISION_1,
         security_information
       )
Exemplo n.º 50
0
 def __init__ (self, computer, name):
   core._WinSysObject.__init__ (self)
   self.computer = computer or "."
   self.name = name
   key = registry.registry (self.REG_ROOT % self.computer).get_key (self.name)
   if not key:
     raise x_not_found (None, "EventLog", r"\\%s\%s" % (self.computer, self.name))
   else:
     values = dict (key.values ())
     self.auto_backup_log_files = values.get ("AutoBackupLogFiles")
     self.display_name_file = values.get ("DisplayNameFile")
     self.display_name_id = values.get ("DisplayNameID")
     self.file = values.get ("File")
     self.max_size = values.get ("MaxSize")
     self.primary_module = values.get ("PrimaryModule")
     self.restrict_guest_access = values.get ("RestrictGuestAccess")
     self.retention = values.get ("Retention")
     self.sources = values.get ("Sources")
   self._handle = wrapped (win32evtlog.OpenEventLog, self.computer, self.name)
Exemplo n.º 51
0
 def __init__(self, computer, log_name, source_name):
     core._WinSysObject.__init__(self)
     self.computer = computer or "."
     self.log_name = log_name or DEFAULT_LOG_NAME
     self.name = source_name
     key = registry.registry(r"%s\%s\%s" % (EventLog.REG_ROOT % self.computer, self.log_name, self.name))
     if not key:
         raise exc.x_not_found(None, "EventSource", r"\\%s\%s\%s" % (self.computer, self.log_name, self.name))
     self._handle = None
     values = dict(key.values())
     types = dict((name, type) for (name, value, type) in key.values(_want_types=True))
     self.category_count = values.get("CategoryCount")
     self.category_message_file = values.get("CategoryMessageFile")
     self.event_message_file = values.get("EventMessageFile")
     self.parameter_message_file = values.get("ParameterMessageFile")
     types_supported = values.get("TypesSupported") or 0
     #
     # This is messy because, although TypeSupported is specified
     # as a DWORD and constitutes a set of flags, it seems to be
     # implemented in any number of ingenious ways, including
     # binary data representing a number and a string representing
     # the hexadecimal value of the flags.
     #
     try:
         self.types_supported = int(types_supported or 0)
     except ValueError:
         types_type = types.get("TypesSupported")
         if types_type == registry.REGISTRY_VALUE_TYPE.REG_SZ:
             if types_supported.startswith("0x"):
                 self.types_supported = int(types_supported, 16)
             else:
                 self.types_supported = int(types_supported, 10)
         elif types_type == registry.REGISTRY_VALUE_TYPE.REG_BINARY:
             self.types_supported, = struct.unpack("L", types_supported)
         else:
             raise x_event_logs(None, None, "Can't determine types supported")
Exemplo n.º 52
0
from winsys import registry, environment

def munge_path(env, python_paths):
    #env['PATH'] =
    print ";".join(
        p for p in env['PATH'].split(";") if not any(
            p.lower().startswith(py) for py in python_paths
        )
    )

py = registry.registry(r"hklm\software\python\pythoncore")
py_paths = set(version.InstallPath.get_value("").rstrip("\\").lower() for version in py)
py = registry.registry(r"hkcu\software\python\pythoncore")
py_paths.update(version.InstallPath.get_value("").rstrip("\\").lower() for version in py)

munge_path(environment.user(), py_paths)
munge_path(environment.system(), py_paths)
Exemplo n.º 53
0
def get_environment ():
  return dict (
    registry.registry (r"HKCU\Environment").itervalues ()
  )
Exemplo n.º 54
0
 def setUp(self):
     event_logs.EventSource.create(GUID, LOG_NAME)
     self.registry_root = registry.registry(r"HKLM\SYSTEM\CurrentControlSet\Services\Eventlog")
Exemplo n.º 55
0

from winsys import dialogs, registry

root, term = dialogs.dialog (
  "Search the Registry",
  ("Root", registry.REGISTRY_HIVE.keys ()),
  ("Term", "")
)

root = registry.registry (root)
term = term.lower ()
for key, subkeys, values in root.walk (ignore_access_errors=True):
  for name, value in values:
    if term in str (value).lower ():
      print key.moniker.encode ("utf8")
      print name.encode ("utf8") or "(Default)"
      print unicode (value).encode ("utf8")
      print
 

Exemplo n.º 56
0
 def __init__(self, root):
     super(Persistent, self).__init__()
     self.registry = registry.registry(root)
Exemplo n.º 57
0
def event_sources(log_name=DEFAULT_LOG_NAME, computer="."):
    """Simple iterator over all the event sources for a named log
    """
    for key in registry.registry(EventLog.REG_ROOT % computer).get_key(log_name).keys():
        yield EventSource(computer, log_name, key.name)
Exemplo n.º 58
0
def event_logs(computer="."):
    """Simple iterator over all known event logs.
    """
    for key in registry.registry(EventLog.REG_ROOT % computer).keys():
        yield EventLog(computer, key.name)