From ccceb61fd15f50eb05407dd139a1abf08829e05a Mon Sep 17 00:00:00 2001 From: lipc_1700 <3236568459@somechatapp.com> Date: Tue, 24 Jan 2023 21:45:28 +0800 Subject: [PATCH] fix bug + 32bit --- .gitignore | 3 +- changeWallpaper.py | 30 +++++++++++------- readme.md | 22 ++++++++++++- requirements.txt | 14 ++++++++ screenSaverTest.py | 12 +++---- ChangeWallpaper.exe => vb/ChangeWallpaper.exe | Bin .../VB_compiles_changewallpaper_vb_exe.bat | 0 changeWallpaper.vb => vb/changeWallpaper.vb | 0 8 files changed, 62 insertions(+), 19 deletions(-) create mode 100644 requirements.txt rename ChangeWallpaper.exe => vb/ChangeWallpaper.exe (100%) rename VB_compiles_changewallpaper_vb_exe.bat => vb/VB_compiles_changewallpaper_vb_exe.bat (100%) rename changeWallpaper.vb => vb/changeWallpaper.vb (100%) diff --git a/.gitignore b/.gitignore index 00661a0..3791f3c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ __pycache__/ build/ dist/ -venv/ \ No newline at end of file +venv/ +venv32/ \ No newline at end of file diff --git a/changeWallpaper.py b/changeWallpaper.py index 9d48dac..ac386cd 100644 --- a/changeWallpaper.py +++ b/changeWallpaper.py @@ -4,6 +4,7 @@ import win32api import os import shutil +import sys # 获取当前背景桌面壁纸图片路径 @@ -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( @@ -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, @@ -143,10 +141,18 @@ 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"), @@ -154,6 +160,8 @@ def main_screensaver(): ) 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() \ No newline at end of file +main_screensaver() +# TODO 收集执行信息 发到服务器 diff --git a/readme.md b/readme.md index e4a104c..378b01b 100644 --- a/readme.md +++ b/readme.md @@ -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 @@ -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后 @@ -28,4 +30,22 @@ https://stackoverflow.com/questions/56522110/how-to-fix-rundll32-exe-user32-dll- 加上 --onefile 后 启动速度也没变快。 -onefile 和 -F 都会输出一个exe,但启动速度都不快 \ No newline at end of file +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 文件夹中,然后设置为屏保 + + + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..30ed409 --- /dev/null +++ b/requirements.txt @@ -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 diff --git a/screenSaverTest.py b/screenSaverTest.py index f221d3d..093a621 100644 --- a/screenSaverTest.py +++ b/screenSaverTest.py @@ -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 一次性读了所有图片 内存占用太多 diff --git a/ChangeWallpaper.exe b/vb/ChangeWallpaper.exe similarity index 100% rename from ChangeWallpaper.exe rename to vb/ChangeWallpaper.exe diff --git a/VB_compiles_changewallpaper_vb_exe.bat b/vb/VB_compiles_changewallpaper_vb_exe.bat similarity index 100% rename from VB_compiles_changewallpaper_vb_exe.bat rename to vb/VB_compiles_changewallpaper_vb_exe.bat diff --git a/changeWallpaper.vb b/vb/changeWallpaper.vb similarity index 100% rename from changeWallpaper.vb rename to vb/changeWallpaper.vb