Skip to content

Commit 4209daa

Browse files
committed
Fix autorun
260 char limit...
1 parent b91da2e commit 4209daa

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

RemoveWindowsLockScreenAds/RemoveWindowsLockScreenAds.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import functools
66
import subprocess
77
import shutil
8+
import time
89

910
import win32api
1011
import win32file
@@ -57,7 +58,7 @@ def GetAdSettingsDirectory(user=None):
5758
return os.path.join(base, EXT)
5859

5960
class AdRemover():
60-
INSTALL_LOCATION = os.path.join(os.path.expandvars(r"%LOCALAPPDATA%\RemoveWindowsLockScreenAds"), os.path.basename(__file__))
61+
INSTALL_LOCATION = os.path.expandvars(r"%LOCALAPPDATA%\RemoveWindowsLockScreenAds")
6162

6263
def __init__(self, dry_run=False, remove_credits=False):
6364
self.dry_run = dry_run
@@ -171,14 +172,18 @@ def __autorun_key(self, do_add, path=None):
171172
0, winreg.KEY_SET_VALUE
172173
) as hKey:
173174
if do_add:
174-
cmdline = [sys.executable, self.INSTALL_LOCATION, '--watch']
175+
# Run key has maximum length of 260 chars, so make a .bat file
176+
bat_path = os.path.join(self.INSTALL_LOCATION, 'RemoveWindowsLockScreenAds.bat')
177+
cmdline = ['start', sys.executable, os.path.join(self.INSTALL_LOCATION, os.path.basename(__file__)), '--watch']
175178
if self.remove_credits:
176179
cmdline.append('--remove-credits')
177180
if path is not None:
178181
cmdline.append(path)
179182
cmdline = ' '.join(cmdline)
180183
logger.info("On startup will run:\n\t{}".format(cmdline))
181-
winreg.SetValueEx(hKey, key, 0, winreg.REG_SZ, cmdline)
184+
with open(bat_path, 'w') as f:
185+
f.write(cmdline)
186+
winreg.SetValueEx(hKey, key, 0, winreg.REG_SZ, bat_path)
182187
else:
183188
try:
184189
winreg.DeleteValue(hKey, key)
@@ -192,8 +197,8 @@ def install(self, path):
192197

193198
try:
194199
# Copy self (script) to install location
195-
os.makedirs(os.path.dirname(self.INSTALL_LOCATION), exist_ok=True)
196-
shutil.copyfile(__file__, self.INSTALL_LOCATION)
200+
os.makedirs(self.INSTALL_LOCATION, exist_ok=True)
201+
shutil.copyfile(__file__, os.path.join(self.INSTALL_LOCATION, os.path.basename(__file__)))
197202

198203
# Create startup key
199204
self.__autorun_key(True, path=path)
@@ -217,13 +222,13 @@ def uninstall(self):
217222

218223
# Remove files
219224
try:
220-
path = os.path.dirname(self.INSTALL_LOCATION)
225+
path = self.INSTALL_LOCATION
221226
if os.path.exists(path):
222227
shutil.rmtree(path)
223228
except Exception as e:
224229
logger.error("Failed to remove installed files: {}".format(e))
225230
else:
226-
logger.info("Uninstalled from {}".format(self.INSTALL_LOCATION))
231+
logger.info("Uninstalled from {}".format(path))
227232

228233
def main(argv):
229234
parser = argparse.ArgumentParser()

0 commit comments

Comments
 (0)