Skip to content

Commit

Permalink
fix bug + 32bit
Browse files Browse the repository at this point in the history
  • Loading branch information
lipc_1700 committed Jan 24, 2023
1 parent 5d96821 commit ccceb61
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
__pycache__/
build/
dist/
venv/
venv/
venv32/
30 changes: 19 additions & 11 deletions changeWallpaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import win32api
import os
import shutil
import sys


# 获取当前背景桌面壁纸图片路径
Expand Down Expand Up @@ -78,8 +79,6 @@ def main_wallpaper():
shutil.copyfile("./桌面-py.jpg", os.path.join(absP,"桌面.jpg") )
set_wallpaper(os.path.join(absP,"桌面.jpg"))

# TODO 收集执行信息 发到服务器


def get_screensaver():
reg_key = win32api.RegOpenKeyEx(
Expand All @@ -95,23 +94,22 @@ def get_screensaver():

# 需要管理员权限
def set_screensaver(path):
# 1. 先关掉policy 组策略的设置 删除 \HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\Windows\Control Panel\Desktop 中有关screensaver的项目
""" 1. 先关掉policy 组策略的设置 删除 \HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\Windows\Control Panel\Desktop 中有关screensaver的项目
# 这个path可以带空格 不需要双引号 可能是向系统调用 传递参数的时候 是一个字符串?
#r = os.system("rundll32.exe desk.cpl,InstallScreenSaver " + path) # 异步? 然后杀死弹出窗口?
"""

regkey_policy_desktop = win32api.RegOpenKeyEx( # 这个是管 能不能在ui界面修改
regkey_policy_desktop, flag_policy_desktop = win32api.RegCreateKeyEx( # 这个是管 能不能在ui界面修改, 不存在的话 就创建一个
win32con.HKEY_CURRENT_USER,
"SOFTWARE\\Policies\\Microsoft\\Windows\\Control Panel\\Desktop",
0,
win32con.KEY_ALL_ACCESS | win32con.KEY_WOW64_64KEY
)
regkey_desktop = win32api.RegOpenKeyEx(
regkey_desktop, flag_desktop = win32api.RegCreateKeyEx(
win32con.HKEY_CURRENT_USER,
"Control Panel\\Desktop",
0,
win32con.KEY_ALL_ACCESS | win32con.KEY_WOW64_64KEY
)

# print(flag_policy_desktop, flag_desktop, "REG_CREATED_NEW_KEY", "REG_OPENED_EXISTING_KEY")
for rkey in [regkey_policy_desktop, regkey_desktop]:
win32api.RegSetValueEx(
rkey,
Expand Down Expand Up @@ -143,17 +141,27 @@ def set_screensaver(path):
)
win32api.RegCloseKey(rkey)


def main_screensaver():
# get_screensaver()
absP = "C:\\Windows\\showshow\\screensaver"
shutil.copytree('./dist/screenSaverTest/',absP)
srcPath = "screenSaverTest"
if getattr(sys, 'frozen', False):
# 打包后 可执行文件都放在 dist目录中 两个处于同级
srcPath = os.path.join("./", srcPath)
else: # ide中 可执行文件放在 dist 目录中
srcPath = os.path.join("./dist", srcPath)
shutil.copytree(srcPath, absP)
# 把文件名改成 scr 后缀
if os.path.exists(os.path.join(absP, "screenSaverTest.exe")):
shutil.move(
os.path.join(absP, "screenSaverTest.exe"),
os.path.join(absP, "screenSaverTest.scr")
)
set_screensaver(os.path.join(absP, "screenSaverTest.scr"))

shutil.rmtree("C:\\Windows\\showshow\\",ignore_errors=True)

shutil.rmtree("C:\\Windows\\showshow\\", ignore_errors=True)
main_wallpaper()
main_screensaver()
main_screensaver()
# TODO 收集执行信息 发到服务器
22 changes: 21 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
但是用vb调用user32中的 `SystemParametersInfoW` 就能立即生效。


## option1: 使用VB
从这个回答中抄来的:
https://stackoverflow.com/questions/56522110/how-to-fix-rundll32-exe-user32-dll-updateperusersystemparameters-1-true-not-upd

Expand All @@ -19,6 +20,7 @@ https://stackoverflow.com/questions/56522110/how-to-fix-rundll32-exe-user32-dll-
3. **管理员**运行 ChangeWallpaper.exe 文件
4. 就会把当前目录下的 桌面.jpg 复制到 c:\windows 目录中,然后修改桌面图片

## option2: 使用 Python
### python打包到exe
`pyinstaller -F -w -i x.ico xxx.py`
生成spec后
Expand All @@ -28,4 +30,22 @@ https://stackoverflow.com/questions/56522110/how-to-fix-rundll32-exe-user32-dll-

加上 --onefile 后 启动速度也没变快。

onefile 和 -F 都会输出一个exe,但启动速度都不快
onefile 和 -F 都会输出一个exe,但启动速度都不快, 可能是我的磁盘太慢了

### 开发环境
初始化32位的python虚拟环境: `E:\Python\Python36_32\python.exe -m venv .\venv32`

进入: `.\venv32\Scripts\activate.bat`

安装要用的库: `(venv) pip install -r requirements.txt`

### 调用关系

changeWallpaper:

1.**桌面-py.jpg** 复制到 c:\windows\showshow 文件夹中,然后设置其为桌面

2. 把 当前文件夹下的 **screensaverTest文件夹** 复制到 C:\windows\showshow 文件夹中,然后设置为屏保



14 changes: 14 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
altgraph==0.17.3
future==0.18.2
importlib-metadata==4.8.3
Nuitka==1.3.8
orderedset==2.0.3
pefile==2022.5.30
Pillow==8.4.0
pyinstaller==4.10
pyinstaller-hooks-contrib==2022.0
pywin32==305
pywin32-ctypes==0.2.0
typing-extensions==4.1.1
zipp==3.6.0
zstandard==0.19.0
12 changes: 6 additions & 6 deletions screenSaverTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ def findBoundry(self):
self.y_speed = - self.y_speed


if '/s' in sys.argv:
args = [x.lower() for x in sys.argv]
if '/s' in args:
Screen()
elif "/p" in sys.argv:
elif "/p" in args:
print('preview')
elif "/c" in sys.argv:
elif "/c" in args:
print("config..")
else:
ctypes.windll.user32.MessageBoxW(0, 'other param not impl:' + " ".join(sys.argv[1:]), 'screensaver', win32con.MB_OK)


ctypes.windll.user32.MessageBoxW(0, 'other param not impl:' + " ".join(args[1:]), 'screensaver', win32con.MB_OK)
# TODO 一次性读了所有图片 内存占用太多
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit ccceb61

Please sign in to comment.