Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions ContextMenuManager/Controls/ShellExecuteDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override bool RunDialog(IntPtr hwndOwner)

public static string GetCommand(string fileName, string arguments, string verb, int windowStyle, string directory = null)
{
if (directory == null)
if (string.IsNullOrWhiteSpace(directory))
{
ObjectPath.GetFullFilePath(fileName, out var filePath);
directory = Path.GetDirectoryName(filePath);
Expand All @@ -48,11 +48,16 @@ public static string GetCommand(string fileName, string arguments, string verb,
}

string psFileName = "'" + fileName.Replace("'", "''") + "'";
string psDir = string.IsNullOrEmpty(directory) ? "$null" : "'" + directory.Replace("'", "''") + "'";
string psVerb = "'" + verb.Replace("'", "''") + "'";
string psArgs = "'" + arguments.Replace("'", "''") + "'";

return $"powershell -WindowStyle Hidden -Command \"Start-Process -FilePath {psFileName} -ArgumentList {psArgs} -WorkingDirectory {psDir} -Verb {psVerb} -WindowStyle {winStyleStr}\"";
string psDirPart = "";
if (!string.IsNullOrWhiteSpace(directory))
{
psDirPart = $"-WorkingDirectory '{directory.Replace("'", "''")}'";
}

return $"powershell -WindowStyle Hidden -Command \"Start-Process -FilePath {psFileName} -ArgumentList {psArgs} {psDirPart} -Verb {psVerb} -WindowStyle {winStyleStr}\"";
}
else
{
Expand Down
155 changes: 127 additions & 28 deletions ContextMenuManager/Properties/Resources/Texts/EnhanceMenusDic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,111 @@ Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开
</Command>
</SubKey>
</Item>
<Item KeyName='GetHash'>
<OSVersion Compare="&gt;=">6.3</OSVersion>
<Value>
<REG_SZ MUIVerb='获取哈希值' Icon='imageres.dll,-5372'/>
<REG_SZ MUIVerb='Get Hash'>
<Culture>en-US</Culture>
</REG_SZ>
</Value>
<SubKey>
<Command>
<ShellExecute Verb='open' WindowStyle='3'/>
<FileName>powershell.exe</FileName>
<Arguments>-noexit write-host '"%1"';$args = 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'mactripledes', 'ripemd160'; foreach($arg in $args){get-filehash '"%1"' -algorithm $arg | select-object algorithm, hash | format-table -wrap}</Arguments>
</Command>
</SubKey>
</Item>
<Item KeyName='GetHash'>
<OSVersion Compare="&gt;=">6.3</OSVersion>
<Value>
<REG_SZ MUIVerb='获取哈希值' Icon='imageres.dll,-5372' SubCommands=''/>
<REG_SZ MUIVerb='Get Hash'>
<Culture>en-US</Culture>
</REG_SZ>
</Value>
<SubKey>
<Shell>
<SubKey>
<Item0>
<Value>
<REG_SZ MUIVerb='MD5' Icon='imageres.dll,-5372'/>
<REG_SZ MUIVerb='MD5'>
<Culture>en-US</Culture>
</REG_SZ>
</Value>
<SubKey>
<Command>
<ShellExecute Verb='open' WindowStyle='1'/>
<FileName>powershell.exe</FileName>
<Arguments>-NoExit -Command "$Host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size(512, 50); $h = Get-FileHash '%1' -Algorithm MD5; Write-Host 'File: %1' -ForegroundColor Cyan; Write-Host 'MD5 : ' -NoNewline; Write-Host $h.Hash -ForegroundColor Yellow"</Arguments>
</Command>
</SubKey>
</Item0>
<Item1>
<Value>
<REG_SZ MUIVerb='SHA1' Icon='imageres.dll,-5372'/>
<REG_SZ MUIVerb='SHA1'>
<Culture>en-US</Culture>
</REG_SZ>
</Value>
<SubKey>
<Command>
<ShellExecute Verb='open' WindowStyle='1'/>
<FileName>powershell.exe</FileName>
<Arguments>-NoExit -Command "$Host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size(512, 50); $h = Get-FileHash '%1' -Algorithm SHA1; Write-Host 'File: %1' -ForegroundColor Cyan; Write-Host 'SHA1 : ' -NoNewline; Write-Host $h.Hash -ForegroundColor Yellow"</Arguments>
</Command>
</SubKey>
</Item1>
<Item2>
<Value>
<REG_SZ MUIVerb='SHA256' Icon='imageres.dll,-5372'/>
<REG_SZ MUIVerb='SHA256'>
<Culture>en-US</Culture>
</REG_SZ>
</Value>
<SubKey>
<Command>
<ShellExecute Verb='open' WindowStyle='1'/>
<FileName>powershell.exe</FileName>
<Arguments>-NoExit -Command "$Host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size(512, 50); $h = Get-FileHash '%1' -Algorithm SHA256; Write-Host 'File: %1' -ForegroundColor Cyan; Write-Host 'SHA256 : ' -NoNewline; Write-Host $h.Hash -ForegroundColor Yellow"</Arguments>
</Command>
</SubKey>
</Item2>
<Item3>
<Value>
<REG_SZ MUIVerb='SHA384' Icon='imageres.dll,-5372'/>
<REG_SZ MUIVerb='SHA384'>
<Culture>en-US</Culture>
</REG_SZ>
</Value>
<SubKey>
<Command>
<ShellExecute Verb='open' WindowStyle='1'/>
<FileName>powershell.exe</FileName>
<Arguments>-NoExit -Command "$Host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size(512, 50); $h = Get-FileHash '%1' -Algorithm SHA384; Write-Host 'File: %1' -ForegroundColor Cyan; Write-Host 'SHA384 : ' -NoNewline; Write-Host $h.Hash -ForegroundColor Yellow"</Arguments>
</Command>
</SubKey>
</Item3>
<Item4>
<Value>
<REG_SZ MUIVerb='SHA512' Icon='imageres.dll,-5372'/>
<REG_SZ MUIVerb='SHA512'>
<Culture>en-US</Culture>
</REG_SZ>
</Value>
<SubKey>
<Command>
<ShellExecute Verb='open' WindowStyle='1'/>
<FileName>powershell.exe</FileName>
<Arguments>-NoExit -Command "$Host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size(512, 50); $h = Get-FileHash '%1' -Algorithm SHA512; Write-Host 'File: %1' -ForegroundColor Cyan; Write-Host 'SHA512 : ' -NoNewline; Write-Host $h.Hash -ForegroundColor Yellow"</Arguments>
</Command>
</SubKey>
</Item4>
<Item5>
<Value>
<REG_SZ MUIVerb='全部算法' Icon='imageres.dll,-5372'/>
<REG_SZ MUIVerb='All Algorithms'>
<Culture>en-US</Culture>
</REG_SZ>
</Value>
<SubKey>
<Command>
<ShellExecute Verb='open' WindowStyle='1'/>
<FileName>powershell.exe</FileName>
<Arguments>-NoExit -Command "$Host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size(512, 50); Write-Host 'File: %1' -ForegroundColor Cyan; Write-Host ('-' * 64); 'MD5','SHA1','SHA256','SHA384','SHA512' | ForEach-Object { $h = Get-FileHash '%1' -Algorithm $_; Write-Host ('{0,-8}: ' -f $h.Algorithm) -NoNewline; Write-Host $h.Hash -ForegroundColor Yellow }; Write-Host ('-' * 64)"</Arguments>
</Command>
</SubKey>
</Item5>
</SubKey>
</Shell>
</SubKey>
</Item>
</Shell>
</Group>

Expand Down Expand Up @@ -1223,30 +1312,34 @@ Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开
<Item0>
<Value>
<REG_SZ MUIVerb='禁止入站' Icon='imageres.dll,-105'/>
<REG_SZ MUIVerb='Not Allow In'>
<REG_SZ MUIVerb='Block In'>
<Culture>en-US</Culture>
</REG_SZ>
</Value>
<SubKey>
<Command>
<ShellExecute Verb='runas' WindowStyle='0'/>
<FileName>cmd.exe</FileName>
<Arguments>/R (netsh advfirewall firewall delete rule name="_%1" dir=in program="%1" &amp; netsh advfirewall firewall add rule name="_%1" dir=in program="%1" action=block)</Arguments>
<FileName>powershell.exe</FileName>
<Arguments>
Get-NetFirewallRule -DisplayName '_%1' | Where-Object { ($_ | Get-NetFirewallApplicationFilter).Program -eq '%1' -and $_.Direction -eq 'Inbound' } | Remove-NetFirewallRule; New-NetFirewallRule -DisplayName '_%1' -Program '%1' -Direction Inbound -Action Block
</Arguments>
</Command>
</SubKey>
</Item0>
<Item1>
<Value>
<REG_SZ MUIVerb='禁止出站' Icon='imageres.dll,-105'/>
<REG_SZ MUIVerb='Not Allow Out'>
<REG_SZ MUIVerb='Block Out'>
<Culture>en-US</Culture>
</REG_SZ>
</Value>
<SubKey>
<Command>
<ShellExecute Verb='runas' WindowStyle='0'/>
<FileName>cmd.exe</FileName>
<Arguments>/R (netsh advfirewall firewall delete rule name="_%1" dir=out program="%1" &amp; netsh advfirewall firewall add rule name="_%1" dir=out program="%1" action=block)</Arguments>
<FileName>powershell.exe</FileName>
<Arguments>
Get-NetFirewallRule -DisplayName '_%1' | Where-Object { ($_ | Get-NetFirewallApplicationFilter).Program -eq '%1' -and $_.Direction -eq 'Outbound' } | Remove-NetFirewallRule; New-NetFirewallRule -DisplayName '_%1' -Program '%1' -Direction Outbound -Action Block
</Arguments>
</Command>
</SubKey>
</Item1>
Expand All @@ -1260,8 +1353,10 @@ Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开
<SubKey>
<Command>
<ShellExecute Verb='runas' WindowStyle='0'/>
<FileName>cmd.exe</FileName>
<Arguments>/R (netsh advfirewall firewall delete rule name="_%1" dir=in program="%1" &amp; netsh advfirewall firewall add rule name="_%1" dir=in program="%1" action=allow)</Arguments>
<FileName>powershell.exe</FileName>
<Arguments>
Get-NetFirewallRule -DisplayName '_%1' | Where-Object { ($_ | Get-NetFirewallApplicationFilter).Program -eq '%1' -and $_.Direction -eq 'Inbound' } | Remove-NetFirewallRule; New-NetFirewallRule -DisplayName '_%1' -Program '%1' -Direction Inbound -Action Allow
</Arguments>
</Command>
</SubKey>
</Item2>
Expand All @@ -1275,8 +1370,10 @@ Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开
<SubKey>
<Command>
<ShellExecute Verb='runas' WindowStyle='0'/>
<FileName>cmd.exe</FileName>
<Arguments>/R (netsh advfirewall firewall delete rule name="_%1" dir=out program="%1" &amp; netsh advfirewall firewall add rule name="_%1" dir=out program="%1" action=allow)</Arguments>
<FileName>powershell.exe</FileName>
<Arguments>
Get-NetFirewallRule -DisplayName '_%1' | Where-Object { ($_ | Get-NetFirewallApplicationFilter).Program -eq '%1' -and $_.Direction -eq 'Outbound' } | Remove-NetFirewallRule; New-NetFirewallRule -DisplayName '_%1' -Program '%1' -Direction Outbound -Action Allow
</Arguments>
</Command>
</SubKey>
</Item3>
Expand All @@ -1290,8 +1387,10 @@ Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开
<SubKey>
<Command>
<ShellExecute Verb='runas' WindowStyle='0'/>
<FileName>cmd.exe</FileName>
<Arguments>/R (netsh advfirewall firewall delete rule name="_%1" program="%1")</Arguments>
<FileName>powershell.exe</FileName>
<Arguments>
Get-NetFirewallRule -DisplayName '_%1' | Where-Object { ($_ | Get-NetFirewallApplicationFilter).Program -eq '%1' } | Remove-NetFirewallRule
</Arguments>
</Command>
</SubKey>
</Item4>
Expand Down
Loading