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

run.py - github.com/10se1ucgo/DisableWinTracking.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/run.py
blob: 13a5011159df25480c05b174549bf59a4525f3cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
from os import path, environ
from ctypes import windll
from subprocess import Popen
import _winreg
import sys

from win32serviceutil import RemoveService, StopService
from pywintypes import error as win32apierror
import wx
import wx.lib.wordwrap


class RedirectText(object):
    def __init__(self, console):
        self.out = console

    def write(self, string):
        self.out.WriteText(string)


class ConsoleFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent=None, title="Console Output", size=[500, 150],
                          style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX)

        panel = wx.Panel(self)  # Frame panel

        self.Bind(wx.EVT_CLOSE, sys.exit)  # Close application once log output is closed

        # Redirect console output to TextCtrl box
        self.redirect = RedirectText(wx.TextCtrl(panel, wx.ID_ANY, size=(475, 100),
                                                 style=wx.TE_MULTILINE | wx.TE_READONLY, pos=(10, 10)))
        sys.stdout = self.redirect

        self.Center()  # Center window


class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent=None, title='Disable Windows 10 Tracking', size=[375, 150],
                          style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX)

        panel = wx.Panel(self)  # Frame panel

        # Test for elevation
        if windll.shell32.IsUserAnAdmin() != 1:
            warn = wx.MessageDialog(parent=None,
                                    message="Program requires elevation, please run it as an administrator",
                                    caption="ERROR", style=wx.OK | wx.ICON_WARNING)
            warn.ShowModal()
            sys.exit()

        # Get icon
        shell32file = path.join(environ['SYSTEMROOT'], 'System32\\shell32.dll')
        self.SetIcon(wx.Icon(shell32file + ";315", wx.BITMAP_TYPE_ICO))

        # Info bar w/ about menu
        infomenu = wx.Menu()
        aboutitem = infomenu.Append(wx.ID_ABOUT, "About", "About the application")

        menubar = wx.MenuBar()
        menubar.Append(infomenu, "&Info")

        self.SetMenuBar(menubar)
        self.Bind(wx.EVT_MENU, self.about, aboutitem)

        self.Bind(wx.EVT_CLOSE, sys.exit)  # Close application once log output is closed

        # Service checkbox
        self.servicebox = wx.CheckBox(panel, label="Services", pos=(10, 15))
        self.servicebox.SetToolTip(wx.ToolTip("Disables or Deletes tracking services. Choose option in Service Method"))
        self.Bind(wx.EVT_CHECKBOX, self.serviceradioboxcheck, self.servicebox)

        # DiagTrack checkbox
        self.diagtrackbox = wx.CheckBox(panel, label="Clear DiagTrack log", pos=(10, 30))
        self.diagtrackbox.SetToolTip(wx.ToolTip("Clears Diagnostic Tracking log and prevents modification to it."))

        # Telemetry checkbox
        self.telemetrybox = wx.CheckBox(panel, label="Telemetry", pos=(10, 45))
        self.telemetrybox.SetToolTip(
            wx.ToolTip("Sets \'AllowTelemetry\' to 0. On non-Enterprise OS editions, requires HOSTS file modification"))
        self.Bind(wx.EVT_CHECKBOX, self.telemetryhostcheck, self.telemetrybox)

        # HOSTS file checkbox
        self.hostbox = wx.CheckBox(panel, label="Block tracking servers with HOSTS file", pos=(10, 60))
        self.hostbox.SetToolTip(wx.ToolTip("Add known tracking domains to HOSTS file. Required to disable Telemetry"))

        self.extrahostbox = wx.CheckBox(panel, label="Block even more tracking servers", pos=(10, 75))
        self.extrahostbox.SetToolTip(wx.ToolTip("For the paranoid. Adds extra domains to the HOSTS file. WARNING: Some "
                                                "things like Dr. Watson and Error Reporting may be disabled by this"))

        # Service radio box
        self.serviceradbox = wx.RadioBox(panel, label="Service Method", pos=(135, 10), choices=["Disable", "Delete"])
        self.serviceradbox.Disable()

        # OK button
        self.okbutton = wx.Button(panel, wx.ID_OK, "Go Private!", (275, 25))
        self.Bind(wx.EVT_BUTTON, self.goprivate, self.okbutton)

        # Center and show the window
        self.Centre()
        self.Show()

    def serviceradioboxcheck(self, event):
        self.serviceradbox.Enable(self.servicebox.IsChecked())

    def telemetryhostcheck(self, event):
        self.hostbox.SetValue(self.telemetrybox.IsChecked())

    def about(self, event):
        licensetext = "Copyright 2015 10se1ucgo\r\n\r\nLicensed under the Apache License, Version 2.0" \
                      " (the \"License\");\r\nyou may not use this file except in compliance with the License" \
                      ".\r\nYou may obtain a copy of the License at\r\n\r\n" \
                      "    http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nUnless required by applicable law or" \
                      " agreed to in writing, software\r\ndistributed under the License is distributed on an" \
                      " \"AS IS\" BASIS,\r\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." \
                      "\r\nSee the License for the specific language governing permissions and\r\nlimitations under" \
                      " the License."

        aboutpg = wx.AboutDialogInfo()
        aboutpg.Name = "Windows 10 Tracking Disable Tool"
        aboutpg.Version = "v2.0"
        aboutpg.Copyright = "(c) 2015 10se1ucgo"
        aboutpg.Description = "A tool to disable nasty tracking in Windows 10"
        aboutpg.WebSite = ("https://github.com/10se1ucgo/DisableWinTracking", "GitHub Project Page")
        aboutpg.License = wx.lib.wordwrap.wordwrap(licensetext, 500, wx.ClientDC(self))
        wx.AboutBox(aboutpg)

    def goprivate(self, event):
        console = ConsoleFrame()  # Call ConsoleFrame to start redirecting stdout to the TextCtrl in the frame.
        try:
            if self.servicebox.IsChecked():
                if self.serviceradbox.Selection == 0:
                    disableservice('dmwappushsvc')
                    disableservice('Diagnostics Tracking Service')
                    modifyserviceregs()
                elif self.serviceradbox.Selection == 1:
                    deleteservice('dmwappushsvc')
                    deleteservice('Diagnostics Tracking Service')
                    modifyserviceregs()
            if self.diagtrackbox.IsChecked():
                cleardiagtracklog()
            if self.telemetrybox.IsChecked():
                modifytelemetryregs()
            if self.hostbox.IsChecked():
                modifyhosts(extra=False)
            if self.extrahostbox.IsChecked():
                modifyhosts(extra=True)
        finally:
            console.Show()  # Show console output window after the code is run


