Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/10se1ucgo/DisableWinTracking.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Galkin <leks.molecul@gmail.com>2019-01-05 06:11:25 +0300
committerAlexey Galkin <leks.molecul@gmail.com>2019-01-05 06:43:17 +0300
commit6c5f17b00cf5545ef37e4b8905a829682237f854 (patch)
tree3861ed8649c717f291e79e0872c97f9d876002ba
parent5f13d302c0f9d33999b891c1b76c8e0e12cf9576 (diff)
Fix code-write style (with pep7)
-rw-r--r--dwt.py235
-rw-r--r--dwt_util.py251
2 files changed, 257 insertions, 229 deletions
diff --git a/dwt.py b/dwt.py
index 0864cc6..21f5ac2 100644
--- a/dwt.py
+++ b/dwt.py
@@ -28,52 +28,54 @@ from wx.lib.itemspicker import ItemsPicker, IP_SORT_SELECTED, IP_SORT_CHOICES, I
import dwt_about
import dwt_util
+
class RedirectText(io.StringIO):
- def __init__(self, console, old_stdout):
- super(RedirectText, self).__init__()
+ def __init__(self, cli, old_stdout):
+ super(RedirectText, self).__init__()
- self.out = console
- self.old_out = old_stdout
+ self.out = cli
+ self.old_out = old_stdout
- def write(self, string):
- # Oh my god this is the DUMBEST THING I've ever done. (Keeping a reference to the old stdout)
- self.old_out.write(string)
- self.out.WriteText(string)
+ def write(self, string):
+ # Oh my god this is the DUMBEST THING I've ever done. (Keeping a reference to the old stdout)
+ self.old_out.write(string)
+ self.out.WriteText(string)
class ConsoleDialog(wx.Dialog):
- def __init__(self, old_stdout):
- wx.Dialog.__init__(self, parent=wx.GetApp().TopWindow, title="Console Output", size=(500, 200),
- style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
+ def __init__(self, old_stdout):
+ wx.Dialog.__init__(
+ self, parent=wx.GetApp().TopWindow, title="Console Output", size=(500, 200),
+ style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
- console_box = wx.TextCtrl(self, style=wx.TE_MULTILINE | wx.TE_READONLY)
- sys.stdout = RedirectText(console_box, old_stdout)
+ console_box = wx.TextCtrl(self, style=wx.TE_MULTILINE | wx.TE_READONLY)
+ sys.stdout = RedirectText(console_box, old_stdout)
- top_sizer = wx.BoxSizer(wx.VERTICAL)
- console_sizer = wx.BoxSizer(wx.VERTICAL)
- button_sizer = self.CreateButtonSizer(wx.OK | wx.CANCEL)
+ top_sizer = wx.BoxSizer(wx.VERTICAL)
+ console_sizer = wx.BoxSizer(wx.VERTICAL)
+ button_sizer = self.CreateButtonSizer(wx.OK | wx.CANCEL)
- report_button = wx.FindWindowById(wx.ID_CANCEL, self)
- report_button.SetLabel("Report an issue")
+ report_button = wx.FindWindowById(wx.ID_CANCEL, self)
+ report_button.SetLabel("Report an issue")
- console_sizer.Add(console_box, 1, wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ALIGN_TOP, 5)
+ console_sizer.Add(console_box, 1, wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ALIGN_TOP, 5)
- top_sizer.Add(console_sizer, 1, wx.ALL | wx.EXPAND, 5)
- top_sizer.Add(button_sizer, 0, wx.ALL | wx.ALIGN_LEFT, 5)
+ top_sizer.Add(console_sizer, 1, wx.ALL | wx.EXPAND, 5)
+ top_sizer.Add(button_sizer, 0, wx.ALL | wx.ALIGN_LEFT, 5)
- self.Bind(wx.EVT_CLOSE, handler=lambda x: sys.exit(0))
- self.Bind(wx.EVT_BUTTON, handler=lambda x: sys.exit(0), id=wx.ID_OK)
- self.Bind(wx.EVT_BUTTON, source=report_button, handler=self.submit_issue)
- self.SetSizer(top_sizer)
+ self.Bind(wx.EVT_CLOSE, handler=lambda x: sys.exit(0))
+ self.Bind(wx.EVT_BUTTON, handler=lambda x: sys.exit(0), id=wx.ID_OK)
+ self.Bind(wx.EVT_BUTTON, source=report_button, handler=self.submit_issue)
+ self.SetSizer(top_sizer)
- def submit_issue(self, event):
- webbrowser.open_new_tab("https://github.com/10se1ucgo/DisableWinTracking/issues/new")
+ def submit_issue(self, event):
+ webbrowser.open_new_tab("https://github.com/10se1ucgo/DisableWinTracking/issues/new")
class MainFrame(wx.Frame):
- def __init__(self):
- super(MainFrame, self).__init__(parent=wx.GetApp().GetTopWindow(), title="Disable Windows 10 Tracking",
- size=(415, 245))
+ def __init__(self):
+ super(MainFrame, self).__init__(
+ parent=wx.GetApp().GetTopWindow(), title="Disable Windows 10 Tracking", size=(415, 245))
self.SetMinSize(self.GetSize())
panel = MainPanel(self)
@@ -111,13 +113,13 @@ class MainPanel(wx.Panel):
self.service_check.SetToolTip("Disables or deletes tracking services. Choose option in 'Services Method'")
self.diagtrack_check = wx.CheckBox(self, label="Clear DiagTrack log")
- self.diagtrack_check.SetToolTip("Clears Dianostic Tracking log and prevents modification to it. "
- "Cannot be undone automatically.")
+ self.diagtrack_check.SetToolTip(
+ "Clears Dianostic Tracking log and prevents modification to it. Cannot be undone automatically.")
# Telemetry checkbox
self.telemetry_check = wx.CheckBox(self, label="Telemetry")
- self.telemetry_check.SetToolTip("Sets 'AllowTelemetry' to 0. "
- "On non-Enterprise OS editions, requires HOSTS file modification.")
+ self.telemetry_check.SetToolTip(
+ "Sets 'AllowTelemetry' to 0. On non-Enterprise OS editions, requires HOSTS file modification.")
# HOSTS file checkbox
self.host_check = wx.CheckBox(self, label="Block tracking domains")
@@ -125,8 +127,9 @@ class MainPanel(wx.Panel):
# Extra HOSTS checkbox
self.extra_host_check = wx.CheckBox(self, label="Block even more tracking domains")
- self.extra_host_check.SetToolTip("For the paranoid. Adds extra domains to the HOSTS file.\n"
- "May cause issues with Skype, Dr. Watson, Hotmail and/or Error Reporting.")
+ self.extra_host_check.SetToolTip(
+ "For the paranoid. Adds extra domains to the HOSTS file.\n"
+ "May cause issues with Skype, Dr. Watson, Hotmail and/or Error Reporting.")
# IP block checkbox
self.ip_check = wx.CheckBox(self, label="Block tracking IP addresses")
@@ -134,8 +137,8 @@ class MainPanel(wx.Panel):
# Windows Privacy Regs (Policy Manager)
self.defender_check = wx.CheckBox(self, label="Windows Defender collection")
- #self.defender_check.SetToolTip("Modifies registry to prevent Defender collection")
- #Disable defender option until a solution is found.
+ # self.defender_check.SetToolTip("Modifies registry to prevent Defender collection")
+ # Disable defender option until a solution is found.
self.defender_check.SetToolTip("Disable due to limitation set by windows kernel.")
self.defender_check.Enable(False)
@@ -156,9 +159,8 @@ class MainPanel(wx.Panel):
go_button = wx.Button(self, label="Go!")
- #Temporarily removed due to issues with not being able to restore apps properly
- #This was honestly beyond the scope of the project to begin with and shouldn't have been implemented
-
+ # Temporarily removed due to issues with not being able to restore apps properly
+ # This was honestly beyond the scope of the project to begin with and shouldn't have been implemented
'''self.app_box = wx.StaticBoxSizer(wx.VERTICAL, self, "Built-in Apps")
stat_box = self.app_box.GetStaticBox()
@@ -228,7 +230,7 @@ class MainPanel(wx.Panel):
rad_sizer = wx.BoxSizer(wx.VERTICAL)
top_sizer.Add(top_row_sizer, 0, wx.ALL, 5)
- #top_sizer.Add(self.app_box, 0, wx.ALL, 5)
+ # top_sizer.Add(self.app_box, 0, wx.ALL, 5)
top_row_sizer.Add(check_sizer, 0, wx.ALL)
top_row_sizer.Add(rad_sizer, 0, wx.ALL)
rad_sizer.Add(self.service_rad, 0, wx.ALL, 10)
@@ -244,10 +246,10 @@ class MainPanel(wx.Panel):
check_sizer.Add(self.wifisense_check, 0, wx.ALL, 1)
check_sizer.Add(self.onedrive_check, 0, wx.ALL, 1)
- #self.Bind(wx.EVT_CHECKBOX, handler=self.select_all_apps, source=select_all_check)
+ # self.Bind(wx.EVT_CHECKBOX, handler=self.select_all_apps, source=select_all_check)
self.Bind(wx.EVT_CHECKBOX, handler=self.ip_warn, source=self.ip_check)
self.Bind(wx.EVT_CHECKBOX, handler=self.hosts_warn, source=self.extra_host_check)
- #self.Bind(wx.EVT_BUTTON, handler=self.remove_apps, source=remove_app_button)
+ # self.Bind(wx.EVT_BUTTON, handler=self.remove_apps, source=remove_app_button)
self.Bind(wx.EVT_BUTTON, handler=self.go, source=go_button)
self.SetSizer(top_sizer)
@@ -261,10 +263,11 @@ class MainPanel(wx.Panel):
def ip_warn(self, event):
# Warn users about the potential side effects of the IP blocking firewall rules
if event.IsChecked():
- warn = wx.MessageDialog(parent=self,
- message="This option could potentially disable Microsoft Licensing traffic and thus "
- "certain games and apps may cease to work, such as, Forza, or Gears of War.",
- caption="Attention!", style=wx.YES_NO | wx.ICON_EXCLAMATION)
+ warn = wx.MessageDialog(
+ parent=self,
+ message="""This option could potentially disable Microsoft Licensing traffic and thus certain games
+ and apps may cease to work, such as, Forza, or Gears of War.""",
+ caption="Attention!", style=wx.YES_NO | wx.ICON_EXCLAMATION)
if warn.ShowModal() == wx.ID_NO:
event.GetEventObject().SetValue(False)
@@ -274,10 +277,10 @@ class MainPanel(wx.Panel):
def hosts_warn(self, event):
# Warn users about the potential side effects of the extra hosts mod.
if event.IsChecked():
- warn = wx.MessageDialog(parent=self,
- message="This option could potentially disable one or more of the following "
- "services:\n\nSkype, Hotmail, Dr. Watson and/or Error Reporting. Continue?",
- caption="Attention!", style=wx.YES_NO | wx.ICON_EXCLAMATION)
+ warn = wx.MessageDialog(
+ parent=self, caption="Attention!", style=wx.YES_NO | wx.ICON_EXCLAMATION,
+ message="""This option could potentially disable one or more of the following services:
+ \n\nSkype, Hotmail, Dr. Watson and/or Error Reporting. Continue?""")
if warn.ShowModal() == wx.ID_NO:
event.GetEventObject().SetValue(False)
@@ -315,18 +318,19 @@ class MainPanel(wx.Panel):
if self.onedrive_check.IsChecked():
dwt_util.onedrive(undo=undo)
logger.info("Done. It's recommended that you reboot as soon as possible for the full effect.")
- logger.info(("If you feel something didn't work properly, please press the 'Report an issue'"
- " button and follow the directions"))
+ logger.info(
+ "If you feel something didn't work properly, please press the "
+ "'Report an issue' button and follow the directions")
console.Center()
console.Show()
- def remove_apps(self, event):
+ def remove_apps(self):
children = [child for child in self.app_box.GetStaticBox().GetChildren() if child.GetName() != "check"]
app_list = [child.GetName() for child in children if isinstance(child, wx.CheckBox) and child.IsChecked()]
dwt_util.app_manager(app_list, undo=False)
- def settings(self, event, silent=False):
- if silent == False:
+ def settings(self, event, silent_flag=False):
+ if not silent_flag:
dialog = wx.Dialog(parent=self, title="Settings", style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
sizer = wx.BoxSizer(wx.VERTICAL)
@@ -376,31 +380,37 @@ class MainPanel(wx.Panel):
'137.116.81.24', '157.56.106.189', '204.79.197.200', '65.52.108.33', '64.4.54.254'
)
- normal_domain_picker = ItemsPicker(dialog, choices=[], selectedLabel="Domains to be blocked",
- ipStyle=IP_SORT_SELECTED | IP_SORT_CHOICES | IP_REMOVE_FROM_CHOICES)
+ normal_domain_picker = ItemsPicker(
+ dialog, choices=[], selectedLabel="Domains to be blocked",
+ ipStyle=IP_SORT_SELECTED | IP_SORT_CHOICES | IP_REMOVE_FROM_CHOICES)
+
if self.picked_normal:
normal_domain_picker.SetSelections(self.picked_normal)
normal_domain_picker.SetItems([domain for domain in normal_domains if domain not in self.picked_normal])
else:
normal_domain_picker.SetSelections(normal_domains)
- extra_domain_picker = ItemsPicker(dialog, choices=[], selectedLabel="Extra domains to be blocked",
- ipStyle=IP_SORT_SELECTED | IP_SORT_CHOICES | IP_REMOVE_FROM_CHOICES)
+ extra_domain_picker = ItemsPicker(
+ dialog, choices=[], selectedLabel="Extra domains to be blocked",
+ ipStyle=IP_SORT_SELECTED | IP_SORT_CHOICES | IP_REMOVE_FROM_CHOICES)
+
if self.picked_extra:
extra_domain_picker.SetSelections(self.picked_extra)
extra_domain_picker.SetItems([domain for domain in extra_domains if domain not in self.picked_extra])
else:
extra_domain_picker.SetSelections(extra_domains)
- ip_picker = ItemsPicker(dialog, choices=[], selectedLabel="IP addresses to be blocked",
- ipStyle=IP_SORT_SELECTED | IP_SORT_CHOICES | IP_REMOVE_FROM_CHOICES)
+ ip_picker = ItemsPicker(
+ dialog, choices=[], selectedLabel="IP addresses to be blocked",
+ ipStyle=IP_SORT_SELECTED | IP_SORT_CHOICES | IP_REMOVE_FROM_CHOICES)
+
if self.picked_ips:
ip_picker.SetSelections(self.picked_ips)
ip_picker.SetItems([ip for ip in ip_addresses if ip not in self.picked_ips])
else:
ip_picker.SetSelections(ip_addresses)
- if silent == False:
+ if not silent_flag:
sizer.Add(normal_domain_picker, 0, wx.EXPAND)
sizer.Add(extra_domain_picker, 0, wx.EXPAND)
sizer.Add(ip_picker, 0, wx.EXPAND)
@@ -416,57 +426,63 @@ class MainPanel(wx.Panel):
def setup_logging():
- global logger
- logger = logging.getLogger('dwt')
- logger.setLevel(logging.DEBUG)
-
- formatter = logging.Formatter(fmt='%(asctime)s %(levelname)s: %(message)s', datefmt='%H:%M:%S')
-
- stdout_log = logging.StreamHandler(sys.stdout)
- stdout_log.setLevel(logging.DEBUG)
- stdout_log.setFormatter(formatter)
- logger.addHandler(stdout_log)
-
- try:
- file_log = logging.FileHandler(filename='dwt.log')
- file_log.setLevel(logging.DEBUG)
- file_log.setFormatter(formatter)
- logger.addHandler(file_log)
- except (OSError, IOError):
- error_dialog = wx.MessageDialog(parent=wx.GetApp().GetTopWindow(),
- message="Could not create log file, errors will not be recorded!",
- caption="ERROR!", style=wx.OK | wx.ICON_ERROR)
- error_dialog.ShowModal()
- error_dialog.Destroy()
- logger.exception("Could not create log file.")
-
- logger.info("Python {version} on {platform}".format(version=sys.version, platform=sys.platform))
- logger.info(platform.uname())
- logger.info("DisableWinTracking version {v}".format(v=dwt_about.__version__))
+ global logger
+ logger = logging.getLogger('dwt')
+ logger.setLevel(logging.DEBUG)
+
+ formatter = logging.Formatter(fmt='%(asctime)s %(levelname)s: %(message)s', datefmt='%H:%M:%S')
+
+ stdout_log = logging.StreamHandler(sys.stdout)
+ stdout_log.setLevel(logging.DEBUG)
+ stdout_log.setFormatter(formatter)
+ logger.addHandler(stdout_log)
+
+ try:
+ file_log = logging.FileHandler(filename='dwt.log')
+ file_log.setLevel(logging.DEBUG)
+ file_log.setFormatter(formatter)
+ logger.addHandler(file_log)
+ except (OSError, IOError):
+ error_dialog = wx.MessageDialog(
+ parent=wx.GetApp().GetTopWindow(),
+ message="Could not create log file, errors will not be recorded!",
+ caption="ERROR!", style=wx.OK | wx.ICON_ERROR)
+ error_dialog.ShowModal()
+ error_dialog.Destroy()
+ logger.exception("Could not create log file.")
+
+ logger.info("Python {version} on {platform}".format(version=sys.version, platform=sys.platform))
+ logger.info(platform.uname())
+ logger.info("DisableWinTracking version {v}".format(v=dwt_about.__version__))
def exception_hook(error, value, trace):
- error_message = ''.join(traceback.format_exception(error, value, trace))
- logger.critical(error_message)
- error_dialog = wx.MessageDialog(parent=wx.GetApp().GetTopWindow(),
- message="An error has occured!\n\n" + error_message,
- caption="ERROR!", style=wx.OK | wx.CANCEL | wx.ICON_ERROR)
- error_dialog.SetOKCancelLabels("Ignore", "Quit")
- if error_dialog.ShowModal() == wx.ID_OK:
- error_dialog.Destroy()
- else:
- error_dialog.Destroy()
- sys.exit(1)
-
-def check_elevated(silent=False):
+ error_message = ''.join(traceback.format_exception(error, value, trace))
+ logger.critical(error_message)
+ error_dialog = wx.MessageDialog(
+ parent=wx.GetApp().GetTopWindow(),
+ message="An error has occured!\n\n" + error_message,
+ caption="ERROR!", style=wx.OK | wx.CANCEL | wx.ICON_ERROR)
+ error_dialog.SetOKCancelLabels("Ignore", "Quit")
+ if error_dialog.ShowModal() == wx.ID_OK:
+ error_dialog.Destroy()
+ else:
+ error_dialog.Destroy()
+ sys.exit(1)
+
+
+def check_elevated(silent_flag=False):
if not bool(windll.advpack.IsNTAdmin(0, None)):
- if silent:
- windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), u"{0} -silent".format(unicode(__file__)), None, 1)
+ if silent_flag:
+ windll.shell32.ShellExecuteW(
+ None, u"runas", unicode(sys.executable), u"{0} -silent".format(unicode(__file__)), None, 1)
sys.exit(1)
else:
- windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(__file__), None, 1)
+ windll.shell32.ShellExecuteW(
+ None, u"runas", unicode(sys.executable), unicode(__file__), None, 1)
sys.exit(1)
+
def silent():
setup_logging()
@@ -477,12 +493,13 @@ def silent():
dwt_util.disable_service("DiagTrack")
dwt_util.services(0)
dwt_util.telemetry(0)
- #dwt_util.defender(0)
+ # dwt_util.defender(0)
dwt_util.wifisense(0)
dwt_util.onedrive(0)
logger.info("COMPLETE")
-
+
+
if __name__ == '__main__':
if '-silent' in sys.argv:
silent()
diff --git a/dwt_util.py b/dwt_util.py
index 33f64f8..6836cec 100644
--- a/dwt_util.py
+++ b/dwt_util.py
@@ -66,13 +66,12 @@ class CalledProcessError(Exception):
def is_64bit():
if os.name == 'nt':
- output = subprocess.check_output(['wmic', 'os', 'get', 'OSArchitecture'])
- os_arch = output.split()[1]
- return True if os_arch == '64-bit' else False
+ output = subprocess.check_output(['wmic', 'os', 'get', 'OSArchitecture'])
+ os_arch = output.split()[1]
+ return True if os_arch == '64-bit' else False
else:
- logger.critical("This was only meant to be run on Windows-based system. Specifically, Windows 10.")
- os._exit(0)
- return os_arch
+ logger.critical("This was only meant to be run on Windows-based system. Specifically, Windows 10.")
+ exit(0)
def ip_block(ip_list, undo):
@@ -84,89 +83,98 @@ def ip_block(ip_list, undo):
try:
subprocess_handler(shlex.split(cmd))
- logger.info("IP Blocker: The IP {ip} was successfully {act}.".format(ip=ip, act='unblocked' if undo else 'blocked'))
+ logger.info(
+ "IP Blocker: The IP {ip} was successfully {act}.".format(ip=ip, act='unblocked' if undo else 'blocked'))
except CalledProcessError as e:
logger.exception("IP Blocker: Failed to {act} IP {ip}".format(act='unblock' if undo else 'block', ip=ip))
logger.critical("IP Blocker: Error output:\n" + e.stdout.decode('ascii', 'replace'))
def clear_diagtrack():
- file = os.path.join(os.environ['SYSTEMDRIVE'], ('\\ProgramData\\Microsoft\\Diagnosis\\ETLLogs\\AutoLogger\\AutoLogger-Diagtrack-Listener.etl'))
-
- cmds = ['sc delete DiagTrack',
- 'sc delete dmwappushservice',
- 'echo "" > "{file}"'.format(file=file)]
-
- i = 0
- failed = False
- for cmd in cmds:
- i += 1
- service = split(cmd, 'sc delete ')
-
-
- output = subprocess_handler(cmd)
- if output[0] in [0, 1060, 1072]:
- if output[0] == 0:
- if len(service) > 1:
- logger.info("DiagTrack: Successfully deleted service '{0}'".format(service[1]))
- else:
- logger.info("DiagTrack: Successfully erased tracking log.")
- if output[0] == 1060:
- logger.info("DiagTrack: {0} service doesn't exist. This is OK, you likely removed it already.".format(service[1]))
- if output[0] == 1072:
- logger.info("DiagTrack: {0} service marked for deletion. This is OK, make sure you reboot your machine!".format(service[1]))
-
- logger.info("DiagTrack: Completed Part {0}/{1}".format(i, len(cmds)))
- else:
- logger.info("{0}".format(output[0]))
- failed = True
- logger.exception("DiagTrack: Failed Part {0}/{1}".format(i, len(cmds)))
- logger.critical("DiagTrack: Error code: {0} - {1}".format(output[0],output[1]))
-
- if failed:
- logger.info("DiagTrack: Complete. Errors were recorded.")
- else:
- logger.info("DiagTrack: Completed successfully, without errors.")
-
- '''
- This is an ORDERED dictionary. It will always run in order, not subject to the devastation
- of a standard dictionary, so no worries.
- '''
-
- #temporarily removing this code in favor of something that actually works
- '''
- cmds = OrderedDict()
- cmds["takeown /f {0}".format(file)]="Take Ownership"
- cmds["icacls {0} /grant administrators:F".format(file)]="Grant Admin Privilege"
- cmds["icacls {0} /inheritance:r /deny SYSTEM:F /grant Administrators:F".format(file)]="Deny System Privilege"
-
- i = 0
-
- for x, y in cmds.iteritems():
- i += 1
-
- if i == 3:
- try:
- open(file, 'w').close()
- logger.info("DiagTrack: Cleared AutoLogger-Diagtrack-Listener.etl")
- except:
- logger.exception("DiagTrack: Couldn't open AutoLogger-Diagtrack-Listener.etl for writing")
-
- p = subprocess.Popen(x, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
- output = p.communicate()
- logger.info("DiagTrack: {0} of AutoLogger-Diagtrack-Listener.etl was successful".format(y))
-
- if p.returncode:
- logger.exception(p.returncode.decode())
-
- if i == 3:
- logger.info("DiagTrack: Successfully cleared and locked DiagTrack log.")
- '''
+ file_path = os.path.join(
+ os.environ['SYSTEMDRIVE'],
+ '\\ProgramData\\Microsoft\\Diagnosis\\ETLLogs\\AutoLogger\\AutoLogger-Diagtrack-Listener.etl')
+
+ cmds = [
+ 'sc delete DiagTrack',
+ 'sc delete dmwappushservice',
+ 'echo "" > "{file}"'.format(file=file_path)
+ ]
+
+ i = 0
+ failed = False
+ for cmd in cmds:
+ i += 1
+ service = split(cmd, 'sc delete ')
+
+ output = subprocess_handler(cmd)
+ if output[0] in [0, 1060, 1072]:
+ if output[0] == 0:
+ if len(service) > 1:
+ logger.info("DiagTrack: Successfully deleted service '{0}'".format(service[1]))
+ else:
+ logger.info("DiagTrack: Successfully erased tracking log.")
+ if output[0] == 1060:
+ logger.info(
+ "DiagTrack: {0} service doesn't exist. "
+ "This is OK, you likely removed it already.".format(service[1]))
+ if output[0] == 1072:
+ logger.info(
+ "DiagTrack: {0} service marked for deletion. "
+ "This is OK, make sure you reboot your machine!".format(service[1]))
+
+ logger.info("DiagTrack: Completed Part {0}/{1}".format(i, len(cmds)))
+ else:
+ logger.info("{0}".format(output[0]))
+ failed = True
+ logger.exception("DiagTrack: Failed Part {0}/{1}".format(i, len(cmds)))
+ logger.critical("DiagTrack: Error code: {0} - {1}".format(output[0], output[1]))
+
+ if failed:
+ logger.info("DiagTrack: Complete. Errors were recorded.")
+ else:
+ logger.info("DiagTrack: Completed successfully, without errors.")
+
+ '''
+ This is an ORDERED dictionary. It will always run in order, not subject to the devastation
+ of a standard dictionary, so no worries.
+ '''
+
+ # temporarily removing this code in favor of something that actually works
+ '''
+ cmds = OrderedDict()
+ cmds["takeown /f {0}".format(file)]="Take Ownership"
+ cmds["icacls {0} /grant administrators:F".format(file)]="Grant Admin Privilege"
+ cmds["icacls {0} /inheritance:r /deny SYSTEM:F /grant Administrators:F".format(file)]="Deny System Privilege"
+
+ i = 0
+
+ for x, y in cmds.iteritems():
+ i += 1
+
+ if i == 3:
+ try:
+ open(file, 'w').close()
+ logger.info("DiagTrack: Cleared AutoLogger-Diagtrack-Listener.etl")
+ except:
+ logger.exception("DiagTrack: Couldn't open AutoLogger-Diagtrack-Listener.etl for writing")
+
+ p = subprocess.Popen(x, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
+ output = p.communicate()
+ logger.info("DiagTrack: {0} of AutoLogger-Diagtrack-Listener.etl was successful".format(y))
+
+ if p.returncode:
+ logger.exception(p.returncode.decode())
+
+ if i == 3:
+ logger.info("DiagTrack: Successfully cleared and locked DiagTrack log.")
+ '''
+
def delete_service(service):
try:
win32serviceutil.RemoveService(service)
- logger.info("Services: Succesfully removed service '{service}'".format(service=service))
+ logger.info("Services: Successfully removed service '{service}'".format(service=service))
except pywintypes.error as e:
errors = (winerror.ERROR_SERVICE_DOES_NOT_EXIST, winerror.ERROR_SERVICE_NOT_ACTIVE)
if not any(error == e.winerror for error in errors):
@@ -176,7 +184,7 @@ def delete_service(service):
def disable_service(service):
try:
win32serviceutil.StopService(service)
- logger.info("Services: Succesfully stopped service '{service}'".format(service=service))
+ logger.info("Services: Successfully stopped service '{service}'".format(service=service))
except pywintypes.error as e:
errors = (winerror.ERROR_SERVICE_DOES_NOT_EXIST, winerror.ERROR_SERVICE_NOT_ACTIVE)
if not any(error == e.winerror for error in errors):
@@ -233,42 +241,45 @@ def wifisense(undo):
def onedrive(undo):
- file_sync_value = int(undo)
- list_pin_value = int(not undo)
- action = "install" if undo else "uninstall"
-
- if is_64bit():
- onedrive_keys = {'FileSync': [winreg.HKEY_LOCAL_MACHINE,
- r'SOFTWARE\Policies\Microsoft\Windows\OneDrive',
- 'DisableFileSyncNGSC', winreg.REG_DWORD, file_sync_value],
-
- 'ListPin': [winreg.HKEY_CLASSES_ROOT,
- r'CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}',
- 'System.IsPinnedToNameSpaceTree', winreg.REG_DWORD, list_pin_value],
-
- 'ListPin64Bit': [winreg.HKEY_CLASSES_ROOT,
- r'Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}',
- 'System.IsPinnedToNameSpaceTree', winreg.REG_DWORD, list_pin_value]}
- else:
- onedrive_keys = {'FileSync': [winreg.HKEY_LOCAL_MACHINE,
- r'SOFTWARE\Policies\Microsoft\Windows\OneDrive',
- 'DisableFileSyncNGSC', winreg.REG_DWORD, file_sync_value],
-
- 'ListPin': [winreg.HKEY_CLASSES_ROOT,
- r'CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}',
- 'System.IsPinnedToNameSpaceTree', winreg.REG_DWORD, list_pin_value]}
-
- set_registry(onedrive_keys)
-
- system = "SysWOW64" if is_64bit() else "System32"
- onedrive_setup = os.path.join(os.environ['SYSTEMROOT'], "{system}\\OneDriveSetup.exe".format(system=system))
- cmd = "{bin} /{action}".format(bin=onedrive_setup, action=action)
-
- output = subprocess_handler(cmd)
- if output[0] == -2147219823:
- logger.info("OneDrive: successfully {action}ed".format(action=action))
- else:
- logger.info("OneDrive: unable to {action}. Exited with code: {code} - {message}".format(action=action, code=output[0], message=output[1]))
+ file_sync_value = int(undo)
+ list_pin_value = int(not undo)
+ action = "install" if undo else "uninstall"
+
+ if is_64bit():
+ onedrive_keys = {'FileSync': [winreg.HKEY_LOCAL_MACHINE,
+ r'SOFTWARE\Policies\Microsoft\Windows\OneDrive',
+ 'DisableFileSyncNGSC', winreg.REG_DWORD, file_sync_value],
+
+ 'ListPin': [winreg.HKEY_CLASSES_ROOT,
+ r'CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}',
+ 'System.IsPinnedToNameSpaceTree', winreg.REG_DWORD, list_pin_value],
+
+ 'ListPin64Bit': [
+ winreg.HKEY_CLASSES_ROOT,
+ r'Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}',
+ 'System.IsPinnedToNameSpaceTree', winreg.REG_DWORD, list_pin_value]}
+ else:
+ onedrive_keys = {'FileSync': [winreg.HKEY_LOCAL_MACHINE,
+ r'SOFTWARE\Policies\Microsoft\Windows\OneDrive',
+ 'DisableFileSyncNGSC', winreg.REG_DWORD, file_sync_value],
+
+ 'ListPin': [winreg.HKEY_CLASSES_ROOT,
+ r'CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}',
+ 'System.IsPinnedToNameSpaceTree', winreg.REG_DWORD, list_pin_value]}
+
+ set_registry(onedrive_keys)
+
+ system = "SysWOW64" if is_64bit() else "System32"
+ onedrive_setup = os.path.join(os.environ['SYSTEMROOT'], "{system}\\OneDriveSetup.exe".format(system=system))
+ cmd = "{bin} /{action}".format(bin=onedrive_setup, action=action)
+
+ output = subprocess_handler(cmd)
+ if output[0] == -2147219823:
+ logger.info("OneDrive: successfully {action}ed".format(action=action))
+ else:
+ logger.info(
+ "OneDrive: unable to {action}. "
+ "Exited with code: {code} - {message}".format(action=action, code=output[0], message=output[1]))
def set_registry(keys):
@@ -331,10 +342,10 @@ def app_manager(apps, undo):
def subprocess_handler(cmd):
- p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
- output = p.communicate()
-
- return [p.returncode, output]
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
+ output = p.communicate()
+
+ return [p.returncode, output]
# Old reinstall code, does not work:
# if reinstall: