# cat_trash **Repository Path**: fe521/cat_trash ## Basic Information - **Project Name**: cat_trash - **Description**: 猫猫回收站 node.js electron 版本 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-11-15 - **Last Updated**: 2023-11-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 模仿陈依涵-猫猫回收站 ## 手动修改(有效) 1. 下载.ico 图标 点击这里查看图标 2. 修改.ico 图标为 .dll 3. 鼠标右键 - 个性化 - 主题 - 桌面图标设置 - 选中 回收站(满) - 点击 更改图标(h) - 浏览 - 选中更改修改后的.dll 小猫闭嘴的.dll 文件 4. 回收站(空) 也是一样的设置 5. 做一个 UI - 假装点击 - 弹出一个修改成功 - 画面转移到回收站这里 ## 回收站注册表目录 ``` 计算机\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}\DefaultIcon ``` ## cat.js 代码实现 ### 编写 cat.js ```js // cat.js // 导入 child_process 模块中的 exec 函数 const { exec } = require("child_process"); // 获取当前用户的主目录 const userProfile = process.env.USERPROFILE; // 定义空猫图标和满猫图标的路径 const emptyIconPath = `${userProfile}\\Downloads\\cat_icons\\cat_4.dll,0`; const fullIconPath = `${userProfile}\\Downloads\\cat_icons\\cat_1.dll,0`; // 定义设置空猫图标和满猫图标的注册表命令 const setEmptyIconCommand = `reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CLSID\\{645FF040-5081-101B-9F08-00AA002F954E}\\DefaultIcon" /v empty /t REG_SZ /d "${emptyIconPath}" /f`; const setFullIconCommand = `reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CLSID\\{645FF040-5081-101B-9F08-00AA002F954E}\\DefaultIcon" /v full /t REG_SZ /d "${fullIconPath}" /f`; // 封装执行命令的函数并返回 Promise function executeCommand(command) { return new Promise((resolve, reject) => { exec(command, (error, stdout, stderr) => { if (error) { console.error(`执行错误: ${error}`); reject(); return; } if (stderr) { console.error(`标准错误输出: ${stderr}`); } console.log(`标准输出: ${stdout}`); resolve(); }); }); } // 异步函数:设置猫图标 async function setCatIcon() { await executeCommand(setEmptyIconCommand); await executeCommand(setFullIconCommand); // 等待 3 秒钟,然后刷新资源管理器 await new Promise((resolve) => setTimeout(resolve, 3000)); refreshExplorer(); } // 封装执行命令的函数并返回 Promise function execPromise(command) { return new Promise((resolve, reject) => { exec(command, (error, stdout, stderr) => { if (error) { reject(`执行错误: ${error}`); return; } if (stderr) { reject(`执行错误: ${stderr}`); return; } resolve(stdout); }); }); } // 异步函数:重启资源管理器 async function refreshExplorer() { try { // 结束资源管理器进程 await execPromise("taskkill /f /im explorer.exe"); console.log("资源管理器已结束."); // 重启资源管理器,但不等待其执行完成 exec("start explorer.exe", (error, stdout, stderr) => { if (error) { console.error(`重启资源管理器时出错: ${error}`); } }); console.log("资源管理器重启命令已发出."); } catch (error) { console.error(error); } finally { // 确保无论成功还是失败,进程都将退出 console.log("退出进程."); setTimeout(() => { process.exit(0); }, 1000 * 3); } } // 定义还原默认图标的路径 const emptyIconPathRest = `%SystemRoot%\\System32\\imageres.dll,-55`; const fullIconPathRest = `%SystemRoot%\\System32\\imageres.dll,-54`; // 定义设置空猫图标和满猫图标为默认图标的注册表命令 const setEmptyIconCommandRest = `reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CLSID\\{645FF040-5081-101B-9F08-00AA002F954E}\\DefaultIcon" /v empty /t REG_SZ /d "${emptyIconPathRest}" /f`; const setFullIconCommandRest = `reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CLSID\\{645FF040-5081-101B-9F08-00AA002F954E}\\DefaultIcon" /v full /t REG_SZ /d "${fullIconPathRest}" /f`; // 异步函数:还原默认图标 async function reset() { await executeCommand(setEmptyIconCommandRest); await executeCommand(setFullIconCommandRest); // 等待 3 秒钟,然后刷新资源管理器 await new Promise((resolve) => setTimeout(resolve, 3000)); refreshExplorer(); } // 处理命令行参数 const args = process.argv.slice(2); if (args.length > 0 && args[0] === "reset") { // node cat.js reset reset(); } else { // node cat.js setCatIcon(); } ``` ### 调用 cat.js 设置猫猫回收站 ```powershell node cat.js ``` 还原成默认的方式 ```powershell node cat.js reset ``` ## 注册表类型 REG_SZ 和 REG_EXPAND_SZ 的区别 在 Windows 注册表中,`REG_SZ`(字符串)和`REG_EXPAND_SZ`(可扩展字符串)是两种不同的数据类型,它们有以下区别: 1. **REG_SZ (字符串值)**: - `REG_SZ` 表示一个普通的字符串值。 - 它包含普通的文本数据,不会自动扩展或解释其中的变量。 - 这种类型通常用于存储普通文本信息,如路径、文件名、配置等。 2. **REG_EXPAND_SZ (可扩展字符串值)**: - `REG_EXPAND_SZ` 表示一个可扩展字符串值。 - 它也包含文本数据,但可以包含环境变量,例如 `%SystemRoot%` 或 `%USERPROFILE%`,这些环境变量在读取时会被自动扩展为实际的值。 - 这种类型通常用于存储包含环境变量的路径或其他需要在使用时动态扩展的文本信息。 比如,如果你在`REG_SZ`中存储了一个路径,例如`C:\Program Files\MyApp`,那么读取它时将得到原始的路径。而如果你在`REG_EXPAND_SZ`中存储了相同的路径,例如`%ProgramFiles%\\MyApp`,那么读取它时系统会自动扩展 `%ProgramFiles%` 为实际的路径,例如 `C:\Program Files`。 总之,区别在于`REG_SZ`存储纯文本,而`REG_EXPAND_SZ`允许存储包含环境变量的文本,并在读取时自动扩展这些环境变量。你可以根据需要选择合适的数据类型来存储数据。