THANK YOU amcssit!! Your posts helped me cobble together a script that fully works on Windows 10 Pro. As you said, I had to make a batch file with the REG ADD commands, and that worked perfectly. It seems Windows doesn't like when a 3rd party program modifies those registry keys directly. I combined the portion of the script that the developers created (here) that downloads the image and puts it into a local folder, and the "execute the batch file" script that you posted. Here's what I have, it's probably not 100% code efficient (because it's pretty much copy-pasting parts of 2 different scripts), but it works well in my environment.
And the .bat file simply contains the 4 REG ADD commands from the previous couple posts pointing at the image path that is created by the first half of the script.
Thank you everyone who helped!
Edit: If someone would like to use this for themselves, I believe you will need to:
Code:
#To define a particular parameter, replace the 'parameterName' inside itsm.getParameter('parameterName') with that parameter's name import os import subprocess import urllib import ctypes fromURL=itsm.getParameter('BackgroundImageUrl') ## Here mention the download url in parameters Down_path=os.environ['PROGRAMDATA'] fileName = fromURL.split('/')[-1] DownTo = os.path.join(Down_path, fileName) Folder_name=r"LockScreenBatch" # Give the new folder name Folder_Path=r"C:\Temp" # Provide Path for the New folder URL=r'https://drive.google.com/PUT_YOUR_DIRECT_DOWNLOAD_LINK_HERE' # Provide the direct download link for the BAT file File_name=r"TLS.bat" #Provide the Bat file name with extension directory=Folder_Path+"\\"+Folder_name def ecmd(command): import ctypes from subprocess import PIPE, Popen class disable_file_system_redirection: _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirect ion _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirecti on def __enter__(self): self.old_value = ctypes.c_long() self.success = self._disable(ctypes.byref(self.old_value)) def __exit__(self, type, value, traceback): if self.success: self._revert(self.old_value) with disable_file_system_redirection(): obj = Popen(command, shell = True, stdout = PIPE, stderr = PIPE) out, err = obj.communicate() ret=obj.returncode if ret==0: if out: return out.strip() else: return ret else: if err: return err.strip() else: return ret import ctypes class disable_file_system_redirection: _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirect ion _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirecti on def __enter__(self): self.old_value = ctypes.c_long() self.success = self._disable(ctypes.byref(self.old_value)) def __exit__(self, type, value, traceback): if self.success: self._revert(self.old_value) import subprocess with disable_file_system_redirection(): import urllib def downloadFile(DownTo, fromURL): try: with open(DownTo, 'wb') as f: f.write(urllib.urlopen(fromURL).read()) if os.path.isfile(DownTo): return '{} - {}KB'.format(DownTo, os.path.getsize(DownTo)/1000) except: return 'Please Check URL or Download Path!' print downloadFile(DownTo, fromURL ) if not os.path.exists(directory): os.makedirs(directory) class disable_file_system_redirection: _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirect ion _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirecti on def __enter__(self): self.old_value = ctypes.c_long() self.success = self._disable(ctypes.byref(self.old_value)) def __exit__(self, type, value, traceback): if self.success: self._revert(self.old_value) def Download(src_path, URL,fp): import urllib2 request = urllib2.Request(URL, headers={'User-Agent' : "Magic Browser"}) try: gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1) parsed = urllib2.urlopen(request,context=gcontext) except: parsed = urllib2.urlopen(request) if not os.path.exists(src_path): os.makedirs(src_path) with open(fp, 'wb') as f: while True: chunk=parsed.read(100*1000*1000) if chunk: f.write(chunk) else: break return fp def bat(path): print path with disable_file_system_redirection(): print "Excuting Bat File" process = subprocess.Popen([path],stdout=subprocess.PIPE) stdout = process.communicate()[0] print "---------------------------" print stdout if __name__=='__main__': import time fp = os.path.join(directory, File_name) path=Download(directory, URL,fp) print path time.sleep(10) bat(path)
Thank you everyone who helped!
Edit: If someone would like to use this for themselves, I believe you will need to:
- Change the image URL in the parameters
- Change/create the .bat file to point at the correct image path
- Upload the .bat file to your Google Drive (or other filehost)
- Change the URL for the download in the script
- Change the filename of the .bat file in the script
Comment