def modifyhosts(extra):
    nullip = "0.0.0.0 "  # IP to route domains to

    # List of tracking domains
    normallist = ['a-0001.a-msedge.net', 'a-0001.a-msedge.net', 'a-0002.a-msedge.net', 'a-0003.a-msedge.net',
                  'a-0004.a-msedge.net', 'a-0005.a-msedge.net', 'a-0006.a-msedge.net', 'a-0007.a-msedge.net',
                  'a-0008.a-msedge.net', 'a-0009.a-msedge.net', 'a-msedge.net', 'a.ads1.msn.com', 'a.ads2.msads.net',
                  'a.ads2.msn.com', 'a.rad.msn.com', 'ac3.msn.com', 'ad.doubleclick.net', 'adnexus.net', 'adnxs.com',
                  'ads.msn.com', 'ads1.msads.net', 'ads1.msn.com', 'aidps.atdmt.com', 'aka-cdn-ns.adtech.de',
                  'apps.skype.com', 'az361816.vo.msecnd.net', 'az512334.vo.msecnd.net', 'b.ads1.msn.com',
                  'b.ads2.msads.net', 'b.rad.msn.com', 'bs.serving-sys.com', 'c.atdmt.com', 'c.msn.com',
                  'cdn.atdmt.com', 'cds26.ams9.msecn.net', 'choice.microsoft.com', 'choice.microsoft.com.nsatc.net',
                  'compatexchange.cloudapp.net', 'corp.sts.microsoft.com', 'corpext.msitadfs.glbdns2.microsoft.com',
                  'cs1.wpc.v0cdn.net', 'db3aqu.atdmt.com', 'df.telemetry.microsoft.com',
                  'diagnostics.support.microsoft.com', 'ec.atdmt.com', 'feedback.microsoft-hohm.com',
                  'feedback.search.microsoft.com', 'feedback.windows.com', 'flex.msn.com', 'g.msn.com', 'h1.msn.com',
                  'i1.services.social.microsoft.com', 'i1.services.social.microsoft.com.nsatc.net',
                  'lb1.www.ms.akadns.net', 'live.rads.msn.com', 'm.adnxs.com', 'm.hotmail.com', 'msedge.net',
                  'msftncsi.com', 'msnbot-65-55-108-23.search.msn.com', 'msntest.serving-sys.com',
                  'oca.telemetry.microsoft.com', 'oca.telemetry.microsoft.com.nsatc.net', 'pre.footprintpredict.com',
                  'pre.footprintpredict.com', 'preview.msn.com', 'pricelist.skype.com', 'rad.live.com', 'rad.msn.com',
                  'redir.metaservices.microsoft.com', 's.gateway.messenger.live.com', 'schemas.microsoft.akadns.net ',
                  'secure.adnxs.com', 'secure.flashtalking.com', 'settings-sandbox.data.microsoft.com',
                  'settings-win.data.microsoft.com', 'sls.update.microsoft.com.akadns.net',
                  'sqm.df.telemetry.microsoft.com', 'sqm.telemetry.microsoft.com',
                  'sqm.telemetry.microsoft.com.nsatc.net', 'static.2mdn.net', 'statsfe1.ws.microsoft.com',
                  'statsfe2.ws.microsoft.com', 'telecommand.telemetry.microsoft.com',
                  'telecommand.telemetry.microsoft.com.nsatc.net', 'telemetry.appex.bing.net',
                  'telemetry.microsoft.com', 'telemetry.urs.microsoft.com', 'ui.skype.com',
                  'vortex-bn2.metron.live.com.nsatc.net', 'vortex-cy2.metron.live.com.nsatc.net',
                  'vortex-sandbox.data.microsoft.com', 'vortex-win.data.microsoft.com', 'vortex.data.microsoft.com',
                  'watson.live.com', 'www.msftncsi.com']

    extralist = ['fe2.update.microsoft.com.akadns.net', 'reports.wes.df.telemetry.microsoft.com', 's0.2mdn.net',
                 'schemas.microsoft.akadns.net', 'services.wes.df.telemetry.microsoft.com',
                 'statsfe2.update.microsoft.com.akadns.net', 'survey.watson.microsoft.com', 'view.atdmt.com',
                 'watson.microsoft.com', 'watson.ppe.telemetry.microsoft.com', 'watson.telemetry.microsoft.com',
                 'watson.telemetry.microsoft.com.nsatc.net', 'wes.df.telemetry.microsoft.com']

    # Domains with 0.0.0.0 added to the beginning of each.
    normallistip = [nullip + x for x in normallist]
    extralistip = [nullip + x for x in extralist]

    hostspath = path.join(environ['SYSTEMROOT'], 'System32\\drivers\\etc\\hosts')

    try:
        with open(hostspath, 'ab') as f:
            f.write('\r\n' + '\r\n'.join(normallistip))
            if extra:
                f.write('\r\n' + '\r\n'.join(extralistip))
        print "Domains successfully appended to HOSTS file."
    except WindowsError:
        print "Could not access HOSTS file. Is the program not elevated?"


