Skip to content

修复 PowerShell 命令 WorkingDirectory 参数处理,及优化部分命令#98

Merged
Jack251970 merged 3 commits intoJack251970:masterfrom
CMJNB:master
Feb 24, 2026
Merged

修复 PowerShell 命令 WorkingDirectory 参数处理,及优化部分命令#98
Jack251970 merged 3 commits intoJack251970:masterfrom
CMJNB:master

Conversation

@CMJNB
Copy link

@CMJNB CMJNB commented Feb 23, 2026

Start-Process : 无法对参数“WorkingDirectory”执行参数验证。参数为 Null 或空。请提供一个不为 Null 或空的参数,然后重试
该命令。
所在位置 行:1 字符: 81
+ ... 'tskill.exe' -ArgumentList 'explorer' -WorkingDirectory $null -Verb ' ...
+                                                             ~~~~~
    + CategoryInfo          : InvalidData: (:) [Start-Process],ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StartProcessCommand

#93

修正了生成 PowerShell 命令时 WorkingDirectory 参数的逻辑,仅在 directory 非空且非空白时添加该参数,避免传递无意义的 $null,使命令更简洁且符合 PowerShell 规范。
将 EnhanceMenusDic.xml 中防火墙相关菜单项的命令由 cmd+netsh 替换为 PowerShell 脚本,提升规则操作的准确性和兼容性。同时优化英文菜单项描述,使其更符合表达习惯。
将“获取哈希值”菜单由单一命令改为多子菜单结构,支持 MD5、SHA1、SHA256、SHA384、SHA512 及全部算法选项。每项均调用 PowerShell 并以彩色高亮显示结果,提升交互体验和易用性,支持中英文多语言。
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a critical bug in PowerShell command generation where the WorkingDirectory parameter was being passed as $null, causing the "Restart Explorer" feature to fail. The PR also enhances the "Get Hash" menu by splitting it into individual submenu items for different hash algorithms with improved output formatting, and modernizes firewall rule management by migrating from netsh commands to PowerShell cmdlets.

Changes:

  • Fixed WorkingDirectory parameter handling to omit the parameter when directory is null/empty/whitespace instead of passing $null
  • Refactored "Get Hash" menu from a single command showing all algorithms to separate submenu items for MD5, SHA1, SHA256, SHA384, SHA512, and all algorithms
  • Migrated firewall rule commands from cmd.exe with netsh to powershell.exe with NetFirewall cmdlets
  • Updated English translations for firewall commands from "Not Allow" to "Block"

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
ContextMenuManager/Controls/ShellExecuteDialog.cs Fixed WorkingDirectory parameter to only include it in PowerShell command when directory is not null/empty/whitespace, resolving the $null parameter error
ContextMenuManager/Properties/Resources/Texts/EnhanceMenusDic.xml Enhanced Get Hash menu structure with individual algorithm submenus, migrated firewall commands to PowerShell cmdlets, and improved English translations
Comments suppressed due to low confidence (1)

ContextMenuManager/Controls/ShellExecuteDialog.cs:66

  • In the else branch (for Windows versions before 10), the directory variable is passed directly to the VBScript ShellExecute call without checking if it's null or empty after attempting to derive it from the file path. If ObjectPath.GetFullFilePath fails to find the file path, and Path.GetDirectoryName returns null, this could result in passing a null directory to the VBScript. Consider adding a null check or default value handling for the directory in this branch as well.
            else
            {
                arguments = arguments.Replace("\"", "\"\"");
                return "mshta vbscript:createobject(\"shell.application\").shellexecute" +
                    $"(\"{fileName}\",\"{arguments}\",\"{directory}\",\"{verb}\",{windowStyle})(close)";

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Owner

@Jack251970 Jack251970 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢你的贡献!

@Jack251970 Jack251970 merged commit 640c704 into Jack251970:master Feb 24, 2026
6 checks passed
@Jack251970 Jack251970 added the bug Something isn't working label Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 增强菜单中-桌面背景-重启资源管理器-功能失效

3 participants