Esempio n. 1
0
 def try_delete_user(self):
     try:
         commands_to_delete_user = get_windows_commands_to_delete_user(self.username)
         logger.debug(
             "Trying to delete {} with commands {}".format(self.username, str(commands_to_delete_user)))
         _ = subprocess.check_output(
             commands_to_delete_user, stderr=subprocess.STDOUT, shell=True)
     except Exception as err:
         raise NewUserError("Can't delete user {}. Info: {}".format(self.username, err))
Esempio n. 2
0
 def __enter__(self):
     try:
         # Logon as new user: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf
         # -winbase-logonusera
         self.logon_handle = win32security.LogonUser(
             self.username,
             ".",  # Use current domain.
             self.password,
             # Logon type - interactive (normal user), since we're using a shell.
             win32con.LOGON32_LOGON_INTERACTIVE,
             win32con.LOGON32_PROVIDER_DEFAULT,
         )  # Which logon provider to use - whatever Windows offers.
     except Exception as err:
         raise NewUserError("Can't logon as {}. Error: {}".format(self.username, str(err)))
     return self
Esempio n. 3
0
    def __enter__(self):
        # Importing these only on windows, as they won't exist on linux.
        import win32security
        import win32con

        try:
            # Logon as new user: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-logonusera
            self.logon_handle = win32security.LogonUser(
                self.username,
                ".",  # Use current domain.
                self.password,
                win32con.
                LOGON32_LOGON_INTERACTIVE,  # Logon type - interactive (normal user). Need this to open ping
                # using a shell.
                win32con.LOGON32_PROVIDER_DEFAULT
            )  # Which logon provider to use - whatever Windows offers.
        except Exception as err:
            raise NewUserError("Can't logon as {}. Error: {}".format(
                self.username, str(err)))
        return self