def cleardiagtracklog():
    logfile = path.join(environ['SYSTEMDRIVE'],
                        '\\ProgramData\\Microsoft\\Diagnosis\\ETLLogs\\AutoLogger\\AutoLogger-Diagtrack-Listener.etl')

    disableservice('Diagnostics Tracking Service')

    try:
        open(logfile, 'w').close()  # Clear the AutoLogger file
        Popen(["echo", "y|cacls", logfile, "/d", "SYSTEM"], shell=True)  # Prevent modification to file
        print "DiagTrack log succesfully cleared and locked."
    except IOError:
        print "Unable to clear DiagTrack log. Deleted, or is the program not elevated?"


def deleteservice(service):
    try:
        RemoveService(service)  # Delete service
        print "%s successfully deleted." % service
    except win32apierror:
        print "%s unable to be deleted. Deleted already, or is the program not elevated?" % service


def disableservice(service):
    try:
        StopService(service)  # Delete service
        print "%s successfully stopped." % service
    except win32apierror:
        print "%s unable to be stopped. Deleted, or is the program not elevated?" % service


def modifytelemetryregs():
    telemetrypath = r'SOFTWARE\Policies\Microsoft\Windows\DataCollection'  # Path to Telemetry key
    telemetrypath2 = r'SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\DataCollection'  # 2nd path

    try:
        telemetrykey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, telemetrypath, 0, _winreg.KEY_ALL_ACCESS)
        _winreg.SetValueEx(telemetrykey, "AllowTelemetry", 0, _winreg.REG_SZ, "0")  # Disable Telemetry
        _winreg.CloseKey(telemetrykey)
        print "Telemetry key succesfully modified."
    except WindowsError:
        print "Unable to modify Telemetry key. Deleted, or is the program not elevated? Trying another method"

    try:
        telemetrykey2 = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, telemetrypath2, 0, _winreg.KEY_ALL_ACCESS)
        _winreg.SetValueEx(telemetrykey2, "AllowTelemetry", 0, _winreg.REG_SZ, "0")  # Disable Telemetry
        _winreg.CloseKey(telemetrykey2)
        print "2nd Telemetry key succesfully modified."
    except WindowsError:
        print "Unable to modify 2nd Telemetry key. Deleted, or is the program not elevated?"


def modifyserviceregs():
    diagtrackpath = r'SYSTEM\CurrentControlSet\Services\DiagTrack'
    dmwapushhpath = r'SYSTEM\CurrentControlSet\Services\dmwappushsvc'

    try:
        diagtrackkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, diagtrackpath, 0, _winreg.KEY_ALL_ACCESS)
        _winreg.SetValueEx(diagtrackkey, "Start", 0, _winreg.REG_DWORD, 0x0000004)
        _winreg.CloseKey(diagtrackkey)
        print "DiagTrack key successfully modified"
    except WindowsError:
        print "Unable to modify DiagTrack key. Deleted, or is the program not elevated?"

    try:
        dmwapushkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, dmwapushhpath, 0, _winreg.KEY_ALL_ACCESS)
        _winreg.SetValueEx(dmwapushkey, "Start", 0, _winreg.REG_DWORD, 0x0000004)
        _winreg.CloseKey(dmwapushkey)
        print "dmwappushsvc key successfully modified"
    except WindowsError:
        print "Unable to modify dmwappushsvc key. Deleted, or is the program not elevated?"


if __name__ == '__main__':
    wxwindow = wx.App(False)
    frame = MainFrame()  # Create Window
    wxwindow.MainLoop()