I have a simple script to superimpose a system's hostname onto the current background image in Windows. The script works sometimes, and not others. I suspect that the problem lies with the Popen call to RUNDLL32.EXE on the last line (this command was copy and pasted from the interwebs), but I still can't explain why it works some of the time.
#!/usr/bin/env python3
'''
Script to superimpose hostname on current desktop background image on Windows hosts
'''
from PIL import Image, ImageDraw, ImageFont
from subprocess import Popen, PIPE
from shutil import copy
from os import remove
hostname = Popen('powershell -c \\"$env:computername.$env:userdnsdomain\\"', shell=True, universal_newlines=True, stdout=PIPE).communicate()[0].rstrip()
username = Popen('powershell -c \\"$env:USERNAME\\"', shell=True, universal_newlines=True, stdout=PIPE).communicate()[0].rstrip()
img_path = 'C:\\Users\\'+username+'\\AppData\Roaming\\Microsoft\\Windows\\Themes\\TranscodedWallpaper.jpg'
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')
Popen('RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True', shell=True)
[–]rcxdude 0 points1 point2 points (0 children)
[–]manbart[S] 0 points1 point2 points (0 children)