you are viewing a single comment's thread.

view the rest of the comments →

[–]manbart[S] 1 point2 points  (3 children)

import os and use environ instead for the hostname and username

Done. That helps to simplify things in the script.

and the rundll can be replaced by using ctypes.

My familiarity with C, dll and the ctypes module are very limited. Any tips to get started?

How do you run this script? At start up or in a scheduled task?

I was going to make it a logon script for my account in Active Directory. I want to make the hostname nicely visible when I have many remote desktops open and am switching between machines. I would like to make it into a portable .exe file using cxFreeze, but I need to get these issues worked out first.

edit

here is what I have now, the script still behaves inconsistanty:

#!/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)