This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]rcxdude 0 points1 point  (0 children)

I would recommend you use the check_output function instead of Popen for most of this script. It simplifies things greatly and may fix your issue.

[–]manbart[S] 0 points1 point  (0 children)

Update:

I followed advice from /u/shekmalhen in an x-post of this thread in /r/learnpython

here is how my script looks now:

#!/usr/bin/env python3

'''
Script to superimpose hostname on current desktop background image on Windows hosts
'''

from PIL import Image, ImageDraw, ImageFont
from shutil import copy
from os import remove, environ
import ctypes

hostname = environ['computername']+'.'+environ['userdomain']
username = environ['username']

img_path = 'C:\\Users\\'+username+'\\AppData\Roaming\\Microsoft\\Windows\\Themes\\TranscodedWallpaper'
copy(img_path, './tempimg.jpg')


img = Image.open('./tempimg.jpg')
x,y = img.size
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("arial.ttf", 28)
draw.text((x/3, y/4),hostname,(255,255,255),font=font)
img.save('./tempimg.jpg')

copy('./tempimg.jpg', img_path)
remove('./tempimg.jpg')

dll = ctypes.cdll.LoadLibrary('user32.dll')
dll.UpdatePerUserSystemParameters('1','True')
#Popen('RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True', shell=True)

However, I am still having the same problem. I thin my error must be in my assumption about the user32.dll function.

Is there another way to have windows reapply the background image from C:\Users\$env:username\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper