Windows 添加到文本文件上下文菜单 "open in tail mode"
Windows add to text file context menu "open in tail mode"
我想使用 power shell 将“以尾模式打开”添加到 windows 文本文件上下文菜单,power shell 脚本已准备就绪并且可以运行,但我该如何添加它并 link 它到上下文菜单 ?
尝试了几个在线指南但没有成功打开您需要的其他工具和 select 文件并且有点矫枉过正。
PowerShell 基本脚本添加一些颜色以使其更具可读性:
do {
get-content $logfile -wait -tail 1 | ForEach-Object {
switch -Regex ($_) {
"\[ERROR\]" { Write-Host $_ -ForegroundColor Red }
"\[DEBUG\]" { Write-Host $_ -ForegroundColor Yellow }
"\[INFO\]" { Write-Host $_ -ForegroundColor White }
"\[WARNING\]" { Write-Host $_ -ForegroundColor Blue }
Default { Write-Host $_ -ForegroundColor White }
}
}
} while ($false) # dummy loop so that `break` can be used.
将以下内容保存为 .reg 文件并执行它以创建日志文件扩展名的上下文菜单。
把你的脚本的真实路径
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\Classes\.log]
@="Log.File"
[HKEY_CURRENT_USER\SOFTWARE\Classes\Log.File\shell\OpenTailMode]
@="Open in Tail mode"
[HKEY_CURRENT_USER\SOFTWARE\Classes\Log.File\shell\OpenTailMode\command]
@="PowerShell -File \"C:\temp\MyScript.ps1\" %1"
%1 将是右键单击的日志文件,它将作为参数传递给您的 PowerShell 脚本,因此请在脚本的开头添加此行:
$logfile = $Args[0]
通过 Powershell:
#Create a SendTo menu shortcut to call program.
$SendToPath = "$DestinationPath\AppData\Roaming\" +
"Microsoft\Windows\SendTo\"
If (!(Test-path -Path "$SendToPath$PgmBase.lnk")) {
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut(
"$SendToPath$PgmBase.lnk")
$Shortcut.TargetPath =
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$Shortcut.Arguments = "-File `"$PSScriptRoot$PgmName`""
$Shortcut.WindowStyle = 4 #0=Max 4=Normal 7=Minimized
$Shortcut.IconLocation =
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$Shortcut.Save()
$("The $PgmBase option has been added to" +
"File Explorer SendTo menu.")
} #End If (!(Test-Path...
Else {
$("The $PgmBase.lnk shortcut already exists " +
"in the File Explorer SendTo menu.")
}
您可以将上述代码包含在一个函数包装器中,然后将一个参数添加到您的主程序以接受一个 [Switch] 参数,例如 -Install 或 -Setup 并对其进行测试,然后在开关存在时调用该函数。
HTH
我想使用 power shell 将“以尾模式打开”添加到 windows 文本文件上下文菜单,power shell 脚本已准备就绪并且可以运行,但我该如何添加它并 link 它到上下文菜单 ?
尝试了几个在线指南但没有成功打开您需要的其他工具和 select 文件并且有点矫枉过正。
PowerShell 基本脚本添加一些颜色以使其更具可读性:
do {
get-content $logfile -wait -tail 1 | ForEach-Object {
switch -Regex ($_) {
"\[ERROR\]" { Write-Host $_ -ForegroundColor Red }
"\[DEBUG\]" { Write-Host $_ -ForegroundColor Yellow }
"\[INFO\]" { Write-Host $_ -ForegroundColor White }
"\[WARNING\]" { Write-Host $_ -ForegroundColor Blue }
Default { Write-Host $_ -ForegroundColor White }
}
}
} while ($false) # dummy loop so that `break` can be used.
将以下内容保存为 .reg 文件并执行它以创建日志文件扩展名的上下文菜单。 把你的脚本的真实路径
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\Classes\.log]
@="Log.File"
[HKEY_CURRENT_USER\SOFTWARE\Classes\Log.File\shell\OpenTailMode]
@="Open in Tail mode"
[HKEY_CURRENT_USER\SOFTWARE\Classes\Log.File\shell\OpenTailMode\command]
@="PowerShell -File \"C:\temp\MyScript.ps1\" %1"
%1 将是右键单击的日志文件,它将作为参数传递给您的 PowerShell 脚本,因此请在脚本的开头添加此行:
$logfile = $Args[0]
通过 Powershell:
#Create a SendTo menu shortcut to call program.
$SendToPath = "$DestinationPath\AppData\Roaming\" +
"Microsoft\Windows\SendTo\"
If (!(Test-path -Path "$SendToPath$PgmBase.lnk")) {
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut(
"$SendToPath$PgmBase.lnk")
$Shortcut.TargetPath =
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$Shortcut.Arguments = "-File `"$PSScriptRoot$PgmName`""
$Shortcut.WindowStyle = 4 #0=Max 4=Normal 7=Minimized
$Shortcut.IconLocation =
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$Shortcut.Save()
$("The $PgmBase option has been added to" +
"File Explorer SendTo menu.")
} #End If (!(Test-Path...
Else {
$("The $PgmBase.lnk shortcut already exists " +
"in the File Explorer SendTo menu.")
}
您可以将上述代码包含在一个函数包装器中,然后将一个参数添加到您的主程序以接受一个 [Switch] 参数,例如 -Install 或 -Setup 并对其进行测试,然后在开关存在时调用该函数。
HTH