├── LICENSE ├── README.md ├── files.py └── main.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Xizo-114514 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Xizo硬盘图标修改器 DiskIconChangerByXizo 2 | 这是一个可以修改硬盘图标的软件哦~。 A software that can change the disk icon. 3 | 4 | bilibili视频:https://www.bilibili.com/video/BV1nK411C7j1/ 5 | ## 软件截图 Screenshot 6 | ![1](https://user-images.githubusercontent.com/120782087/211531071-8f1f8d51-b58f-4ee5-a8d1-c3bd76d64dbe.png) 7 | 8 | ![2](https://user-images.githubusercontent.com/120782087/211531333-8801f664-f9ea-4bd4-be28-a7244a28b95f.png) 9 | ## 使用方法 How to use 10 | 11 | ### 如何修改图标: 12 | 1.选择磁盘;2.选择图片;3.点击绿色按钮“安装图标”;4.刷新即可生效。 13 | 14 | 图片格式支持 ico、png、jpg、bmp、tif 等常用格式,建议图片比例为1:1,分辨率大于48x48。 15 | 16 | inf安装:如果是U盘或者移动硬盘,改注册表方法不可用,请使用inf安装。该功能更新于V1.1。 17 | 18 | ### 如何重置图标: 19 | 1.选中要重置的磁盘;2.点击红色按钮“重置图标”;3.刷新即可生效。 20 | 21 | ### 其他功能说明: 22 | #### 1.重启资源管理器: 23 | 重启资源管理器,可刷新图标显示。 24 | #### 2.修复网络驱动器: 25 | 在“磁盘选择”列表中,如果找不到映射的网络驱动器,请点此按钮修复。 26 | 这是Windows权限引起的问题,解决方法是新建注册表值。 27 | #### 3.彻底还原清缓存: 28 | 如果你想重置所有的硬盘图标,并清除缓存,请点此按钮。 29 | 程序会在C:\Windows下创建_XizoDiskIconChanger文件夹, 30 | 其中保存着程序配置和所有的图标文件,防止Windows图标缓存丢失。 31 | 正常情况这些缓存文件会在重置时移除,不需要清理。此功能用于特殊情况或彻底卸载。 32 | 按下按钮后会将您的注册表还原,并删除创建的缓存目录及其内的文件。 33 | 34 | ### 欢迎使用本软件,感谢你看完这段说明,谢谢。 35 | DiskIconChanger By Xizo V1.1-2023.01.13 36 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import string 2 | import os 3 | import webbrowser 4 | import winreg 5 | import ctypes 6 | from tkinter import * 7 | import tkinter as tk 8 | from tkinter import ttk 9 | from tkinter import messagebox as msg 10 | from tkinter import filedialog as filemsg 11 | import base64 12 | import datetime 13 | import win32api 14 | import win32con 15 | from PIL import ImageTk, Image 16 | from shutil import rmtree 17 | from files import regfix, imgicon, imgbg, usehelptext 18 | 19 | #使用方法 20 | def usehelp(): 21 | msgbox = Tk() 22 | helpwidth = 840 23 | helpheight = 880 24 | helpx = int((screenwidth - helpwidth) / 2) 25 | helpy = int((screenheight - helpheight) / 2) 26 | msgbox.geometry("%dx%d+%d+%d" % (helpwidth, helpheight, helpx, helpy)) 27 | msgbox.resizable(0, 0) 28 | 29 | icontmp = open("icontmp.ico", "wb+") 30 | icontmp.write(base64.b64decode(imgicon)) 31 | icontmp.close() 32 | msgbox.iconbitmap('icontmp.ico') 33 | os.remove('icontmp.ico') 34 | 35 | msgbox.title('使用方法') 36 | Label(msgbox, text=usehelptext, justify=tk.LEFT, font=("微软雅黑", 15)).pack(fill=X) 37 | msgbox.mainloop() 38 | 39 | #关于作者 40 | def about(): 41 | if msg.askokcancel('关于作者', '这个程序是Xizo编写的。\n版本 V1.1-2023.01.13\n作者QQ群:912164832\n点击确定跳转至我的bilibili主页。'): 42 | webbrowser.open('https://space.bilibili.com/407420026', new=0, autoraise=True) 43 | 44 | #选择图标 45 | def choose_img(): 46 | global imgpath 47 | imgpath = filemsg.askopenfile(filetypes=[("图片文件", (".ico", ".png", ".jpg", ".bmp", ".tif", ".tiff", ".jpeg", ".jpe"))]) 48 | imgpath = imgpath.name 49 | choose_img_bar.configure(state='normal') 50 | choose_img_bar.delete("1.0","end") 51 | choose_img_bar.insert("insert", imgpath) 52 | choose_img_bar.configure(state='disabled') 53 | #预览小图标更新图片 54 | showimg_open = Image.open(imgpath) 55 | showimg = ImageTk.PhotoImage(showimg_open.resize((48,48))) 56 | ShowImage.config(image=showimg) 57 | ShowImage.image = showimg 58 | 59 | #重置图标 60 | def rest(): 61 | errreg = 0 62 | errinf1 = 0 63 | errinf2 = 0 64 | errinf = 1 65 | try: 66 | queryimgpath = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE, 67 | 'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\\' + choose_disk_combobox.get()[0] + '\DefaultIcon') 68 | os.remove(queryimgpath) 69 | winreg.DeleteKey(winreg.HKEY_LOCAL_MACHINE, 70 | 'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\\' + choose_disk_combobox.get()[0] + '\DefaultIcon') 71 | winreg.DeleteKey(winreg.HKEY_LOCAL_MACHINE, 72 | 'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\\' + choose_disk_combobox.get()[0]) 73 | except: 74 | print() 75 | errreg = 1 76 | try: 77 | os.remove(choose_disk_combobox.get()[0] + r":\icon.ico") 78 | except: 79 | errinf1 = 1 80 | try: 81 | os.remove(choose_disk_combobox.get()[0] + r":\autorun.inf") 82 | except: 83 | errinf2 = 1 84 | if errinf1 == 0 or errinf2 == 0: 85 | errinf = 0 86 | if errreg == 1 and errinf == 1: 87 | msg.showerror('重置图标', '错误:没有选择磁盘\n或图标已经重置了') 88 | if errreg == 1 and errinf == 0: 89 | msg.showinfo('重置图标', '图标重置成功(autorun.inf)') 90 | if errreg == 0 and errinf == 1: 91 | msg.showinfo('重置图标', '图标重置成功(注册表)') 92 | if errreg == 0 and errinf == 0: 93 | msg.showinfo('重置图标', '图标重置成功(autorun.inf + 注册表)') 94 | 95 | #安装图标 96 | def install(): 97 | errimg = 0 98 | errdisk = 0 99 | if os.path.exists(r'C:\Windows\_XizoDiskIconChanger\icon') == False: 100 | os.makedirs(r'C:\Windows\_XizoDiskIconChanger\icon') 101 | try: 102 | originimgpath = str(choose_img_bar.get(1.0, END).replace('/','\\'))[:-1] 103 | imgname = originimgpath[originimgpath.rindex('\\')+1:][:-4] 104 | xizopath = r'C:\Windows\_XizoDiskIconChanger\icon\%s_%s.ico' % \ 105 | (imgname[:-4], datetime.datetime.now().strftime('[%Y-%m-%d](%H.%M.%S)')) 106 | except: 107 | errimg = 1 108 | try: 109 | inputimg = Image.open(originimgpath) 110 | imgh, imgw = inputimg.size 111 | if imgh >= 48 and imgw >= 48: 112 | inputimg.save(xizopath, sizes=[(48, 48)]) 113 | else: 114 | inputimg.save(xizopath, sizes=[(imgh, imgw)]) 115 | except: 116 | print() 117 | try: 118 | winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, 119 | 'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\\' + choose_disk_combobox.get()[0] + '\DefaultIcon') 120 | except: 121 | errdisk = 1 122 | try: 123 | winreg.SetValue(winreg.HKEY_LOCAL_MACHINE, 124 | 'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\\' + choose_disk_combobox.get()[0] + '\DefaultIcon', 125 | winreg.REG_SZ, xizopath) 126 | msg.showinfo('安装图标', '通过修改注册表安装图标成功') 127 | except: 128 | if errimg == 1 and errdisk == 1: 129 | msg.showerror('安装图标', '错误:你既没有选择磁盘也没有选择图片') 130 | if errimg == 1 and errdisk == 0: 131 | msg.showerror('安装图标', '错误:你没有选择图片') 132 | if errimg == 0 and errdisk == 1: 133 | msg.showerror('安装图标', '错误:你没有选择磁盘') 134 | 135 | #autorun.inf方式安装图标 136 | def infinstall(): 137 | errimg = 0 138 | errdisk = 0 139 | try: 140 | os.remove(choose_disk_combobox.get()[0] + r":\autorun.inf") 141 | except: 142 | print() 143 | try: 144 | originimgpath = str(choose_img_bar.get(1.0, END).replace('/','\\'))[:-1] 145 | inputimg = Image.open(originimgpath) 146 | except: 147 | errimg = 1 148 | try: 149 | imgh, imgw = inputimg.size 150 | if imgh >= 48 and imgw >= 48: 151 | inputimg.save(choose_disk_combobox.get()[0]+r":\icon.ico", sizes=[(48, 48)]) 152 | else: 153 | inputimg.save(choose_disk_combobox.get()[0]+r":\icon.ico", sizes=[(imgh, imgw)]) 154 | except: 155 | print() 156 | try: 157 | inf = open(choose_disk_combobox.get()[0]+r":\autorun.inf", "w+") 158 | except: 159 | errdisk = 1 160 | try: 161 | inf.write("[autorun]\nicon=icon.ico") 162 | inf.close() 163 | except: 164 | print() 165 | try: 166 | win32api.SetFileAttributes(choose_disk_combobox.get()[0] + r":\icon.ico", win32con.FILE_ATTRIBUTE_HIDDEN) 167 | except: 168 | print() 169 | try: 170 | win32api.SetFileAttributes(choose_disk_combobox.get()[0] + r":\autorun.inf", win32con.FILE_ATTRIBUTE_HIDDEN) 171 | except: 172 | print() 173 | if errimg == 1 and errdisk == 1: 174 | msg.showerror('inf安装', '错误:你既没有选择磁盘也没有选择图片') 175 | if errimg == 1 and errdisk == 0: 176 | msg.showerror('inf安装', '错误:你没有选择图片') 177 | if errimg == 0 and errdisk == 1: 178 | msg.showerror('inf安装', '错误:你没有选择磁盘') 179 | if errimg == 0 and errdisk == 0: 180 | msg.showinfo('inf安装', '通过添加autorun.inf安装图标成功\n重启电脑或重新连接移动驱动器生效') 181 | 182 | #恢复所有硬盘图标并清除缓存 183 | def delete(): 184 | for diski in disk_list: 185 | try: 186 | winreg.DeleteKey(winreg.HKEY_LOCAL_MACHINE, 187 | 'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\\' + diski[0] + '\DefaultIcon') 188 | winreg.DeleteKey(winreg.HKEY_LOCAL_MACHINE, 189 | 'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\\' + diski[0]) 190 | except: 191 | print() 192 | try: 193 | os.remove(diski[0] + r":\icon.ico") 194 | except: 195 | print() 196 | try: 197 | os.remove(diski[0] + r":\autorun.inf") 198 | except: 199 | print() 200 | try: 201 | rmtree(r'C:\Windows\_XizoDiskIconChanger\icon') 202 | except: 203 | print() 204 | msg.showinfo('彻底还原清缓存', '已恢复所有硬盘图标并清除缓存') 205 | 206 | #重启资源管理器 207 | def restartexp(): 208 | os.system("taskkill /f /im explorer.exe & start explorer.exe") 209 | 210 | #修复网络驱动器 211 | def fix(): 212 | if os.path.exists(r'C:\Windows\_XizoDiskIconChanger\NetDeskFixed') == False: 213 | if msg.askyesno('修复网络驱动器','稍后会弹出一个“注册表编辑器”窗口,\n请确认安装注册表\n点击“是”开始'): 214 | regtmp = open("regtmp.reg", "wb+") 215 | regtmp.write(base64.b64decode(regfix)) 216 | regtmp.close() 217 | win32api.ShellExecute(0, 'open', 'regtmp.reg', '', '', 1) 218 | if msg.askyesno('fix','成功添加后点击是\n然后手动重启电脑 即可完成修复'): 219 | os.remove("regtmp.reg") 220 | os.makedirs(r'C:\Windows\_XizoDiskIconChanger\NetDeskFixed') 221 | else: 222 | msg.showerror('修复网络驱动器', '你已经修复过了') 223 | 224 | # 获取盘符 225 | def getdisk(): 226 | global disk_list 227 | kernel32 = ctypes.windll.kernel32 228 | volumeNameBuffer = ctypes.create_unicode_buffer(1024) 229 | fileSystemNameBuffer = ctypes.create_unicode_buffer(1024) 230 | serial_number = None 231 | max_component_length = None 232 | file_system_flags = None 233 | disk_list = [] 234 | for diski in string.ascii_uppercase: 235 | disk = diski + ":\\" 236 | if os.path.isdir(disk): 237 | rc = kernel32.GetVolumeInformationW( 238 | ctypes.c_wchar_p(disk), 239 | volumeNameBuffer, 240 | ctypes.sizeof(volumeNameBuffer), 241 | serial_number, 242 | max_component_length, 243 | file_system_flags, 244 | fileSystemNameBuffer, 245 | ctypes.sizeof(fileSystemNameBuffer) 246 | ) 247 | disk_list.append('%s: %s' % (diski, volumeNameBuffer.value)) 248 | try: 249 | choose_disk_combobox['values'] = disk_list 250 | except: 251 | print() 252 | 253 | if __name__ == "__main__": 254 | 255 | getdisk() 256 | 257 | #主窗口 258 | root = tk.Tk() 259 | root.title("硬盘图标修改器 V1.1 by Xizo") 260 | 261 | #窗口位置大小 262 | screenwidth = root.winfo_screenwidth() 263 | screenheight = root.winfo_screenheight() 264 | width = 750 265 | height = 450 266 | x = int((screenwidth - width) / 2) 267 | y = int((screenheight - height) / 2) 268 | root.geometry("%dx%d+%d+%d" % (width, height, x, y)) 269 | root.resizable(0, 0) 270 | 271 | #图标 272 | icontmp = open("icontmp.ico", "wb+") 273 | icontmp.write(base64.b64decode(imgicon)) 274 | icontmp.close() 275 | root.iconbitmap('icontmp.ico') 276 | os.remove('icontmp.ico') 277 | 278 | #背景 279 | bgtmp = open("bgtmp.png", "wb+") 280 | bgtmp.write(base64.b64decode(imgbg)) 281 | bgtmp.close() 282 | bgphoto = ImageTk.PhotoImage(Image.open('bgtmp.png')) 283 | background = Label() 284 | background.pack() 285 | background['image'] = bgphoto 286 | os.remove('bgtmp.png') 287 | 288 | #Menubars 289 | menubar = tk.Menu(root) 290 | menubar.add_command(label="使用方法", command=usehelp) 291 | menubar.add_command(label="关于作者", command=about) 292 | menubar.add_command(label="退出程序", command=root.quit) 293 | root.config(menu=menubar) 294 | 295 | #选择磁盘下拉框 296 | choose_disk_combobox = ttk.Combobox(root, justify=tk.CENTER, height=10, width=11, 297 | state="readonly", font=("微软雅黑", 10), values=disk_list) 298 | 299 | #选择图标地址框 300 | choose_img_bar = tk.Text(root, width=17, height=2, 301 | state="disabled", font=("微软雅黑", 10)) 302 | choose_img_bar.configure(state='normal') 303 | choose_img_bar.insert("insert", " 请选择图片文件→") 304 | choose_img_bar.configure(state='disabled') 305 | 306 | #Buttons 307 | choose_img_btn = tk.Button(root, text="打开\n图片", command=choose_img, font=("微软雅黑", 8)) 308 | refresh_btn = tk.Button(root, text="刷新", command=getdisk, font=("微软雅黑", 8)) 309 | rest_btn = tk.Button(root, text=" 重置图标 ", command=rest, fg='black', bg='pink', font=("微软雅黑", 10)) 310 | install_btn = tk.Button(root, text=" 安装图标 ", command=install, fg='black', bg='light green', font=("微软雅黑", 10)) 311 | inf_install_btn = tk.Button(root, text="inf安装", command=infinstall, fg='black', bg='yellow', font=("微软雅黑", 8)) 312 | restartexplore_btn = tk.Button(root, text="重启资源管理器", command=restartexp, fg='black', font=("微软雅黑", 10)) 313 | fix_btn = tk.Button(root, text="修复网络驱动器", command=fix, fg='black', font=("微软雅黑", 10)) 314 | delete_btn = tk.Button(root, text="彻底还原清缓存", command=delete, font=("微软雅黑", 10)) 315 | 316 | #Place elements 317 | choose_disk_combobox.place(x=121, y=201) 318 | refresh_btn.place(x=235, y=200) 319 | choose_img_bar.place(x=95, y=250) 320 | choose_img_btn.place(x=235, y=248) 321 | rest_btn.place(x=44, y=323) 322 | install_btn.place(x=190, y=323) 323 | inf_install_btn.place(x=134, y=323,height=33) 324 | restartexplore_btn.place(x=310, y=233) 325 | fix_btn.place(x=310, y=278) 326 | delete_btn.place(x=310, y=323) 327 | 328 | #预览小图标 329 | ShowImage = Label() 330 | ShowImage.place(x=44, y=245) 331 | 332 | #检测文件夹判断初次运行 333 | if os.path.exists(r'C:\Windows\_XizoDiskIconChanger') == False: 334 | os.makedirs(r'C:\Windows\_XizoDiskIconChanger') 335 | usehelp() 336 | 337 | root.mainloop() 338 | --------------------------------------------------------------------------------