本帖最后由 went 于 2022-10-19 16:04 编辑
| using namespace 'Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes' | | using namespace 'System.Windows.Forms' | | using namespace 'System.Collections.Specialized';cls | | [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | | Add-Type -Name 'WinApi' -MemberDefinition '[DllImport("user32.dll")]public static extern short GetKeyState(uint VK);' | | $shell = New-Object -ComObject 'WScript.Shell' | | $paths = New-Object 'StringCollection' | | $arr_err = New-Object 'System.Collections.ArrayList' | | if([WinApi]::GetKeyState(16) -band 0x8000){ write-host 'shift';$paths = [Clipboard]::GetFileDropList() } | | $args | foreach { [void]$paths.Add($_) } | | $paths = &{ | | $paths | Select-Object -Unique | foreach { | | | | if([System.IO.Directory]::Exists($_)){ return $_ } | | | | if([System.IO.File]::Exists($_)){ | | | | if($_.EndsWith('.lnk')){ | | $p = $shell.CreateShortcut($_).TargetPath | | if([System.IO.File]::Exists($p)){ return $p } | | if([System.IO.Directory]::Exists($p)){ return $p } | | [void]$arr_err.Add(('{0} -> {1}' -f $_,$p)) | | return $null | | } | | | | return $_ | | } | | } | Select-Object -Unique | | } | | if($paths.Count -gt 0){ | | [Clipboard]::SetFileDropList($paths) | | 'ok' | | $paths | | '-----------' | | } | | if($arr_err.Count -gt 0){ | | 'fail' | | $arr_err | | '-----------' | | pause | | }COPY |
|