long blogs

进一步有进一步惊喜


  • Home
  • Archive
  • Tags
  •  

© 2025 long

Theme Typography by Makito

Proudly published with Hexo

右键更换壁纸

Posted at 2020-04-11 windows 注册列表 

python文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import win32api
import win32gui
import win32con
import os
import datetime
import random


day = datetime.datetime.now().strftime('%Y%m%d')
log_filename = day+"_log.txt"
def log(value,print_flag = True):
log_path = os.getcwd() + "\\log"
if not os.path.exists(log_path) :
os.mkdir(log_path)
log_file_path = log_path + "\\" + log_filename
logfile = open(log_file_path, 'a', encoding='utf-8')
if logfile.writable():
now_data = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
log_message = "时间:{} : log : {}\n".format(now_data, value)
if print_flag:
print(log_message)
logfile.write(log_message)
try:
logfile.close()
except IOError:
print("写入日志错误{}".format(IOError))
else:
return


def setWallPaper(wallpaper):
try:
key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,
"Control Panel\\Desktop", 0, win32con.KEY_SET_VALUE)
win32api.RegSetValueEx(key, "WallpaperStyle", 0, win32con.REG_SZ, "2")
win32api.RegSetValueEx(key, "TileWallPaper", 0, win32con.REG_SZ, "0")
win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, wallpaper, 1 + 2)
return True
except EnvironmentError:
log("except:{}错误".format(EnvironmentError))
return False


"""
过滤图片文件
"""
def image_filter(file_list):
image_list = []
# 图片后缀
image_suffix = ["jpg","png","bmp"]
for file in file_list:
if file.split(".")[-1] in image_suffix:
image_list.append(file)
return image_list


if __name__ == '__main__':
image_dir = os.getcwd() + "\images"
if os.path.exists(image_dir):
file_list = os.listdir(image_dir)
print(file_list)
image_list = image_filter(file_list)
print(image_list)
if len(image_list) > 0:
wallpaper_path = image_dir + "\\" + random.choice(image_list)
if os.path.exists(wallpaper_path):
if setWallPaper(wallpaper_path):
log("设置壁纸成功:path = {}".format(wallpaper_path))
else:
log("设置壁纸失败,详情查看日志。path = {}".format(wallpaper_path))
else:
log("无效路径:{}".format(wallpaper_path))
else:
log("文件夹中没有图片文件:path = {}".format(image_dir))
else:
log("不存在路径:{}".format(image_dir))

启动文件

1
2
3
4
5
6
7
8
9
set curdir=%~dp0
cd /d %curdir%

@echo off
if "%1" == "h" goto begin
start mshta vbscript:createobject("wscript.shell").run("%~nx0 h",0)(window.close)&&exit
:begin

python main.py

设置右键项的

Share 

 Previous post: Jenkins相关 Next post: windows右键添加项 

© 2025 long

Theme Typography by Makito

Proudly published with Hexo